Compare commits

..

No commits in common. "c32121a4b20d796fae0b8ac5e6f08defff8e40bf" and "f29621d4ca0a5b5ae319ae2c28e0ee34fda1d269" have entirely different histories.

3 changed files with 5 additions and 95 deletions

View File

@ -5,7 +5,7 @@ pub mod d4;
pub mod d5; pub mod d5;
pub mod d6; pub mod d6;
pub mod d7; pub mod d7;
pub mod d8; // pub mod d8;
// pub mod d9; // pub mod d9;
// pub mod d10; // pub mod d10;
// pub mod d11; // pub mod d11;

View File

@ -13,6 +13,10 @@ fn _parse (data: &str) -> I {
}).collect()).collect() }).collect()).collect()
} }
fn _solve (data: &I) -> O {
Default::default()
}
fn _silver (data: &I) -> O { fn _silver (data: &I) -> O {
let mut out = format!(""); let mut out = format!("");

View File

@ -1,94 +0,0 @@
use crate::prelude::*;
pub type I = Vec<Inst>;
pub type O = usize;
#[derive(Clone, Debug)]
pub enum Inst {
Rect(usize, usize),
RotateY(usize, usize),
RotateX(usize, usize),
}
#[allow(dead_code)]
impl Inst {
fn from_line (data: &str) -> Self {
if let Some(suffix) = data.strip_prefix("rotate row y=") && let Some((y, rotation)) = suffix.split_once(" by ") {
Self::RotateY(y.parse().unwrap(), rotation.parse().unwrap())
} else if let Some(suffix) = data.strip_prefix("rotate column x=") && let Some((x, rotation)) = suffix.split_once(" by ") {
Self::RotateX(x.parse().unwrap(), rotation.parse().unwrap())
} else {
let (a, b) = data.strip_prefix("rect ").unwrap().split_once('x').unwrap();
Self::Rect(a.parse().unwrap(), b.parse().unwrap())
}
}
}
fn _parse (data: &str) -> I {
data.lines().map(Inst::from_line).collect()
}
fn _solve (data: &I) -> Vec<Vec<bool>> {
let mut state = vec![vec![false; 50]; 6];
for i in data {
match i {
Inst::Rect(a, b) => {
for y in 0..*b {
for x in 0..*a {
state[y][x] = true;
}
}
},
Inst::RotateY(y, r) => {
state[*y].rotate_right(*r);
},
Inst::RotateX(x, r) => {
let mut view = state.iter().map(|e| e[*x]).collect_vec();
view.rotate_right(*r);
for (y, n) in view.into_iter().enumerate() {
state[y][*x] = n;
}
}
}
}
state
}
fn _silver (data: &I) -> O {
_solve(data).into_iter().flatten().filter(|e| *e).count()
}
fn _gold (data: &I) -> () {
let data = _solve(data).into_iter().map(|line| line.into_iter().map(|f| if f { 'X' } else { '.' }).collect::<String>()).collect_vec();
println!("{:#?}", data);
}
#[cfg(test)]
mod test {
use super::*;
fn read () -> I {
let data = inc!(8);
_parse(data)
}
#[test]
fn silver () {
let data = read();
let ans = _silver(&data);
assert_eq!(ans, 115)
}
#[test]
fn gold () {
let data = read();
let ans = _gold(&data);
// EFEYKFRFIJ
assert_eq!(ans, ())
}
}