-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02.rs
38 lines (31 loc) · 811 Bytes
/
02.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#![feature(test)]
use aoc::intcode::{Int, IntcodeVm};
use rayon::iter::{IntoParallelIterator, ParallelIterator};
type Input = Vec<Int>;
fn setup(input: &str) -> Input {
input
.split(',')
.map(|x| x.trim().parse().unwrap())
.collect()
}
fn run(input: &Input, noun: Int, verb: Int) -> Int {
let mut vm = IntcodeVm::new(input.iter().copied());
vm.write(1, noun);
vm.write(2, verb);
vm.run().unwrap();
vm.read(0)
}
fn part1(input: &Input) -> Int {
run(input, 12, 2)
}
fn part2(input: &Input) -> Int {
(0..100)
.into_par_iter()
.find_map_any(|noun| {
(0..100)
.find(|&verb| run(input, noun, verb) == 19690720)
.map(|verb| 100 * noun + verb)
})
.unwrap()
}
aoc::main!(2019, 2);