Skip to content

Commit

Permalink
day22
Browse files Browse the repository at this point in the history
  • Loading branch information
vslinko committed Dec 22, 2024
1 parent 9894b0a commit fd96156
Showing 1 changed file with 30 additions and 35 deletions.
65 changes: 30 additions & 35 deletions src/day22.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,46 +68,41 @@ pub fn part2(input: &str) -> i64 {
};
}

macro_rules! iter2 {
($number:expr, $prev:expr, |$new_price:ident| $block:block) => {
iter!($number);
let $new_price = $number % 10;
$block
$prev = $new_price;
};
}

for line in input.lines() {
let mut number = line.parse::<i64>().unwrap();
let mut new_price = number % 10;
let mut prev = new_price;

iter!(number);
new_price = number % 10;
diff_seq[0] = new_price - prev;
prev = new_price;

iter!(number);
new_price = number % 10;
diff_seq[1] = new_price - prev;
prev = new_price;

iter!(number);
new_price = number % 10;
diff_seq[2] = new_price - prev;
prev = new_price;

iter!(number);
new_price = number % 10;
diff_seq[3] = new_price - prev;
prev = new_price;

remember_seq!(diff_seq, new_price);

for _ in 4..2000 {
iter!(number);

new_price = number % 10;

diff_seq[0] = diff_seq[1];
diff_seq[1] = diff_seq[2];
diff_seq[2] = diff_seq[3];
let mut prev = number % 10;

iter2!(number, prev, |new_price| {
diff_seq[0] = new_price - prev;
});
iter2!(number, prev, |new_price| {
diff_seq[1] = new_price - prev;
});
iter2!(number, prev, |new_price| {
diff_seq[2] = new_price - prev;
});
iter2!(number, prev, |new_price| {
diff_seq[3] = new_price - prev;

remember_seq!(diff_seq, new_price);
});

prev = new_price;
for _ in 4..2000 {
iter2!(number, prev, |new_price| {
diff_seq[0] = diff_seq[1];
diff_seq[1] = diff_seq[2];
diff_seq[2] = diff_seq[3];
diff_seq[3] = new_price - prev;
remember_seq!(diff_seq, new_price);
});
}

already_done.clear();
Expand Down

0 comments on commit fd96156

Please sign in to comment.