Added empty files/folders and removed unused files/folders
This commit is contained in:
parent
6f20f87a36
commit
283b6faa4d
|
@ -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
|
||||
|
|
@ -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
|
0
src/day12/1.rs
Normal file
0
src/day12/1.rs
Normal file
0
src/day12/2.rs
Normal file
0
src/day12/2.rs
Normal file
0
src/day13/1.rs
Normal file
0
src/day13/1.rs
Normal file
0
src/day13/2.rs
Normal file
0
src/day13/2.rs
Normal file
0
src/day14/1.rs
Normal file
0
src/day14/1.rs
Normal file
0
src/day14/2.rs
Normal file
0
src/day14/2.rs
Normal file
0
src/day15/1.rs
Normal file
0
src/day15/1.rs
Normal file
0
src/day15/2.rs
Normal file
0
src/day15/2.rs
Normal file
0
src/day16/1.rs
Normal file
0
src/day16/1.rs
Normal file
0
src/day16/2.rs
Normal file
0
src/day16/2.rs
Normal file
0
src/day17/1.rs
Normal file
0
src/day17/1.rs
Normal file
0
src/day17/2.rs
Normal file
0
src/day17/2.rs
Normal file
0
src/day18/1.rs
Normal file
0
src/day18/1.rs
Normal file
0
src/day18/2.rs
Normal file
0
src/day18/2.rs
Normal file
0
src/day19/1.rs
Normal file
0
src/day19/1.rs
Normal file
0
src/day19/2.rs
Normal file
0
src/day19/2.rs
Normal file
0
src/day20/1.rs
Normal file
0
src/day20/1.rs
Normal file
0
src/day20/2.rs
Normal file
0
src/day20/2.rs
Normal file
0
src/day21/1.rs
Normal file
0
src/day21/1.rs
Normal file
0
src/day21/2.rs
Normal file
0
src/day21/2.rs
Normal file
0
src/day22/1.rs
Normal file
0
src/day22/1.rs
Normal file
0
src/day22/2.rs
Normal file
0
src/day22/2.rs
Normal file
0
src/day23/1.rs
Normal file
0
src/day23/1.rs
Normal file
0
src/day23/2.rs
Normal file
0
src/day23/2.rs
Normal file
0
src/day24/1.rs
Normal file
0
src/day24/1.rs
Normal file
0
src/day24/2.rs
Normal file
0
src/day24/2.rs
Normal file
0
src/day25/1.rs
Normal file
0
src/day25/1.rs
Normal file
0
src/day25/2.rs
Normal file
0
src/day25/2.rs
Normal file
149
src/main.rs
149
src/main.rs
|
@ -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<usize>,
|
||||
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<Monkey>, 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<usize> = 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<Monkey>, 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user