Add D13P1
This commit is contained in:
parent
315d0cac7e
commit
6faab62f5e
|
@ -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" }
|
|
@ -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);
|
||||||
|
}
|
|
@ -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]
|
#[rustfmt::skip]
|
||||||
fn get_next(&mut self, mode: Mode) -> i64 {
|
fn get_next(&mut self, mode: Mode) -> i64 {
|
||||||
let value = *self.tape.get(self.pos as usize).unwrap();
|
let value = *self.tape.get(self.pos as usize).unwrap();
|
||||||
|
|
|
@ -41,7 +41,6 @@ fn test_find_max_with_loops() {
|
||||||
),
|
),
|
||||||
Some(139629729)
|
Some(139629729)
|
||||||
);
|
);
|
||||||
/*
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
find_max(
|
find_max(
|
||||||
5..10,
|
5..10,
|
||||||
|
@ -49,7 +48,6 @@ fn test_find_max_with_loops() {
|
||||||
),
|
),
|
||||||
Some(18216)
|
Some(18216)
|
||||||
);
|
);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user