From 283b6faa4d0d68c87f8346b564dd1b341de59da5 Mon Sep 17 00:00:00 2001 From: Ishan Jain Date: Mon, 12 Dec 2022 01:24:47 +0530 Subject: [PATCH] Added empty files/folders and removed unused files/folders --- inputs/input.txt | 56 ----------------- inputs/sample.txt | 27 --------- src/day12/1.rs | 0 src/day12/2.rs | 0 src/day13/1.rs | 0 src/day13/2.rs | 0 src/day14/1.rs | 0 src/day14/2.rs | 0 src/day15/1.rs | 0 src/day15/2.rs | 0 src/day16/1.rs | 0 src/day16/2.rs | 0 src/day17/1.rs | 0 src/day17/2.rs | 0 src/day18/1.rs | 0 src/day18/2.rs | 0 src/day19/1.rs | 0 src/day19/2.rs | 0 src/day20/1.rs | 0 src/day20/2.rs | 0 src/day21/1.rs | 0 src/day21/2.rs | 0 src/day22/1.rs | 0 src/day22/2.rs | 0 src/day23/1.rs | 0 src/day23/2.rs | 0 src/day24/1.rs | 0 src/day24/2.rs | 0 src/day25/1.rs | 0 src/day25/2.rs | 0 src/main.rs | 149 ---------------------------------------------- 31 files changed, 232 deletions(-) delete mode 100644 inputs/input.txt delete mode 100644 inputs/sample.txt create mode 100644 src/day12/1.rs create mode 100644 src/day12/2.rs create mode 100644 src/day13/1.rs create mode 100644 src/day13/2.rs create mode 100644 src/day14/1.rs create mode 100644 src/day14/2.rs create mode 100644 src/day15/1.rs create mode 100644 src/day15/2.rs create mode 100644 src/day16/1.rs create mode 100644 src/day16/2.rs create mode 100644 src/day17/1.rs create mode 100644 src/day17/2.rs create mode 100644 src/day18/1.rs create mode 100644 src/day18/2.rs create mode 100644 src/day19/1.rs create mode 100644 src/day19/2.rs create mode 100644 src/day20/1.rs create mode 100644 src/day20/2.rs create mode 100644 src/day21/1.rs create mode 100644 src/day21/2.rs create mode 100644 src/day22/1.rs create mode 100644 src/day22/2.rs create mode 100644 src/day23/1.rs create mode 100644 src/day23/2.rs create mode 100644 src/day24/1.rs create mode 100644 src/day24/2.rs create mode 100644 src/day25/1.rs create mode 100644 src/day25/2.rs delete mode 100644 src/main.rs diff --git a/inputs/input.txt b/inputs/input.txt deleted file mode 100644 index a458ed3..0000000 --- a/inputs/input.txt +++ /dev/null @@ -1,56 +0,0 @@ -Monkey 0: - Starting items: 83, 97, 95, 67 - Operation: new = old * 19 - Test: divisible by 17 - If true: throw to monkey 2 - If false: throw to monkey 7 - -Monkey 1: - Starting items: 71, 70, 79, 88, 56, 70 - Operation: new = old + 2 - Test: divisible by 19 - If true: throw to monkey 7 - If false: throw to monkey 0 - -Monkey 2: - Starting items: 98, 51, 51, 63, 80, 85, 84, 95 - Operation: new = old + 7 - Test: divisible by 7 - If true: throw to monkey 4 - If false: throw to monkey 3 - -Monkey 3: - Starting items: 77, 90, 82, 80, 79 - Operation: new = old + 1 - Test: divisible by 11 - If true: throw to monkey 6 - If false: throw to monkey 4 - -Monkey 4: - Starting items: 68 - Operation: new = old * 5 - Test: divisible by 13 - If true: throw to monkey 6 - If false: throw to monkey 5 - -Monkey 5: - Starting items: 60, 94 - Operation: new = old + 5 - Test: divisible by 3 - If true: throw to monkey 1 - If false: throw to monkey 0 - -Monkey 6: - Starting items: 81, 51, 85 - Operation: new = old * old - Test: divisible by 5 - If true: throw to monkey 5 - If false: throw to monkey 1 - -Monkey 7: - Starting items: 98, 81, 63, 65, 84, 71, 84 - Operation: new = old + 3 - Test: divisible by 2 - If true: throw to monkey 2 - If false: throw to monkey 3 - diff --git a/inputs/sample.txt b/inputs/sample.txt deleted file mode 100644 index 30e09e5..0000000 --- a/inputs/sample.txt +++ /dev/null @@ -1,27 +0,0 @@ -Monkey 0: - Starting items: 79, 98 - Operation: new = old * 19 - Test: divisible by 23 - If true: throw to monkey 2 - If false: throw to monkey 3 - -Monkey 1: - Starting items: 54, 65, 75, 74 - Operation: new = old + 6 - Test: divisible by 19 - If true: throw to monkey 2 - If false: throw to monkey 0 - -Monkey 2: - Starting items: 79, 60, 97 - Operation: new = old * old - Test: divisible by 13 - If true: throw to monkey 1 - If false: throw to monkey 3 - -Monkey 3: - Starting items: 74 - Operation: new = old + 3 - Test: divisible by 17 - If true: throw to monkey 0 - If false: throw to monkey 1 diff --git a/src/day12/1.rs b/src/day12/1.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day12/2.rs b/src/day12/2.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day13/1.rs b/src/day13/1.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day13/2.rs b/src/day13/2.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day14/1.rs b/src/day14/1.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day14/2.rs b/src/day14/2.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day15/1.rs b/src/day15/1.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day15/2.rs b/src/day15/2.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day16/1.rs b/src/day16/1.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day16/2.rs b/src/day16/2.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day17/1.rs b/src/day17/1.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day17/2.rs b/src/day17/2.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day18/1.rs b/src/day18/1.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day18/2.rs b/src/day18/2.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day19/1.rs b/src/day19/1.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day19/2.rs b/src/day19/2.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day20/1.rs b/src/day20/1.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day20/2.rs b/src/day20/2.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day21/1.rs b/src/day21/1.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day21/2.rs b/src/day21/2.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day22/1.rs b/src/day22/1.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day22/2.rs b/src/day22/2.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day23/1.rs b/src/day23/1.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day23/2.rs b/src/day23/2.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day24/1.rs b/src/day24/1.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day24/2.rs b/src/day24/2.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day25/1.rs b/src/day25/1.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/day25/2.rs b/src/day25/2.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index c8167f2..0000000 --- a/src/main.rs +++ /dev/null @@ -1,149 +0,0 @@ -#![feature(test)] - -use std::cmp::Reverse; -extern crate test; - -const INPUTS: [&str; 2] = [ - include_str!("../inputs/sample.txt"), - include_str!("../inputs/input.txt"), -]; - -#[derive(Clone)] -struct Monkey { - items: Vec, - operation: Operation, - div_by_test: usize, - if_true: usize, - if_false: usize, -} - -#[derive(Clone, Debug, Copy)] -enum Operation { - MulOld, - MulNop(usize), - AddNop(usize), -} - -impl Operation { - fn apply(&self, v: usize) -> usize { - match self { - Operation::MulOld => v * v, - Operation::MulNop(i) => v * i, - Operation::AddNop(i) => v + i, - } - } -} - -fn parse(input: &'static str) -> (Vec, usize) { - let mut lcm = 1; - let output = input - .split("\n\n") - .filter(|c| !c.is_empty()) - .map(|set| { - let mut lines = set.lines().skip(1); - - let sitems: Vec = lines.next().unwrap()[18..] - .split(',') - .map(|c| { - c.bytes() - .filter(|&c| c != b' ') - .fold(0, |a, x| (a * 10) + (x - b'0') as usize) - }) - .collect(); - - let op = match lines.next().unwrap()[23..].split_at(1) { - ("*", " old") => Operation::MulOld, - ("+", v) => Operation::AddNop( - v[1..] - .bytes() - .fold(0, |a, x| (a * 10) + (x - b'0') as usize), - ), - ("*", v) => Operation::MulNop( - v[1..] - .bytes() - .fold(0, |a, x| (a * 10) + (x - b'0') as usize), - ), - (_, _) => unreachable!(), - }; - - let test = lines.next().unwrap()[21..] - .bytes() - .fold(0, |a, x| (a * 10) + (x - b'0') as usize); - - let true_result = lines.next().unwrap()[29..] - .bytes() - .fold(0, |a, x| (a * 10) + (x - b'0') as usize); - - let false_result = lines.next().unwrap()[30..] - .bytes() - .fold(0, |a, x| (a * 10) + (x - b'0') as usize); - - lcm = lcm * test / gcd(lcm, test); - - Monkey { - items: sitems, - operation: op, - div_by_test: test, - if_true: true_result, - if_false: false_result, - } - }) - .collect(); - - (output, lcm) -} - -fn main() { - for input in INPUTS.iter() { - let output = parse(input); - let score = solution(output.0, output.1); - println!("{}", score); - } -} - -fn solution(mut input: Vec, lcm: usize) -> usize { - let mlen = input.len(); - let mut activity = [0; 8]; - - for _ in 0..10000 { - for i in 0..mlen { - activity[i] += input[i].items.len(); - let if_true = input[i].if_true; - let if_false = input[i].if_false; - let operation = input[i].operation; - let div_by_test = input[i].div_by_test; - - while let Some(item) = input[i].items.pop() { - let newwlevel = operation.apply(item); - let newwlevel = newwlevel % lcm; - - if newwlevel % div_by_test == 0 { - input[if_true].items.push(newwlevel); - } else { - input[if_false].items.push(newwlevel); - } - } - } - } - - activity.select_nth_unstable_by_key(1, |c| Reverse(*c)); - - activity[0] * activity[1] -} - -#[bench] -fn solution_bench(b: &mut test::Bencher) { - b.iter(|| { - let input = parse(INPUTS[1]); - let result = solution(input.0, input.1); - test::black_box(result); - }) -} - -#[inline] -const fn gcd(a: usize, b: usize) -> usize { - if b == 0 { - return a; - } - gcd(b, a % b) -}