Add D13P1

This commit is contained in:
kageru 2019-12-13 08:24:01 +01:00
parent 315d0cac7e
commit 6faab62f5e
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
4 changed files with 30 additions and 2 deletions

10
2019/13/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "day13"
version = "0.1.0"
authors = ["kageru <kageru@encode.moe>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
intcode = { path = "../intcode" }

12
2019/13/src/main.rs Normal file
View File

@ -0,0 +1,12 @@
use intcode::*;
fn main() {
let part1 = IntComputer::new(read_input(), 0, vec![])
.get_all_outputs()
.into_iter()
.skip(2)
.step_by(3)
.filter(|s| s == &2)
.count();
println!("Part 1: {}", part1);
}

View File

@ -42,6 +42,14 @@ impl IntComputer {
}
}
pub fn get_all_outputs(&mut self) -> Vec<i64> {
let mut outputs = Vec::new();
while let IntComputerResult::Output(o) = self.run() {
outputs.push(o);
}
outputs
}
#[rustfmt::skip]
fn get_next(&mut self, mode: Mode) -> i64 {
let value = *self.tape.get(self.pos as usize).unwrap();

View File

@ -41,7 +41,6 @@ fn test_find_max_with_loops() {
),
Some(139629729)
);
/*
assert_eq!(
find_max(
5..10,
@ -49,7 +48,6 @@ fn test_find_max_with_loops() {
),
Some(18216)
);
*/
}
#[test]