readying 2022 to merge
This commit is contained in:
7
2022/day10/Cargo.lock
generated
Normal file
7
2022/day10/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "day10"
|
||||
version = "0.1.0"
|
||||
10
2022/day10/Cargo.toml
Normal file
10
2022/day10/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "day10"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
138
2022/day10/input
Normal file
138
2022/day10/input
Normal file
@@ -0,0 +1,138 @@
|
||||
addx 1
|
||||
noop
|
||||
addx 4
|
||||
noop
|
||||
noop
|
||||
addx 7
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 3
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
addx -1
|
||||
addx 1
|
||||
addx 5
|
||||
addx 3
|
||||
noop
|
||||
addx 3
|
||||
noop
|
||||
addx -1
|
||||
noop
|
||||
addx 3
|
||||
addx 5
|
||||
addx -38
|
||||
addx 7
|
||||
addx 10
|
||||
addx -14
|
||||
addx 5
|
||||
addx 30
|
||||
addx -25
|
||||
noop
|
||||
addx 2
|
||||
addx 3
|
||||
addx -2
|
||||
addx 2
|
||||
addx 5
|
||||
addx 2
|
||||
addx 2
|
||||
addx -21
|
||||
addx 22
|
||||
addx 5
|
||||
addx 2
|
||||
addx 3
|
||||
noop
|
||||
addx -39
|
||||
addx 1
|
||||
noop
|
||||
noop
|
||||
addx 3
|
||||
addx 5
|
||||
addx 4
|
||||
addx -5
|
||||
addx 4
|
||||
addx 4
|
||||
noop
|
||||
addx -9
|
||||
addx 12
|
||||
addx 5
|
||||
addx 2
|
||||
addx -1
|
||||
addx 6
|
||||
addx -2
|
||||
noop
|
||||
addx 3
|
||||
addx 3
|
||||
addx 2
|
||||
addx -37
|
||||
addx 39
|
||||
addx -33
|
||||
addx -1
|
||||
addx 1
|
||||
addx 8
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 2
|
||||
addx 20
|
||||
addx -19
|
||||
addx 4
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 3
|
||||
addx 2
|
||||
addx 5
|
||||
noop
|
||||
addx 1
|
||||
addx 4
|
||||
addx -21
|
||||
addx 22
|
||||
addx -38
|
||||
noop
|
||||
noop
|
||||
addx 7
|
||||
addx 32
|
||||
addx -27
|
||||
noop
|
||||
addx 3
|
||||
addx -2
|
||||
addx 2
|
||||
addx 5
|
||||
addx 2
|
||||
addx 2
|
||||
addx 3
|
||||
addx -2
|
||||
addx 2
|
||||
noop
|
||||
addx 3
|
||||
addx 5
|
||||
addx 2
|
||||
addx 3
|
||||
noop
|
||||
addx -39
|
||||
addx 2
|
||||
noop
|
||||
addx 4
|
||||
addx 8
|
||||
addx -8
|
||||
addx 6
|
||||
addx -1
|
||||
noop
|
||||
addx 5
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 3
|
||||
addx 5
|
||||
addx 2
|
||||
addx -11
|
||||
addx 12
|
||||
addx 2
|
||||
noop
|
||||
addx 3
|
||||
addx 2
|
||||
addx 5
|
||||
addx -6
|
||||
noop
|
||||
48
2022/day10/src/main.rs
Normal file
48
2022/day10/src/main.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
#![warn(clippy::all, clippy::pedantic)]
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::{prelude::*, BufReader};
|
||||
use std::str;
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
//Read in file
|
||||
let file = File::open("input")?;
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut part1: Vec<_> = Vec::new();
|
||||
let mut part2 = [[b'.'; 40]; 6];
|
||||
let mut x_reg = 1;
|
||||
let mut pc = 0_u32;
|
||||
|
||||
reader.lines().for_each(|line| {
|
||||
let line = line.unwrap();
|
||||
let op = match line.split(' ').collect::<Vec<_>>()[..] {
|
||||
["addx", x] => Some(x.parse::<u32>().unwrap()),
|
||||
["noop"] => None,
|
||||
_ => panic!("invalid command: {line}"),
|
||||
};
|
||||
let steps = if op.is_some() { 2 } else { 1 };
|
||||
for i in 0..steps {
|
||||
let row = pc / 40;
|
||||
let col = pc % 40;
|
||||
if col - 1 == x_reg || col == x_reg || col + 1 == x_reg {
|
||||
part2[row as usize][col as usize] = b'#';
|
||||
}
|
||||
pc += 1;
|
||||
if pc < 221 && (pc - 20) % 40 == 0 {
|
||||
part1.push(pc * x_reg);
|
||||
}
|
||||
if i == steps - 1 {
|
||||
if let Some(x) = op {
|
||||
x_reg += x;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
println!("Part 1: {}", part1.iter().sum::<u32>());
|
||||
for row in part2 {
|
||||
println!("Part 2: {}", str::from_utf8(&row).unwrap());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user