Add day 7 part 1 (rough version)
parent
0c31f900d1
commit
61e0d608cc
|
|
@ -0,0 +1,143 @@
|
||||||
|
......................................................................S......................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
......................................................................^......................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.....................................................................^.^.....................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
....................................................................^.^.^....................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...................................................................^.^.^.^...................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..................................................................^...^.^.^..................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.................................................................^...^.^.^.^.................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
................................................................^.^.........^................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...............................................................^.^.^.^.......^...............................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..............................................................^.^...^.....^...^..............................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.............................................................^.....^.^.^.^.^...^.............................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
............................................................^.^...^...^.^.^.^.^.^............................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...........................................................^.^...^.^.^...^.^.^.^.^...........................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..........................................................^.^.^.^.^.......^.^.^.^.^..........................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.........................................................^...^.^.^...^.^.....^.....^.........................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
........................................................^.^.^.^...^.^.^...^...^.^...^........................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.......................................................^...^.^.^.....^...^.^.^.^...^.^.......................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
......................................................^.....^.^.^.^.^...^.^...^.^.^.^.^......................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.....................................................^.^...^.^.^.^.^...^.^.^...^...^.^.^.....................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
....................................................^.....^.^.^.^.^.^.^.^.^...^.^...^.^.^....................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...................................................^.......^.^...^...^.^...^.^.^...^.^.^.^...................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..................................................^.^.^.^.^.^.^...^...^.......^.....^.^.^.^..................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.................................................^...^.^...........^.^.....^.^.^.........^.^.................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
................................................^.^.....^.^...^.^.^.......^.^.^...^.^.^.^.^.^................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...............................................^.^.^.^.^.^.....^.^.^.......^.^...^.^.^...^.^.^...............................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..............................................^.^.^.....^...^...^.^.^.....^...........^.^.^.^.^..............................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.............................................^.^.....^.^.......^...^.^.^.^.^.^.^.....^.......^.^.............................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
............................................^...^.^.^.^.^.^.^.^...^.^...^.^.......^.^.....^.^.^.^............................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...........................................^.^.^.^.^...^.^...^.^.^.^.^.^.^.^.^.....^.^.^.......^.^...........................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..........................................^.^...^.^...^.^.^...^.^...^.^.^.^.^...^.^...^.^.^.....^.^..........................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.........................................^...^...^.^.^.^.^.^...^.^.^.^.^...^.^.^.^.^...^.^...^...^.^.........................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
........................................^.^.....^.^.^.^...^.^...^.^.^.^.^.^.^...^...^...^.....^.^.^.^........................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.......................................^.^...^.....^.^.^.^...^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.......................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
......................................^.^...^.^.....^.^...^.^.^.^...^.^.^.^.....^.^...^.^.^...^.......^......................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.....................................^.^.^...^.^.^.......^...^.^.^.^.^...^.^.^...^.^.....^.^.........^.^.....................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
....................................^...^.....^.^...^.^.......^.^.....^.....^.^...^...^.^.^...^.^.....^.^....................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...................................^.....^.^.^.^.^.^.^...^.^...^.^...^...^...^.^.^...^.^.^.^...^.^.^.^.^.^...................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..................................^.^.^...^.^...^.^.^.......^.^...^.^.^...^.^.^.^.^.....^.^.^.^...^.^.^.^.^..................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.................................^.^.^.....^.....^...^...^.^.^.^.^.^.^.^...^.^.^.^...^...^.^...^.^...^.....^.................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
................................^.........^...^...^.^.^.^...^.^...^.^.......^.^.^.^.^.^.^.^.^.^.............^................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...............................^...^.^...^.^.^...^.^.^.....^...^...^...^...^.^.^.^.....^...^.^.^.^.^.^...^.^.^...............................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..............................^.^.^.^.^.^.....^.^.^...^...^.^.^...........^.^...^.^.^.^.^...^.^.^.^.....^.^...^..............................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.............................^...^.^.^...^.^...^...^.^.....^.^.^...^.^.^...^...^.^.^...^.^.^.^.^.^.^.^...^.^.^.^.............................
|
||||||
|
.............................................................................................................................................
|
||||||
|
............................^...^...^...^.^.^...^...^...^.^...^.^.^.^.^.^.^.^...^.^.^.^.^...^.^...^.^.....^.^.^.^............................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...........................^.^...^.^...^...^.^.^.^...^.^.^.^.^...^.^...^.^.^...^.^.^.^.^.^...^.^.^...^.^.^.^.^.^.^...........................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..........................^.....^.^.^...^...^.^.^...^.^.^.^.^.^.^.^.^...^.^.....^.^.......^.....^.^.^.^.^.^.^.^.^.^..........................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.........................^.^.^.^.^.^.^.^...^.^.....^.^.^...^.^.^.^.....^.^.^...^.^...^.^.^.^.^...^.^...^.^.^.^...^.^.........................
|
||||||
|
.............................................................................................................................................
|
||||||
|
........................^.^.^.^.^.^.^.^.....^.^.^.^...^.^.....^.^.^.^.^.^.^.^.^.^.^.....^.....^.^.....^...^.^.......^........................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.......................^.....^.^.^.^...^.^...^.^.^.^.^.^...^.^.^.^...^...^.^.^.^...^.^.^.......^.^...^.^.^.^.^.^...^.^.......................
|
||||||
|
.............................................................................................................................................
|
||||||
|
......................^...^...^...^.^...^.^.^.....^.^.^...^.........^.^...^.^.^...^.^...........^.^.^.^.....^.^.....^.^......................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.....................^...^.^...^.^...^.^.^...^.^.^.^.^.^...^.^.^.^.^.^.....^.^...^.^.^.^.^.^.^.......^.^.^.^.^...^...^.^.....................
|
||||||
|
.............................................................................................................................................
|
||||||
|
....................^.^.....^.^.^.^.^.^.^.....^.^...^...^.^.^.^.^.^.....^...^.^.^.^.^.^.^.^.^.^...^.....^.^.^.^.^.^...^.^....................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...................^.^.^.^.^...^.^.^.^...^...^.^.^.....^.....^...^...^.^...^.^.^.^.^...^.....^...^.^...^.^.............^.^...................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..................^.^.^.^.^.^.^.....^.^...^...^.^.......^.^.^.^.^.^...^.^.^...^.^.^.......^.^.^.^.^.^...^.^.^...^.^...^.^.^..................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.................^.^.^...^.^.^.^.^.^...^.^.^.^.^.^.^...............^.^...^...^.^.^.....^.^...^.^.^.^.^...^.....^...^...^.^.^.................
|
||||||
|
.............................................................................................................................................
|
||||||
|
................^.^.^.^...^.^.....^.^.^.^.^.^...^.^.^.^...^...^.....^.^...^.^.^.^...^.^.^...^.^.^.....^.......^.^.^.....^.^.^................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...............^.^.^.^.^...^.^.^...^.^...^.^.....^...^.^.^...^.....^.^.^.....^.^...^.^.^...^.^.^.^.^.^...^.^.^.^.^.^.......^.^...............
|
||||||
|
.............................................................................................................................................
|
||||||
|
..............^.^.^.^...^.^.^.^.^.........^.^.......^.^.....^.......^.^.^.^.^.^...^.......^.^.^.^.......^.....^.^...^.....^.^.^..............
|
||||||
|
.............................................................................................................................................
|
||||||
|
.............^.^...^.^.......^.....^.^.^...^.......^.....^.....^...^.^.^.^.^.^.....^.^.....^.^.^.^.^.^...........^.^.^.^...^...^.............
|
||||||
|
.............................................................................................................................................
|
||||||
|
............^.^...^...^.^.^.^.^...^...^.......^.....^.^.....^.^...^...^.^.^...^.^...^.....^.....^...^.^.^.^.^.^...^...^.^...^.^.^............
|
||||||
|
.............................................................................................................................................
|
||||||
|
...........^.....^.^.^.^...^.^.^.^.....^...........^.^.^...^.^.^.^.^.^.....^.^...^.^...^...^...^...^.^.^...^.^.^.^.^.^.^...^.^...^...........
|
||||||
|
.............................................................................................................................................
|
||||||
|
..........^.^.^.^...^.^.......^.^.^.^...^.^.^.^...^.^.....^.^.^.^...^...^...^.^...^.^...^.^...^.^.^.^.......^.^.^.^.^...^...^.^.^.^..........
|
||||||
|
.............................................................................................................................................
|
||||||
|
.........^.^.^.^...^.^...^.......^.^...^.^.^...^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.......^...^.....^.^.^...^...^.........^...^.^...^.^.........
|
||||||
|
.............................................................................................................................................
|
||||||
|
........^.^.^...^...^...^.^.^.^.^.^.^.^.....^.^.^.......^.^.^.^.^.^.^.^.^.^.^...^...^...^.^.^.^...^.^.^.^...^...^.^.^...........^.^.^........
|
||||||
|
.............................................................................................................................................
|
||||||
|
.......^.^.^.^.^...^.^.^.^...^.^.....^.^.^.^.....^.^.....^.^.......^.^.^.^.^.^.......^.^.......^.^.^.^.....^...........^.^.^...^.^...^.......
|
||||||
|
.............................................................................................................................................
|
||||||
|
......^.^.^.^.^.^...^.^...^.^.^.^.....^.....^.^...^...^.^.^.....^...^.^.....^.^.^.^...^.^.^.^.....^...^.^.....^...^.......^.....^.....^......
|
||||||
|
.............................................................................................................................................
|
||||||
|
.....^.^.^...^.^.^.^.^.^.^...^.^...^.^.^.^.^.^.......^.^.^...^.........^.....^...^.^.^.^.........^.^.......^.^...^...^.^.^.....^.^...^.^.....
|
||||||
|
.............................................................................................................................................
|
||||||
|
....^...^.^.^.^.^.^.^.^.^.^...^.^...^.^...^.^.^.^.^.....^.^.......^.^...^.^...^.^.^.^.....^.^.^.....^.^...^.....^.^.^.^.^.........^.....^....
|
||||||
|
.............................................................................................................................................
|
||||||
|
...^.^.^.^...^...^.........^.^.^.^.^.^.^.^.^.^...^...........^.^...^...^.......^...^.^.^.^.^...^.^.^.^.......^.^...^.^...^.^.^.....^...^.^...
|
||||||
|
.............................................................................................................................................
|
||||||
|
..^.......^.......^.^.^...^.^.^.^.^.^.......^...^.^...^.^...^.^.^...^.^.....^...^.^.^.^.^...^...^...^.^.^.^.........^.^...^.^.^.^.^.^...^.^..
|
||||||
|
.............................................................................................................................................
|
||||||
|
.^.^.^.^.^.^.^.^.........^.........^...^.^.^.^...^...^.....^.......^...^.........^.^.^.^.^.^.^.^.^.^...^.^.^.^.......^.^.^...^.^.^.^.^.^...^.
|
||||||
|
.............................................................................................................................................
|
||||||
|
|
||||||
|
|
@ -0,0 +1,107 @@
|
||||||
|
use crate::utils;
|
||||||
|
|
||||||
|
pub fn answer(text : String) -> ( u16, u16 ) {
|
||||||
|
( text.trim()
|
||||||
|
.split_whitespace()
|
||||||
|
.fold(TachyonLayer::new(), |tl, s| tl.next_layer(s))
|
||||||
|
.splits
|
||||||
|
// 71 incorrect
|
||||||
|
// 1652 too high
|
||||||
|
, 0
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TachyonLayer {
|
||||||
|
beams : Vec<u8>,
|
||||||
|
layer: u8,
|
||||||
|
splits : u16,
|
||||||
|
}
|
||||||
|
impl TachyonLayer {
|
||||||
|
fn new() -> TachyonLayer {
|
||||||
|
TachyonLayer {
|
||||||
|
beams : Vec::new(),
|
||||||
|
layer : 0,
|
||||||
|
splits : 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_layer(&self, manifold : &str) -> TachyonLayer {
|
||||||
|
// println!("----------------------------------");
|
||||||
|
// println!("Old layer looks like: {:?}", self.beams);
|
||||||
|
|
||||||
|
// Currently tracked beams
|
||||||
|
// The list is sorted to make iteration easier
|
||||||
|
let mut beam_i: usize = 0;
|
||||||
|
let mut beam: Option<u8> = self.beams.get(beam_i).map(|&b| b);
|
||||||
|
|
||||||
|
// Last pushed beam, to avoid duplicates
|
||||||
|
let mut latest_push: Option<usize> = None;
|
||||||
|
|
||||||
|
// New Layer data
|
||||||
|
let mut new: Vec<u8> = Vec::new();
|
||||||
|
let mut splits: u16 = self.splits;
|
||||||
|
|
||||||
|
// Loop over the manifold string
|
||||||
|
for (i, c) in manifold.chars().enumerate() {
|
||||||
|
match c {
|
||||||
|
'.' => {
|
||||||
|
if let Some(b) = beam {
|
||||||
|
if i == usize::from(b) {
|
||||||
|
if let Some(lp) = latest_push {
|
||||||
|
if i == lp {} else {
|
||||||
|
new.push(b);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
new.push(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
beam_i += 1;
|
||||||
|
beam = self.beams.get(beam_i).map(|&b| b);
|
||||||
|
|
||||||
|
latest_push = Some(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'^' => {
|
||||||
|
if let Some(b) = beam {
|
||||||
|
if i == usize::from(b) {
|
||||||
|
if let Some(lp) = latest_push {
|
||||||
|
if i - 1 == lp {} else {
|
||||||
|
new.push(b-1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
new.push(b-1);
|
||||||
|
}
|
||||||
|
new.push(b+1);
|
||||||
|
|
||||||
|
beam_i += 1;
|
||||||
|
beam = self.beams.get(beam_i).map(|&b| b);
|
||||||
|
|
||||||
|
latest_push = Some(i+1);
|
||||||
|
splits += 1;
|
||||||
|
|
||||||
|
// println!("Encountered split #{} at x={} and y={}", splits, i, self.layer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'S' => {
|
||||||
|
new.push(i as u8);
|
||||||
|
latest_push = Some(i);
|
||||||
|
|
||||||
|
if let Some(b) = beam {
|
||||||
|
if i == usize::from(b) {
|
||||||
|
beam_i += 1;
|
||||||
|
beam = self.beams.get(beam_i).map(|&b| b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
panic!("Encountered unexpected input char")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// println!("New layer looks like: {:?}", new);
|
||||||
|
TachyonLayer { beams: new, layer : self.layer + 1, splits: splits }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,7 +4,7 @@ mod day_03;
|
||||||
mod day_04;
|
mod day_04;
|
||||||
mod day_05;
|
mod day_05;
|
||||||
mod day_06;
|
mod day_06;
|
||||||
// mod day_07;
|
mod day_07;
|
||||||
// mod day_08;
|
// mod day_08;
|
||||||
// mod day_09;
|
// mod day_09;
|
||||||
// mod day_10;
|
// mod day_10;
|
||||||
|
|
@ -62,12 +62,12 @@ pub fn day_06() -> DailyOutput {
|
||||||
( p1 as u128, p2 as u128, d )
|
( p1 as u128, p2 as u128, d )
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn day_07() -> DailyOutput {
|
pub fn day_07() -> DailyOutput {
|
||||||
// let s : String = read_from_file("inputs/07.txt");
|
let s : String = read_from_file("inputs/07.txt");
|
||||||
// let (p1, p2, d) = diagnostics::benchmark(s, day_07::answer);
|
let (p1, p2, d) = diagnostics::benchmark(s, day_07::answer);
|
||||||
|
|
||||||
// ( p1 as u128, p2 as u128, d )
|
( p1 as u128, p2 as u128, d )
|
||||||
// }
|
}
|
||||||
|
|
||||||
// pub fn day_08() -> DailyOutput {
|
// pub fn day_08() -> DailyOutput {
|
||||||
// let s : String = read_from_file("inputs/08.txt");
|
// let s : String = read_from_file("inputs/08.txt");
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ fn main() {
|
||||||
Some(4) => run_day(aoc2025::day_04),
|
Some(4) => run_day(aoc2025::day_04),
|
||||||
Some(5) => run_day(aoc2025::day_05),
|
Some(5) => run_day(aoc2025::day_05),
|
||||||
Some(6) => run_day(aoc2025::day_06),
|
Some(6) => run_day(aoc2025::day_06),
|
||||||
// Some(7) => run_day(aoc2025::day_07),
|
Some(7) => run_day(aoc2025::day_07),
|
||||||
// Some(8) => run_day(aoc2025::day_08),
|
// Some(8) => run_day(aoc2025::day_08),
|
||||||
// Some(9) => run_day(aoc2025::day_09),
|
// Some(9) => run_day(aoc2025::day_09),
|
||||||
// Some(10) => run_day(aoc2025::day_10),
|
// Some(10) => run_day(aoc2025::day_10),
|
||||||
|
|
@ -34,7 +34,7 @@ fn run_all_days() {
|
||||||
aoc.insert(4, aoc2025::day_04());
|
aoc.insert(4, aoc2025::day_04());
|
||||||
aoc.insert(5, aoc2025::day_05());
|
aoc.insert(5, aoc2025::day_05());
|
||||||
aoc.insert(6, aoc2025::day_06());
|
aoc.insert(6, aoc2025::day_06());
|
||||||
// aoc.insert(7, aoc2025::day_07());
|
aoc.insert(7, aoc2025::day_07());
|
||||||
// aoc.insert(8, aoc2025::day_08());
|
// aoc.insert(8, aoc2025::day_08());
|
||||||
// aoc.insert(9, aoc2025::day_09());
|
// aoc.insert(9, aoc2025::day_09());
|
||||||
// aoc.insert(10, aoc2025::day_10());
|
// aoc.insert(10, aoc2025::day_10());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue