Compare commits

..

No commits in common. "fdcda09607805c9535b2e8e4e5190fc2fc01cdaf" and "595f4ba264bfb58a8e3acfcbb6df488cd0cefddf" have entirely different histories.

13 changed files with 25 additions and 221 deletions

View file

@ -1,10 +0,0 @@
.|...\....
|.-.\.....
.....|-...
........|.
..........
.........\
..../.\\..
.-.-/..|..
.|....-|.\
..//.|....

View file

@ -1,110 +0,0 @@
\./....\../......................|............../-.......|....................|....../|\..../.............\...
...........|.-.............|.././........../........................./...........||.....................-....\
...............\.............-...................-............/.|...|.......-...............................-.
.......................................\..|-.../\....../.........|............/...|.....-.|...........\...|...
............/.-..|...\........|...........-......................\.........-........\....../....|.........|...
................-...........-|....\.................-........\........\...|.././......./......................
......................-....../.-........../........\....../..../.............-..........|.|.................|.
...|....................|.|../.......\.......|.......-...............|.......\......\....................|\...
.........\.............|.......-.....................|....................|..................-.......\-...\...
.../............-........../.||..../........-...../-.........-......./......\........|........................
....|..../.../../.....\..............-.-................../........|...../....\....\...................|......
.......\..-..................|..../..........|....................-............/...................\|../......
..-.\................../................../....\........./...\.\/.............................\|..............
.......-...............................-.......|....................|......................../...........|/...
................|...\-....-.......|/......./.......................|../.\-...-....../...\........\......\.|...
.....................-.......-....-................|.............-........-....................\....../....-..
\..|.|....-......../......../.../...................|.....................\..--...............-.......||......
.....-.\.....................-...\............../....\.......-/../|...|......../..\..................../......
....|...\......................|...|.../...|...............\...........-........................|.......--.-..
......\....|.-...........\................................|.................\..............\..|...............
...................||..................\|...................|....\............-....../........\.../.....-...-.
....................................|....|......./.\..................../..............|../.............\.....
......|...\./......../......|....\..././.......|...............................-.........../.-..\.............
.|.../....|.................-..............|..................\....../..........-..........|...|......|./.....
.........|.........../..\...|....../...................................................-......................
../....|/.............|.........../....................\.......\............./.........../.......-.........\-.
................\....................\.....-..|............-......-|...............\......\...-...............
..........|..........|...........|.../.............................-......\.....|\.........\.\.............../
.........................../...........\.............|................../.-.......-....././\.........-........
\....\................../..../.............-../......|.\.........-./..\........./.............................
.\..../..............|........../.......\........|.-.-........//\.......|.....-.../..-.....-...........-......
.......|................\.....................\.............-........./..................-...-...........\....
....../.......-......././.-.....|..........|.........|..........\............................/................
................\......\................\\.\..\........\.................................\......-/.....-......
..-...../......-.......................................|.................|......-.-...-.....\....../...-......
........................\....|.....\....|............................\..............\.......................\.
............................/|...|........\.\....\......-|......................|.....|.\-...-......-.........
\..|...........................\.................\.-................../................./..../.\..............
|.../.............\...............................|..|..-......-.......-.......|..\../.........-...........|..
...........|................\............................../.......................|..../-|...................
...\.|.\..................|.\-/....../-/..|/............\......../\.\...........\\.......-....-\..............
.................................-......./..-............|..\../..................................|/./|..../..
.../..../........|-.........|.....|..............-.................../.....|-.......|.....|...............\...
-..-...................//............................./.........-...............-.........|.../...........\...
.............././\......|..............\..................|...............-............................-......
/.........|/.....-../|......-.........|..-.-...........-........|..........-..................................
.............\.......|/........../.....|.......-....-....../......-...................-....|........\.........
\...|.|.../..|....../....-.........................-..............|.....\.......-........\........-....|......
-.-..\..........|........................./..........|..-./...........................|...........-........-..
....\./..............-.........|......./.-..............-.-../\........|..|.........-..............\...\.../..
..|...........\...../......../.../.........\....../....-..................................|/............-...|.
.../.........|..-................|..........|....\/..........|..|\.......|...........|........................
........../.............\...\.............................-...................|................-...-..........
.....................-.................................../../.............................-../................
.-........./......|........-...../...................\..|-........-...\..........././||.......................
.........|../../.....-...........-....-..-...|.............................\..................................
...................-.....\......../............./...............-.......\.........../........|............../.
.|\.............................................-.........-....|.....\..................-..-.......\..........
/................/....\.........\|...............-.............|......./...........-.....\........-.......--..
..........-........\........\-...\....\\........../...|./.........................\.....|.................\../
............................-.|............................\...\../..........................\......./...../..
.....//.......|..\.........-..\.........-....\..-..\.....-.....//.../.........................................
................................|....|..\............/|./.\....|.............-..\|................./..........
.....|.......-.............-../...../.........|../.....................|........................./.....|......
.-...\...../................\.-........|..|...|...|.........\|......|...../...../..........\................|.
.../../............-.........|................\.....\....-...................../.../...........-...|...../|...
..-..........-.......-.............\..............-..............\.......|....................................
..|................/........................-...................../.................................|......../
...../........\......./....../......||.......|-...............-.....-............../../.......................
...\..../...................-........\.........\............................/....|.........-..........-.......
.../................\....\..|-...........................\.-..-......|.|.-/.....-............./...............
../............\...........................-../....|....................-..............|........./......|...\\
.........................\..................|..\........................./....................\...............
/.............|.....................-.....\.....-..|............/..........|./...|....-...-....|-....../......
.\.-.....\............././.........................\..........-......................|........\...............
........\../............../......\.....\..-............|............\............../..|.......................
....-../....\..................................-......../...|................................................-
.......................\............-...................../.........\............-../.........\/..|../....-/|.
..../.............|....../............-.|......../.....................|...../..|.....-.............../.......
....................|\...........-...................................../.......................-...-..|..\.|/.
......................-....-\........../..............\.......-....\.....|...............\.........-..........
.|......../.....|.........||.................../.....\...|.........\........../........\............../.......
.-............/-..........-...........\..........\.......-....................................................
.....|/....-.../......-......................../.|./...\.......\/......./......../..\...../...|...|.........\-
.............../..\.../-......|\\......../............../............|/......................./.......\.......
.....\.-./....../............/..-................../....\..................-.................|.......-/..-....
.-................-..-...........................-..|............-.................../...........-...........|
-......\......|......\............../.............../...-/.../....\.........................-.....|.....-.....
.......\.....--.-............................\..........-./........||......|..\...../..../................|...
.............-.....|..../.......|............|....................-......\.............../|...............|...
............|........../........|....................-....|....../.........\..........-........-..-...........
..............|.................-....|...........\.|.../.........../..........-......\|.............\..-......
......-............\.......\....................................................|\..\.......................-.
................||...........\...-\/..|..............\.........................../.......\.|.............|...|
....-...................-...../....|............\.../.........-..../....\........../..../.|..........\........
........-.....\........../....|.........\......./...........\.......-..|............../...........-..|........
.................../.....-...........|....-...\......\...|...|...........................\.......||......\|...
......-.........|.....\....-..........|.......\....\..................................../........|...|./......
..................\.........../.............../.................../.........-.......-..../............/\.../..
........\...\...\....../.......\\........../............../.-.................../........|..............-.....
....../........................|................-.-......-....|......\\.-...-.|..........|..../...............
/.......-.....|.....\...................|...../..............|......|.../....................\.....|..........
|.\....-...............|/....|........../....................................\.-............................/.
.......................-...............-.|...................|......\.....-\..|.......-......./\.....-......-.
................................|../.................................-........-...................|...........
.....-.........\..-................./...........|...............|....................\/../../........|.-......
............................../......./.\/........./..|..............|.......................\................
......./.-.......\...........-...............|............|.............|..........|.|..........|.........--..
............-..............-.............\./...|.....|................|..........|/.............\.............
.../....................-........-.................../.....\.............-...................\................

