Compare commits
No commits in common. "2deb1e1a03df7e1f5e30a718bf3d1b01dc9144e9" and "5444a86e226f7baaa75168bc9b3d93ab91cf2b40" have entirely different histories.
2deb1e1a03
...
5444a86e22
|
@ -1,110 +0,0 @@
|
||||||
\.................-....-.-.|....................|......./.|.\................|...........|....--..............
|
|
||||||
............-...................|.............|..-.......-/..............-....\...............................
|
|
||||||
|.......//...........................................|...............-......../.....\....................\....
|
|
||||||
....|......-.-.............-......\.....\......../..................../.......................................
|
|
||||||
..\..\../................../.............-............|....-.........................|......|...............|.
|
|
||||||
-..|........................./.................\.........\./.............\..|..-...-.............\............
|
|
||||||
.\......||-..................../................-................./....|........................|.............
|
|
||||||
..............\./...........-.........../-................-.........\...\........../-.......|.................
|
|
||||||
....-..........-.-.....\......................../.......-..........-/.....................||................|.
|
|
||||||
./..........|/............................\./............................./....../........\...-|............\-
|
|
||||||
........\.............................-...../............---...........|...............|......\\..............
|
|
||||||
........//....|.\......./...\.............|..............\............./...........-.|..-.............|.......
|
|
||||||
...................\...........-/..-......\...|........-.|................\-.......|........\.................
|
|
||||||
|.|....../|............\./..-........\..............................-.....................|....../............
|
|
||||||
............-....................-..............-..-................|.//.............-.............-..........
|
|
||||||
..........-.......-......|-................./........../...\........-.......................-..\.......\......
|
|
||||||
................../....|............-....../................./.....................|.................-........
|
|
||||||
...\..............--..|.....||.....\.............\../................................................-.-...../
|
|
||||||
.........-......|....-.................-.......\-................./..|...................|\.....\.....|.|-....
|
|
||||||
......................-......................-............/....................\...../...\..../...............
|
|
||||||
...../......-...............\...-....|......../.........\................................|.........../........
|
|
||||||
........../.......\..............-...............\........-|....-......-.............|...........|........./..
|
|
||||||
./...............\....../....../..../...................................................|.....|.|../......./..
|
|
||||||
....|\........\-...../...................-.............\.\..................................././..........\...
|
|
||||||
....................................-..../......................-..///......-...|.|..........................|
|
|
||||||
.........-\.....-...........|........./..........-..\.....\./...................-........................-....
|
|
||||||
....../.......././......--.....|.\..-...-....\..........................-....-...-..|.|.....|.......\-./......
|
|
||||||
...-....................-................|.............-../........|../........-.............|\...............
|
|
||||||
...../...........-......../................|................|.....\.....-.............../...|....../\.........
|
|
||||||
./...\.....\..-./.........................|................................-....................-.............
|
|
||||||
.............\|.../....\\.....\..|...........\.....................|......|.|.....|.....-............\.\......
|
|
||||||
........................|......-..........-.../......-........|...../.\|...-................................|.
|
|
||||||
.......\...-...\..........|.....\...................\.........|..........-/.........\...................../...
|
|
||||||
.-|.......|............./..|./....-.../...\............-......../..............-.......//...-...........||.\..
|
|
||||||
..|..\./..-........\..|....-..\.........../..............................|..\..................../..|...../-..
|
|
||||||
.|.........-.\...........................\..../......./....||............\..........|............-.\|.........
|
|
||||||
....................\..../|............................\.../..|........./...../............||........\....../.
|
|
||||||
....................../.....|...................|......|.................|..|.......|................|........
|
|
||||||
.....................\.........-..../.........../../..-......\.................|.../....................../...
|
|
||||||
........\.-................/........\...../....../.|.\...|/../..........................................-.....
|
|
||||||
....................................|......./...../............-................-/..|.-....................\..
|
|
||||||
..|.........................-....................../...|.....|.............../.........../.....|\.............
|
|
||||||
.......................................|.\.|.......................-.......|..............\............-./....
|
|
||||||
..........//................\..|./................-.................-..../../|................................
|
|
||||||
.|......................................./............/..-.......-.|.........................\|..|............
|
|
||||||
............................/.-..................-./..../..............|-.........-|..........................
|
|
||||||
.................-...|................\.........|\...............................\...........\...//...........
|
|
||||||
........\..|.|--.............|.......\.................|......|\./.........................\.|................
|
|
||||||
.-|.............|\|.....\|././...|..\.............\..\...................\...........\...../..................
|
|
||||||
..../..............-..|...|.........-.........\.....-...........-.....|...\.-....-../.................\.......
|
|
||||||
........\.|........\\.........-...............-.......-..................................../..........|.......
|
|
||||||
...............-...................\/...............\..-\...........|.-........-.\-.....\....\..../......-....
|
|
||||||
.../-......./..............|.......|..//......-....................../.|....\......|..\.........../-\.........
|
|
||||||
.-....|./....-.../....../.....-..............\..-..\..-............\................|...|..........-.......|..
|
|
||||||
|......../...................\..../....\......./..|.................\...............\.........\../.|......../.
|
|
||||||
../............/........|..|.......................................\../\...............\............/.......\.
|
|
||||||
........-.-...\........../.......-....-............./.............-......./................\..........-.......
|
|
||||||
.../-................/......|/........-......|..........|..-..............|/..........................-.......
|
|
||||||
......./............../...................|../...../................./../..........\../.....\....\............
|
|
||||||
..............-..|../-........................|...\.../...-/..........\.......\......\.................-....-.
|
|
||||||
......................................-/.\........................../......-..\..\........\...............|..\
|
|
||||||
.............-.........../-|........-........\....-.....\....../..\........................\......|.......\...
|
|
||||||
.././....................|\.../\.........\.|.............../..../...|......./.\...|.......\.........|.........
|
|
||||||
......................./........./-./...........................|/...\........-.../.................||........
|
|
||||||
..............|./........\..............\.............................|/................../............|.-..|.
|
|
||||||
.........................-......../........./.....|....-..-.-..............-.-......../.......\...\./.........
|
|
||||||
.-............../../....\//......../...|......|......\..................-......\.....-....\|.........|........
|
|
||||||
..............-.....................\.................\.|...-............................|......\.............
|
|
||||||
\\.....|...........\............|............................../............................................\.
|
|
||||||
.-........../|...\..............-...............................\...........\.....|......\..........\.........
|
|
||||||
.\............\.|....-........./....../../.....-..\........|...............-..................|............-.|
|
|
||||||
.....\......-.........-.........|....../..-....|.....\..../....|........-.....................................
|
|
||||||
..........\-..-..../\.....................\.........-...........|..../-.......................\....-..........
|
|
||||||
...../............./..|..................../............../../.........|...............-../...................
|
|
||||||
.....|...../.....|......-.............................|...........-......................./............/......
|
|
||||||
.....................||./.-.................-.........\.\..................-..............\...--.........\....
|
|
||||||
.|......-......-.\.......-......\....\..\..|.........../......./.....................-..........|.............
|
|
||||||
.....\.....\............................--..................|..-........\....\...\.|.\.-...........\...\......
|
|
||||||
./...........\.......\/......|........./..|................\-................/....\...................\.\.....
|
|
||||||
..|...............................-.........-.|/......|.....|........\........................................
|
|
||||||
.......|............-............../............-......../..-...\|-...-..../...........-..........-..-/.......
|
|
||||||
............................-..\.......................................-.........................\..........-.
|
|
||||||
........................\.........|................||...-....\......\.....\.................\...\\....../.....
|
|
||||||
....\../.....-.......-.................-|...................-../.|-............|........-|......./../...\.....
|
|
||||||
..................................................\.......|......./..\./......../....|....-|.-................
|
|
||||||
....../.........|.......|...|.......\.../|...............-.......-\..\......././..................|..\.|...../
|
|
||||||
............|.....\...........-.............................../.....-.................-.../............/.../..
|
|
||||||
...../.......\............................|.....\....\................/..................\......../...........
|
|
||||||
..................-....\.........\|................/|......../.-................|...\......................--.
|
|
||||||
......-..-.....................................-\.........|.../.....................|..|.-.....\...|....\....-
|
|
||||||
......-......-.................-......|..................................................|....................
|
|
||||||
..\...............|......../........-......./.............../...........-..........|/.....///\.....-..........
|
|
||||||
.........../..|.............../..........\|.........................\...|.....\||....\...|.|/.....-....../....
|
|
||||||
...../...../.....-............................................|........|............|.........................
|
|
||||||
......-../\................../..............\............\.................../|...........|.............\.....
|
|
||||||
...........-..........................-....\..\..|.-..............................................\........|..
|
|
||||||
/.--..//....\...............................-............|..././..............................................
|
|
||||||
/...............|.........../..../......................\.....|............|...........|...................-..
|
|
||||||
..-................\../|......../...................../...........\..|.|\../..................................
|
|
||||||
....|...../.....-......\.........................-.....//...............|.........-.......|...-....--.........
|
|
||||||
....|..\.-..../....................|..........\............./...........\.../.................................
|
|
||||||
............................\...................................../.......................|...........\.......
|
|
||||||
.........../.....-.....................\..\.-..|............-...............\.........................-.......
|
|
||||||
......-.......-\.\......\..-.-........./...........\..........|........................\.....-.....\..........
|
|
||||||
..............-....../.-............./........../..............\-....-.../...../.-............\......./.-.....
|
|
||||||
......|...................................................||..../...|\.....................-.../...\........|.
|
|
||||||
......|.//........................-...../...........-..\...|......|..................../........../...........
|
|
||||||
.....................................................|.........//...........|\.....\....................|.../.
|
|
||||||
............-..||...........|....../....................\...\................................../.......|......
|
|
||||||
..\....\......./-\.\...........-\................|.........../................||.../.....-...........\........
|
|
|
@ -1,10 +0,0 @@
|
||||||
.|...\....
|
|
||||||
|.-.\.....
|
|
||||||
.....|-...
|
|
||||||
........|.
|
|
||||||
..........
|
|
||||||
.........\
|
|
||||||
..../.\\..
|
|
||||||
.-.-/..|..
|
|
||||||
.|....-|.\
|
|
||||||
..//.|....
|
|
|
@ -11,7 +11,7 @@ pub struct DaySolution ;
|
||||||
impl Solution for DaySolution {
|
impl Solution for DaySolution {
|
||||||
|
|
||||||
fn input_path(&self) -> &'static str {
|
fn input_path(&self) -> &'static str {
|
||||||
"input/2023/day_15/input.txt"
|
"input/2023/day_15/input_test.txt"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part_one(&self) -> String {
|
fn part_one(&self) -> String {
|
||||||
|
|
|
@ -18,6 +18,8 @@ pub fn part_two(input_lines: Vec<String>) -> String {
|
||||||
let parsed_seq = parse_sequence(seq);
|
let parsed_seq = parse_sequence(seq);
|
||||||
let hash = hash_sequence(parsed_seq[0].clone());
|
let hash = hash_sequence(parsed_seq[0].clone());
|
||||||
|
|
||||||
|
println!("{}: {:?}", hash, parsed_seq.clone());
|
||||||
|
|
||||||
if parsed_seq[1] == "=" {
|
if parsed_seq[1] == "=" {
|
||||||
let mut lenses = boxes.get(&hash).unwrap().clone();
|
let mut lenses = boxes.get(&hash).unwrap().clone();
|
||||||
let mut found: bool = false;
|
let mut found: bool = false;
|
||||||
|
@ -49,15 +51,14 @@ pub fn part_two(input_lines: Vec<String>) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut res = 0;
|
println!();
|
||||||
for i in 0..256 {
|
for (k, v) in &boxes {
|
||||||
let lenses = boxes.get(&i).unwrap().clone();
|
if v.len() > 0 {
|
||||||
for (j, lens) in lenses.iter().enumerate() {
|
println!("{}: {:?}", k, v);
|
||||||
res += (i + 1) * (j + 1) * lens.1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res.to_string()
|
String::from("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash_sequence(sequence: String) -> usize {
|
fn hash_sequence(sequence: String) -> usize {
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
|
||||||
pub enum Contraption {
|
|
||||||
Empty,
|
|
||||||
MirrorLeft,
|
|
||||||
MirrorRight,
|
|
||||||
SplitterVert,
|
|
||||||
SplitterHoriz,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Copy, Eq, Hash)]
|
|
||||||
pub enum Direction {
|
|
||||||
Up,
|
|
||||||
Down,
|
|
||||||
Left,
|
|
||||||
Right,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn print_contraption(contraption: &Vec<Vec<Contraption>>) {
|
|
||||||
for row in contraption {
|
|
||||||
for c in row {
|
|
||||||
match c {
|
|
||||||
Contraption::Empty => print!("."),
|
|
||||||
Contraption::MirrorLeft => print!("\\"),
|
|
||||||
Contraption::MirrorRight => print!("/"),
|
|
||||||
Contraption::SplitterVert => print!("|"),
|
|
||||||
Contraption::SplitterHoriz => print!("-"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
println!();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn print_energized(contraption: &Vec<Vec<bool>>) {
|
|
||||||
for row in contraption {
|
|
||||||
for c in row {
|
|
||||||
if *c {
|
|
||||||
print!("#");
|
|
||||||
} else {
|
|
||||||
print!(".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
println!();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
pub mod part_one;
|
|
||||||
// pub mod part_two;
|
|
||||||
pub mod common;
|
|
||||||
|
|
||||||
use crate::utils::solution::Solution;
|
|
||||||
use crate::utils::input_reader;
|
|
||||||
|
|
||||||
pub struct DaySolution ;
|
|
||||||
|
|
||||||
|
|
||||||
impl Solution for DaySolution {
|
|
||||||
|
|
||||||
fn input_path(&self) -> &'static str {
|
|
||||||
"input/2023/day_16/input.txt"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn part_one(&self) -> String {
|
|
||||||
input_reader::read_input_file(self.input_path(), part_one::part_one)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn part_two(&self) -> String {
|
|
||||||
// input_reader::read_input_file(self.input_path(), part_two::part_two)
|
|
||||||
String::from("Not implemented")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,110 +0,0 @@
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
use super::common::{Contraption, Direction};
|
|
||||||
|
|
||||||
pub fn part_one(input_lines: Vec<String>) -> String {
|
|
||||||
|
|
||||||
let mut contraption: Vec<Vec<Contraption>> = Vec::new();
|
|
||||||
for line in input_lines {
|
|
||||||
let mut row: Vec<Contraption> = Vec::new();
|
|
||||||
for c in line.chars() {
|
|
||||||
match c {
|
|
||||||
'.' => row.push(Contraption::Empty),
|
|
||||||
'\\' => row.push(Contraption::MirrorLeft),
|
|
||||||
'/' => row.push(Contraption::MirrorRight),
|
|
||||||
'|' => row.push(Contraption::SplitterVert),
|
|
||||||
'-' => row.push(Contraption::SplitterHoriz),
|
|
||||||
_ => panic!("Unknown character: {}", c),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
contraption.push(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
// print_contraption(&contraption);
|
|
||||||
let mut energized: Vec<Vec<bool>> = vec![vec![false; contraption[0].len()]; contraption.len()];
|
|
||||||
let mut memory: HashSet<(i32, i32, Direction)> = HashSet::new();
|
|
||||||
let mut stack: Vec<(i32, i32, Direction)> = Vec::new();
|
|
||||||
stack.push((0,0, Direction::Right));
|
|
||||||
|
|
||||||
while let Some((i, j, direction)) = stack.pop() {
|
|
||||||
|
|
||||||
if i >= contraption[0].len() as i32 || j >= contraption.len() as i32 || i < 0 || j < 0 {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if memory.contains(&(i, j, direction)) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
memory.insert((i, j, direction));
|
|
||||||
}
|
|
||||||
|
|
||||||
energized[i as usize][j as usize] = true;
|
|
||||||
|
|
||||||
let tile = &contraption[i as usize][j as usize];
|
|
||||||
// println!("{} {}: {:?} - {:?}", i, j, direction, tile);
|
|
||||||
|
|
||||||
match (tile, direction) {
|
|
||||||
(Contraption::Empty, Direction::Right) => {
|
|
||||||
stack.push((i, j+1, Direction::Right));
|
|
||||||
},
|
|
||||||
(Contraption::Empty, Direction::Left) => {
|
|
||||||
stack.push((i, j-1, Direction::Left));
|
|
||||||
},
|
|
||||||
(Contraption::Empty, Direction::Up) => {
|
|
||||||
stack.push((i-1, j, Direction::Up));
|
|
||||||
},
|
|
||||||
(Contraption::Empty, Direction::Down) => {
|
|
||||||
stack.push((i+1, j, Direction::Down));
|
|
||||||
},
|
|
||||||
(Contraption::MirrorLeft, Direction::Right) => {
|
|
||||||
stack.push((i+1, j, Direction::Down));
|
|
||||||
}
|
|
||||||
(Contraption::MirrorLeft, Direction::Left) => {
|
|
||||||
stack.push((i-1, j, Direction::Up));
|
|
||||||
},
|
|
||||||
(Contraption::MirrorLeft, Direction::Up) => {
|
|
||||||
stack.push((i, j-1, Direction::Left));
|
|
||||||
},
|
|
||||||
(Contraption::MirrorLeft, Direction::Down) => {
|
|
||||||
stack.push((i, j+1, Direction::Right));
|
|
||||||
},
|
|
||||||
(Contraption::MirrorRight, Direction::Right) => {
|
|
||||||
stack.push((i-1, j, Direction::Up));
|
|
||||||
},
|
|
||||||
(Contraption::MirrorRight, Direction::Left) => {
|
|
||||||
stack.push((i+1, j, Direction::Down));
|
|
||||||
},
|
|
||||||
(Contraption::MirrorRight, Direction::Up) => {
|
|
||||||
stack.push((i, j+1, Direction::Right));
|
|
||||||
},
|
|
||||||
(Contraption::MirrorRight, Direction::Down) => {
|
|
||||||
stack.push((i, j-1, Direction::Left));
|
|
||||||
},
|
|
||||||
(Contraption::SplitterVert, Direction::Right | Direction::Left) => {
|
|
||||||
stack.push((i-1, j, Direction::Up));
|
|
||||||
stack.push((i+1, j, Direction::Down));
|
|
||||||
},
|
|
||||||
(Contraption::SplitterVert, Direction::Down) => {
|
|
||||||
stack.push((i+1, j, Direction::Down));
|
|
||||||
},
|
|
||||||
(Contraption::SplitterVert, Direction::Up) => {
|
|
||||||
stack.push((i-1, j, Direction::Up));
|
|
||||||
},
|
|
||||||
(Contraption::SplitterHoriz, Direction::Up | Direction::Down) => {
|
|
||||||
stack.push((i, j-1, Direction::Left));
|
|
||||||
stack.push((i, j+1, Direction::Right));
|
|
||||||
},
|
|
||||||
(Contraption::SplitterHoriz, Direction::Left) => {
|
|
||||||
stack.push((i, j-1, Direction::Left));
|
|
||||||
},
|
|
||||||
(Contraption::SplitterHoriz, Direction::Right) => {
|
|
||||||
stack.push((i, j+1, Direction::Right));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// print_energized(&energized);
|
|
||||||
|
|
||||||
let energized_count = energized.iter().flatten().filter(|x| **x).count();
|
|
||||||
energized_count.to_string()
|
|
||||||
}
|
|
|
@ -13,7 +13,6 @@ pub mod day_12_hot_springs;
|
||||||
pub mod day_13_point_of_incidence;
|
pub mod day_13_point_of_incidence;
|
||||||
pub mod day_14_parabolic_reflector_dish;
|
pub mod day_14_parabolic_reflector_dish;
|
||||||
pub mod day_15_lens_library;
|
pub mod day_15_lens_library;
|
||||||
pub mod day_16_the_floor_will_be_lava;
|
|
||||||
|
|
||||||
pub fn run(day: &str) {
|
pub fn run(day: &str) {
|
||||||
let solution: Box<dyn Solution> = match day {
|
let solution: Box<dyn Solution> = match day {
|
||||||
|
@ -30,7 +29,6 @@ pub fn run(day: &str) {
|
||||||
"13" => Box::new(day_13_point_of_incidence::DaySolution),
|
"13" => Box::new(day_13_point_of_incidence::DaySolution),
|
||||||
"14" => Box::new(day_14_parabolic_reflector_dish::DaySolution),
|
"14" => Box::new(day_14_parabolic_reflector_dish::DaySolution),
|
||||||
"15" => Box::new(day_15_lens_library::DaySolution),
|
"15" => Box::new(day_15_lens_library::DaySolution),
|
||||||
"16" => Box::new(day_16_the_floor_will_be_lava::DaySolution),
|
|
||||||
_ => panic!("Invalid day specified"),
|
_ => panic!("Invalid day specified"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue