aoc2022 day 10 part one
This commit is contained in:
parent
0a9b91e0f3
commit
c191f67b95
139
src/aoc2022/day10/input.txt
Normal file
139
src/aoc2022/day10/input.txt
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
noop
|
||||||
|
addx 24
|
||||||
|
addx -19
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
addx 5
|
||||||
|
addx -1
|
||||||
|
addx 5
|
||||||
|
addx 1
|
||||||
|
addx 14
|
||||||
|
addx -9
|
||||||
|
addx -1
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
addx 2
|
||||||
|
addx -20
|
||||||
|
addx 24
|
||||||
|
addx -36
|
||||||
|
addx -2
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx 2
|
||||||
|
addx 5
|
||||||
|
addx 21
|
||||||
|
addx -16
|
||||||
|
noop
|
||||||
|
addx 2
|
||||||
|
addx 15
|
||||||
|
addx -14
|
||||||
|
addx 2
|
||||||
|
addx 5
|
||||||
|
addx 2
|
||||||
|
addx -4
|
||||||
|
addx 5
|
||||||
|
addx -8
|
||||||
|
addx 15
|
||||||
|
addx 2
|
||||||
|
addx 3
|
||||||
|
addx -2
|
||||||
|
addx -38
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx 4
|
||||||
|
noop
|
||||||
|
addx 7
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -2
|
||||||
|
addx 5
|
||||||
|
addx -16
|
||||||
|
addx 21
|
||||||
|
noop
|
||||||
|
addx -10
|
||||||
|
addx 11
|
||||||
|
addx 2
|
||||||
|
addx 5
|
||||||
|
addx 4
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -6
|
||||||
|
addx 7
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx -36
|
||||||
|
noop
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
addx 20
|
||||||
|
addx -19
|
||||||
|
addx 5
|
||||||
|
addx 4
|
||||||
|
noop
|
||||||
|
addx -2
|
||||||
|
addx 3
|
||||||
|
noop
|
||||||
|
addx 4
|
||||||
|
noop
|
||||||
|
addx -1
|
||||||
|
addx 5
|
||||||
|
addx 3
|
||||||
|
addx -28
|
||||||
|
addx 30
|
||||||
|
noop
|
||||||
|
addx 6
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
addx -38
|
||||||
|
addx 40
|
||||||
|
addx -33
|
||||||
|
addx 20
|
||||||
|
addx -19
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
addx 28
|
||||||
|
addx -23
|
||||||
|
addx 5
|
||||||
|
addx 2
|
||||||
|
addx 2
|
||||||
|
addx 3
|
||||||
|
addx -2
|
||||||
|
addx 5
|
||||||
|
addx 2
|
||||||
|
addx -7
|
||||||
|
addx 12
|
||||||
|
addx -2
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx -38
|
||||||
|
noop
|
||||||
|
addx 24
|
||||||
|
addx -17
|
||||||
|
noop
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
addx -8
|
||||||
|
addx 13
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 2
|
||||||
|
addx 5
|
||||||
|
addx 2
|
||||||
|
addx 6
|
||||||
|
addx -5
|
||||||
|
addx 4
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
|
33
src/aoc2022/day10/mod.rs
Normal file
33
src/aoc2022/day10/mod.rs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
pub fn task_one(input: &str) -> String {
|
||||||
|
let mut x = 1;
|
||||||
|
let mut cycles: Vec<isize> = Vec::new();
|
||||||
|
|
||||||
|
for line in input.trim().lines() {
|
||||||
|
let mut split = line.split_whitespace();
|
||||||
|
|
||||||
|
match split.next().unwrap() {
|
||||||
|
"noop" => {
|
||||||
|
cycles.push(x);
|
||||||
|
}
|
||||||
|
"addx" => {
|
||||||
|
cycles.push(x);
|
||||||
|
cycles.push(x);
|
||||||
|
x += split.next().unwrap().parse::<isize>().unwrap();
|
||||||
|
}
|
||||||
|
_ => panic!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let interesing: Vec<usize> = vec![20, 60, 100, 140, 180, 220];
|
||||||
|
let mut sum = 0;
|
||||||
|
|
||||||
|
for i in interesing {
|
||||||
|
sum += cycles[i - 1].checked_mul(i as isize).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
sum.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn task_two(input: &str) -> String {
|
||||||
|
String::new()
|
||||||
|
}
|
@ -7,3 +7,4 @@ pub mod day06;
|
|||||||
pub mod day07;
|
pub mod day07;
|
||||||
pub mod day08;
|
pub mod day08;
|
||||||
pub mod day09;
|
pub mod day09;
|
||||||
|
pub mod day10;
|
||||||
|
@ -63,4 +63,7 @@ fn main() {
|
|||||||
|
|
||||||
puzzle = Puzzle { day: 9, year: 2022, task_one: aoc2022::day09::task_one, task_two: aoc2022::day09::task_two };
|
puzzle = Puzzle { day: 9, year: 2022, task_one: aoc2022::day09::task_one, task_two: aoc2022::day09::task_two };
|
||||||
puzzle.solve_and_print();
|
puzzle.solve_and_print();
|
||||||
|
|
||||||
|
puzzle = Puzzle { day: 10, year: 2022, task_one: aoc2022::day10::task_one, task_two: aoc2022::day10::task_two };
|
||||||
|
puzzle.solve_and_print();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user