View file

@ -1,112 +1,18 @@
use std::{collections::HashMap, fs}; use std::fs;
use rayon::prelude::*;
pub fn solve() { pub fn solve() {
let path = "res/16/input"; let path = "res/16/example";
let contents = fs::read_to_string(path).expect("I/O error, wrong path?"); let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?")); //let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
let grid: Vec<Vec<char>> = contents
.lines()
.map(|line| line.chars().collect::<Vec<_>>())
.collect();
let result: usize = solve_starts(&vec![(0usize, 0usize, 0u8)], &grid); let result: usize = 0;
println!("Result 1: {result}"); println!("Result 1: {result}");
let possible_starts: Vec<(usize, usize, u8)> = (0..grid.len())
.map(|x| (x, 0, 0))
.chain((0..grid.len()).map(|x| (x, grid[0].len() - 1, 2)))
.chain((0..grid[0].len()).map(|y| (0, y, 1)))
.chain((0..grid[0].len()).map(|y| (grid.len() - 1, y, 3)))
.collect();
let result: usize = solve_starts(&possible_starts, &grid); let result: usize = 0;
println!("Result 2: {result}"); println!("Result 2: {result}");
} }
fn solve_starts(possible_starts: &Vec<(usize, usize, u8)>, grid: &Vec<Vec<char>>) -> usize {
possible_starts
.par_iter()
.map(|start| {
// (x,y,dir) - dir=0 -> east, dir=1 -> south, ...
let mut starts: Vec<(usize, usize, u8)> = vec![*start];
let mut visited: HashMap<(usize, usize), u8> = HashMap::new();
while !starts.is_empty() {
let (mut x, mut y, mut dir) = starts.pop().unwrap();
'mov: loop {
if visited.contains_key(&(x, y)) && *visited.get(&(x, y)).unwrap() == dir {
break 'mov; // already been here
}
visited.insert((x, y), dir);
match grid[x][y] {
'/' => {
dir = match dir {
2 => 1,
1 => 2,
0 => 3,
3 => 0,
_ => panic!(),
}
}
'\\' => {
dir = match dir {
0 => 1,
1 => 0,
2 => 3,
3 => 2,
_ => panic!(),
}
}
'|' => {
if dir % 2 == 0 {
starts.push((x, y, 1));
starts.push((x, y, 3));
break 'mov;
}
}
'-' => {
if dir % 2 == 1 {
starts.push((x, y, 0));
starts.push((x, y, 2));
break 'mov;
}
}
_ => {}
}
(x, y) = match dir {
0 => (x, y + 1),
1 => (x + 1, y),
2 => {
if y == 0 {
break 'mov;
}
(x, y - 1)
}
3 => {
if x == 0 {
break 'mov;
}
(x - 1, y)
}
_ => panic!(),
};
if x >= grid.len() || y >= grid[0].len() {
break 'mov;
}
}
}
visited.len()
})
.max()
.unwrap()
}

