1
0
Fork 0

Cleaned up day 11 part 2

This commit is contained in:
Ishan Jain 2022-12-11 12:42:06 +05:30
parent b109f0b0aa
commit a31254fc6a
Signed by: ishan
GPG Key ID: 0506DB2A1CC75C27
1 changed files with 5 additions and 18 deletions

View File

@ -37,9 +37,8 @@ fn parse(input: &'static str) -> (Vec<Monkey>, usize) {
.collect();
let op = lines.next().unwrap();
let nop = op
let nop = op[21..]
.bytes()
.filter(|c| (b'0'..=b'9').contains(c))
.fold(0, |a, x| (a * 10) + (x - b'0') as usize);
let op = move |old: usize| -> usize {
@ -54,25 +53,16 @@ fn parse(input: &'static str) -> (Vec<Monkey>, usize) {
}
};
let test = lines
.next()
.unwrap()
let test = lines.next().unwrap()[21..]
.bytes()
.filter(|c| (b'0'..=b'9').contains(c))
.fold(0, |a, x| (a * 10) + (x - b'0') as usize);
let true_result = lines
.next()
.unwrap()
let true_result = lines.next().unwrap()[29..]
.bytes()
.filter(|c| (b'0'..=b'9').contains(c))
.fold(0, |a, x| (a * 10) + (x - b'0') as usize);
let false_result = lines
.next()
.unwrap()
let false_result = lines.next().unwrap()[30..]
.bytes()
.filter(|c| (b'0'..=b'9').contains(c))
.fold(0, |a, x| (a * 10) + (x - b'0') as usize);
lcm = lcm * test / gcd(lcm, test);
@ -105,11 +95,8 @@ fn solution(mut input: Vec<Monkey>, lcm: usize) -> usize {
for _ in 0..10000 {
for i in 0..mlen {
let monkey = &input[i].clone();
let ilen = monkey.items.len();
for j in 0..ilen {
let item = monkey.items[j];
for &item in monkey.items.iter() {
let newwlevel = (monkey.operation)(item);
let newwlevel = newwlevel % lcm;