Day 10 initial

This commit is contained in:
Max Nuding 2022-12-10 05:36:25 +00:00
parent 8787215fdf
commit a0b13e4f3e
2 changed files with 209 additions and 4 deletions

View File

@ -0,0 +1,146 @@
ddx 15
addx -11
addx 6
addx -3
addx 5
addx -1
addx -8
addx 13
addx 4
noop
addx -1
addx 5
addx -1
addx 5
addx -1
addx 5
addx -1
addx 5
addx -1
addx -35
addx 1
addx 24
addx -19
addx 1
addx 16
addx -11
noop
noop
addx 21
addx -15
noop
noop
addx -3
addx 9
addx 1
addx -3
addx 8
addx 1
addx 5
noop
noop
noop
noop
noop
addx -36
noop
addx 1
addx 7
noop
noop
noop
addx 2
addx 6
noop
noop
noop
noop
noop
addx 1
noop
noop
addx 7
addx 1
noop
addx -13
addx 13
addx 7
noop
addx 1
addx -33
noop
noop
noop
addx 2
noop
noop
noop
addx 8
noop
addx -1
addx 2
addx 1
noop
addx 17
addx -9
addx 1
addx 1
addx -3
addx 11
noop
noop
addx 1
noop
addx 1
noop
noop
addx -13
addx -19
addx 1
addx 3
addx 26
addx -30
addx 12
addx -1
addx 3
addx 1
noop
noop
noop
addx -9
addx 18
addx 1
addx 2
noop
noop
addx 9
noop
noop
noop
addx -1
addx 2
addx -37
addx 1
addx 3
noop
addx 15
addx -21
addx 22
addx -6
addx 1
noop
addx 2
addx 1
noop
addx -10
noop
noop
addx 20
addx 1
addx 2
addx 2
addx -6
addx -11
noop
noop
noop

View File

@ -1,15 +1,74 @@
use crate::read;
use std::collections::HashSet;
use itertools::Itertools;
use std::collections::HashSet;
use std::str::FromStr;
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
enum Command {
AddX(i32),
Noop,
}
impl Command {
fn from_str(s: &str) -> Self {
if s == "noop" {
Self::Noop
} else {
let sp = s.split_once(' ').unwrap();
Self::AddX(sp.1.parse().unwrap())
}
}
}
//#[derive(Debug, PartialEq, Eq, Default, Clone, Hash)]
pub fn run() {
let input = read("10");
let lines = input.lines();
let mut lines = input.lines();
let mut cycle = 1;
let mut is_busy = 0;
let mut v: i32 = 1;
let mut v_new: i32 = 1;
let mut sig_str = vec![];
let mut pixels = [false; 40];
'outer: loop {
if cycle == 20 || (cycle - 20) % 40 == 0 {
sig_str.push(cycle * v);
}
if is_busy == 0 {
match lines.next() {
Some(s) => {
let cmd = Command::from_str(s);
match cmd {
Command::Noop => {}
Command::AddX(x) => {
v_new += x;
is_busy = 1;
}
}
}
_ => {
break 'outer;
}
};
} else {
is_busy -= 1;
}
if is_busy == 0 {
v = v_new;
}
let pixel = cycle % 40;
let is_lit = pixel - 1 == v || pixel == v || pixel + 1 == v;
pixels[pixel as usize] = is_lit;
if pixel == 0 && cycle != 0 {
let row: String = pixels.map(|l| if l { '#' } else { '.' }).iter().collect();
println!("{}", row);
}
cycle += 1;
}
#[cfg(feature = "part1")]
{
println!("Day 10, Part 01: {}", "TODO");
println!("Day 10, Part 01: {}", sig_str.iter().sum::<i32>());
}
#[cfg(feature = "part2")]