61 lines
1.4 KiB
Rust
61 lines
1.4 KiB
Rust
use shared::intcode::{IntCode, CELL};
|
|
|
|
fn run(mut ic: IntCode, first: CELL, second: CELL) -> CELL {
|
|
ic.data[1] = first;
|
|
ic.data[2] = second;
|
|
ic.simulate();
|
|
ic.data[0]
|
|
}
|
|
|
|
fn main() {
|
|
let ic = include_str!("input.txt").parse::<IntCode>().unwrap();
|
|
println!("Run 1: {}", run(ic.clone(), 12, 2));
|
|
for limit in 0.. {
|
|
for fst in 0..limit {
|
|
let result = run(ic.clone(), fst, limit);
|
|
if result == 19690720 {
|
|
println!("Found parameters: {}", 100*fst + limit);
|
|
return;
|
|
}
|
|
}
|
|
if limit > 0 {
|
|
for snd in 0..limit-1 {
|
|
let result = run(ic.clone(), limit, snd);
|
|
if result == 19690720 {
|
|
println!("Found parameters: {}", 100*limit + snd);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod day2test {
|
|
use super::*;
|
|
|
|
fn parse(input: &str) -> IntCode {
|
|
input.parse().unwrap()
|
|
}
|
|
|
|
fn run(input: &str) -> IntCode {
|
|
let mut ic = parse(input);
|
|
ic.simulate_step().expect_finished();
|
|
ic
|
|
}
|
|
|
|
#[test]
|
|
fn examples1() {
|
|
assert_eq!(run("1,9,10,3,2,3,11,0,99,30,40,50").data, parse("3500,9,10,70,2,3,11,0,99,30,40,50").data);
|
|
assert_eq!(run("1,0,0,0,99").data, parse("2,0,0,0,99").data);
|
|
assert_eq!(run("2,3,0,3,99").data, parse("2,3,0,6,99").data);
|
|
assert_eq!(run("2,4,4,5,99,0").data, parse("2,4,4,5,99,9801").data);
|
|
assert_eq!(run("1,1,1,4,99,5,6,0,99").data, parse("30,1,1,4,2,5,6,0,99").data);
|
|
}
|
|
|
|
#[test]
|
|
fn examples2() {
|
|
// no examples present
|
|
}
|
|
}
|