Compare commits

..

No commits in common. "061808310664f949d3e97ce9f250dd5d379a6341" and "daad18c6af28c2a944490c10bcff9cba7a031de8" have entirely different histories.

6 changed files with 0 additions and 279 deletions

View file

@ -1,7 +0,0 @@
13520
###...##..###..#..#.###..####..##..###..
#..#.#..#.#..#.#..#.#..#.#....#..#.#..#.
#..#.#....#..#.####.###..###..#..#.###..
###..#.##.###..#..#.#..#.#....####.#..#.
#....#..#.#....#..#.#..#.#....#..#.#..#.
#.....###.#....#..#.###..####.#..#.###..

View file

@ -1,147 +0,0 @@
noop
noop
noop
addx 6
addx -1
addx 5
noop
noop
noop
addx 5
addx 11
addx -10
addx 4
noop
addx 5
noop
noop
noop
addx 1
noop
addx 4
addx 5
noop
noop
noop
addx -35
addx -2
addx 5
addx 2
addx 3
addx -2
addx 2
addx 5
addx 2
addx 3
addx -2
addx 2
addx 5
addx 2
addx 3
addx -28
addx 28
addx 5
addx 2
addx -9
addx 10
addx -38
noop
addx 3
addx 2
addx 7
noop
noop
addx -9
addx 10
addx 4
addx 2
addx 3
noop
noop
addx -2
addx 7
noop
noop
noop
addx 3
addx 5
addx 2
noop
noop
noop
addx -35
noop
noop
noop
addx 5
addx 2
noop
addx 3
noop
noop
noop
addx 5
addx 3
addx -2
addx 2
addx 5
addx 2
addx -25
noop
addx 30
noop
addx 1
noop
addx 2
noop
addx 3
addx -38
noop
addx 7
addx -2
addx 5
addx 2
addx -8
addx 13
addx -2
noop
addx 3
addx 2
addx 5
addx 2
addx -15
noop
addx 20
addx 3
noop
addx 2
addx -4
addx 5
addx -38
addx 8
noop
noop
noop
noop
noop
noop
addx 2
addx 17
addx -10
addx 3
noop
addx 2
addx 1
addx -16
addx 19
addx 2
noop
addx 2
addx 5
addx 2
noop
noop
noop
noop
noop
noop

View file

@ -1,9 +0,0 @@
[package]
name = "rust_2022_10"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
aoc = { path = "../../../common/rust" }

View file

@ -1,108 +0,0 @@
#![feature(generators)]
#![feature(generator_clone)]
#![feature(iter_from_generator)]
#![warn(clippy::pedantic)]
use std::{
io::{stdin, Read},
iter,
str::FromStr,
};
type Word = i64;
#[derive(Debug, Clone, PartialEq, Eq)]
struct MachineState {
x: Word,
}
impl MachineState {
const fn new() -> Self {
Self { x: 1 }
}
fn execute(&mut self, op: MicroOp) {
match op {
MicroOp::Noop => {}
MicroOp::Addx(i) => self.x += i,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum MicroOp {
Noop,
Addx(Word),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Instruction {
Noop,
Addx(Word),
}
impl Instruction {
pub fn expand(self) -> impl Iterator<Item = MicroOp> {
iter::from_generator(move || match self {
Self::Noop => yield MicroOp::Noop,
Self::Addx(x) => {
yield MicroOp::Noop;
yield MicroOp::Addx(x);
}
})
}
}
impl FromStr for Instruction {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut args = s.split_whitespace();
match args.next().ok_or(())? {
"noop" => Ok(Self::Noop),
"addx" => {
let i = args.next().ok_or(())?.parse().map_err(|_| ())?;
Ok(Self::Addx(i))
}
_ => Err(()),
}
}
}
fn main() {
const START: MachineState = MachineState::new();
let mut data = String::new();
stdin().read_to_string(&mut data).unwrap();
let states: Vec<_> = data
.lines()
.map(|l| l.parse().unwrap())
.flat_map(Instruction::expand)
.scan(START, |state, op| {
let prev = state.clone();
state.execute(op);
Some(prev)
})
.enumerate()
.map(|(i, state)| (Word::try_from(i).unwrap() + 1, state))
.collect();
let sum: Word = states
.iter()
.skip(20 - 1)
.step_by(40)
.map(|(i, state)| i * state.x)
.sum();
println!("{:?}", sum);
let crt: Vec<_> = states
.iter()
.map(|(i, state)| ((i - 1) % 40).abs_diff(state.x) < 2)
.map(|x| if x { '#' } else { '.' })
.collect();
for line in crt.chunks_exact(40) {
println!("{}", line.iter().collect::<String>());
}
}

7
Cargo.lock generated
View file

@ -531,13 +531,6 @@ dependencies = [
"aoc",
]
[[package]]
name = "rust_2022_10"
version = "0.1.0"
dependencies = [
"aoc",
]
[[package]]
name = "ryu"
version = "1.0.11"

View file

@ -19,5 +19,4 @@ members = [
"2022/day7/rust",
"2022/day8/rust",
"2022/day9/rust",
"2022/day10/rust",
]