aoc/year2019/day05.rs
1//! # Sunny with a Chance of Asteroids
2use super::intcode::*;
3use crate::util::parse::*;
4
5pub fn parse(input: &str) -> Vec<i64> {
6 input.iter_signed().collect()
7}
8
9pub fn part1(input: &[i64]) -> i64 {
10 run(input, 1)
11}
12
13pub fn part2(input: &[i64]) -> i64 {
14 run(input, 5)
15}
16
17/// Start `IntCode` computer sending a single initial value.
18/// Receives multiple values from the output channel returning only the last one.
19fn run(input: &[i64], value: i64) -> i64 {
20 let mut computer = Computer::new(input);
21 computer.input(value);
22
23 let mut result = 0;
24 while let State::Output(next) = computer.run() {
25 result = next;
26 }
27 result
28}