View file

@ -6,10 +6,12 @@ pub fn solve() {
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?"); let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?")); //let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
let result: usize = 0; let result: usize = 0;
println!("Result 1: {result}"); println!("Result 1: {result}");
let result: usize = 0; let result: usize = 0;
println!("Result 2: {result}"); println!("Result 2: {result}");

View file

@ -6,10 +6,12 @@ pub fn solve() {
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?"); let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?")); //let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
let result: usize = 0; let result: usize = 0;
println!("Result 1: {result}"); println!("Result 1: {result}");
let result: usize = 0; let result: usize = 0;
println!("Result 2: {result}"); println!("Result 2: {result}");

View file

@ -6,10 +6,12 @@ pub fn solve() {
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?"); let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?")); //let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
let result: usize = 0; let result: usize = 0;
println!("Result 1: {result}"); println!("Result 1: {result}");
let result: usize = 0; let result: usize = 0;
println!("Result 2: {result}"); println!("Result 2: {result}");

View file

@ -6,10 +6,12 @@ pub fn solve() {
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?"); let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?")); //let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
let result: usize = 0; let result: usize = 0;
println!("Result 1: {result}"); println!("Result 1: {result}");
let result: usize = 0; let result: usize = 0;
println!("Result 2: {result}"); println!("Result 2: {result}");

View file

@ -6,10 +6,12 @@ pub fn solve() {
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?"); let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?")); //let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
let result: usize = 0; let result: usize = 0;
println!("Result 1: {result}"); println!("Result 1: {result}");
let result: usize = 0; let result: usize = 0;
println!("Result 2: {result}"); println!("Result 2: {result}");

View file

@ -6,10 +6,12 @@ pub fn solve() {
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?"); let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?")); //let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
let result: usize = 0; let result: usize = 0;
println!("Result 1: {result}"); println!("Result 1: {result}");
let result: usize = 0; let result: usize = 0;
println!("Result 2: {result}"); println!("Result 2: {result}");

View file

@ -6,10 +6,12 @@ pub fn solve() {
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?"); let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?")); //let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
let result: usize = 0; let result: usize = 0;
println!("Result 1: {result}"); println!("Result 1: {result}");
let result: usize = 0; let result: usize = 0;
println!("Result 2: {result}"); println!("Result 2: {result}");

View file

@ -6,10 +6,12 @@ pub fn solve() {
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?"); let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?")); //let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
let result: usize = 0; let result: usize = 0;
println!("Result 1: {result}"); println!("Result 1: {result}");
let result: usize = 0; let result: usize = 0;
println!("Result 2: {result}"); println!("Result 2: {result}");

View file

@ -6,10 +6,12 @@ pub fn solve() {
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?"); let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?")); //let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
let result: usize = 0; let result: usize = 0;
println!("Result 1: {result}"); println!("Result 1: {result}");
let result: usize = 0; let result: usize = 0;
println!("Result 2: {result}"); println!("Result 2: {result}");

View file

@ -5,8 +5,8 @@ extern crate scan_fmt;
use std::time::Instant; use std::time::Instant;
fn main() { fn main() {
//days::d16::solve() days::d15::solve()
_all_days() //_all_days()
} }
#[allow(unreachable_code, unused)] #[allow(unreachable_code, unused)]