day 16
This commit is contained in:
parent
1f57dd6464
commit
9cc7b1a890
BIN
day15/src/main
Executable file
BIN
day15/src/main
Executable file
Binary file not shown.
@ -72,6 +72,7 @@ fn main() {
|
||||
let val = hash(piece);
|
||||
part1 += val;
|
||||
}
|
||||
|
||||
println!("part 1 sum is {part1}");
|
||||
|
||||
let mut focusing_power = 0;
|
||||
|
7
day16/Cargo.lock
generated
Normal file
7
day16/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "day16"
|
||||
version = "0.1.0"
|
BIN
day16/src/main
Executable file
BIN
day16/src/main
Executable file
Binary file not shown.
@ -1,3 +1,145 @@
|
||||
use std::collections::HashSet;
|
||||
use std::iter::*;
|
||||
use std::fs;
|
||||
use std::env;
|
||||
|
||||
type Record = (i32, i32, i32, i32);
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
println!("Hello, AoC day 16!");
|
||||
|
||||
let args: Vec<String> = env::args().collect();
|
||||
if args.len() != 2 {
|
||||
println!("wrong number of arguments!");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let file_path = &args[1];
|
||||
|
||||
let contents = fs::read_to_string(file_path)
|
||||
.expect("Should have been able to read the file");
|
||||
|
||||
let mut g: Vec<Vec<char>> = Vec::new();
|
||||
let mut v: Vec<Vec<char>> = Vec::new();
|
||||
|
||||
for line in contents.lines() {
|
||||
let mut row = Vec::new();
|
||||
let mut vrow = Vec::new();
|
||||
for c in line.chars() {
|
||||
row.push(c);
|
||||
vrow.push('.');
|
||||
}
|
||||
g.push(row);
|
||||
v.push(vrow);
|
||||
}
|
||||
|
||||
//print_map(&g);
|
||||
|
||||
let visited = &mut HashSet::<Record>::new();
|
||||
trace(&g, visited, 0,0, 1,0);
|
||||
|
||||
|
||||
let mut sum = 0;
|
||||
for (x, y, _, _) in visited.iter() {
|
||||
if v[*y as usize][*x as usize] == '#' {
|
||||
continue;
|
||||
}
|
||||
v[*y as usize][*x as usize] = '#';
|
||||
sum += 1
|
||||
}
|
||||
|
||||
//print_map(&v);
|
||||
println!("totally marked off {sum} locations when entering from the upper left going right");
|
||||
|
||||
let mut maximum = 0;
|
||||
for x in 0..g[0].len() {
|
||||
let from_the_top = count(&g, (x as i32, 0, 0, 1));
|
||||
if from_the_top > maximum { maximum = from_the_top; }
|
||||
let from_the_bottom = count(&g, (x as i32, g.len() as i32, 0, -1));
|
||||
if from_the_bottom > maximum { maximum = from_the_bottom; }
|
||||
}
|
||||
|
||||
for y in 0..g.len() {
|
||||
let from_the_left = count(&g,
|
||||
(0, y as i32,
|
||||
1, 0));
|
||||
if from_the_left > maximum { maximum = from_the_left; }
|
||||
let from_the_right = count(&g,
|
||||
(g[0].len() as i32, y as i32,
|
||||
-1, 0));
|
||||
if from_the_right > maximum { maximum = from_the_right; }
|
||||
}
|
||||
|
||||
println!("the highest number of locations we could visit was {maximum}");
|
||||
}
|
||||
|
||||
fn print_map(mat: &Vec<Vec<char>>) {
|
||||
for row in mat {
|
||||
for c in row {
|
||||
print!("{c}");
|
||||
}
|
||||
print!("\n");
|
||||
}
|
||||
}
|
||||
|
||||
fn trace(mat: &Vec<Vec<char>>,
|
||||
visited: &mut HashSet<Record>,
|
||||
start_x: i32,
|
||||
start_y: i32,
|
||||
start_dx: i32,
|
||||
start_dy: i32) -> () {
|
||||
|
||||
let mut cx = start_x;
|
||||
let mut cy = start_y;
|
||||
let mut dx = start_dx;
|
||||
let mut dy = start_dy;
|
||||
|
||||
while cy >= 0 && (cy as usize) < mat.len() && cx >= 0 && (cx as usize) < mat[0].len() {
|
||||
if visited.contains(&(cx, cy, dx, dy)) { return (); }
|
||||
visited.insert((cx, cy, dx, dy));
|
||||
|
||||
match mat[cy as usize][cx as usize] {
|
||||
'\\' => (dx, dy) = (dy, dx),
|
||||
'/' => (dx, dy) = (-dy, -dx),
|
||||
'|' =>
|
||||
if dx != 0 {
|
||||
trace(mat, visited, cx, cy, 0, 1);
|
||||
trace(mat, visited, cx, cy, 0, -1);
|
||||
return;
|
||||
},
|
||||
'-' =>
|
||||
if dy != 0 {
|
||||
trace(mat, visited, cx, cy, 1, 0);
|
||||
trace(mat, visited, cx, cy, -1, 0);
|
||||
return;
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
|
||||
cx = cx + dx;
|
||||
cy = cy + dy;
|
||||
}
|
||||
}
|
||||
|
||||
fn count(mat: &Vec<Vec<char>>, start: Record) -> i32 {
|
||||
let mut visit_set = HashSet::<Record>::new();
|
||||
trace(mat, &mut visit_set, start.0, start.1, start.2, start.3);
|
||||
|
||||
let mut v = Vec::<Vec<char>>::new();
|
||||
for row in mat {
|
||||
let mut nr = Vec::new();
|
||||
for _ in row { nr.push('.'); }
|
||||
v.push(nr);
|
||||
}
|
||||
|
||||
let mut sum = 0;
|
||||
for (x, y, _, _) in visit_set.iter() {
|
||||
if v[*y as usize][*x as usize] == '#' {
|
||||
continue;
|
||||
}
|
||||
v[*y as usize][*x as usize] = '#';
|
||||
sum += 1
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
1
day16/target/.rustc_info.json
Normal file
1
day16/target/.rustc_info.json
Normal file
@ -0,0 +1 @@
|
||||
{"rustc_fingerprint":11672801278650259402,"outputs":{"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/shoofle/.rustup/toolchains/stable-x86_64-apple-darwin\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_feature=\"ssse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"apple\"\nunix\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.69.0 (84c898d65 2023-04-16)\nbinary: rustc\ncommit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc\ncommit-date: 2023-04-16\nhost: x86_64-apple-darwin\nrelease: 1.69.0\nLLVM version: 15.0.7\n","stderr":""}},"successes":{}}
|
3
day16/target/CACHEDIR.TAG
Normal file
3
day16/target/CACHEDIR.TAG
Normal file
@ -0,0 +1,3 @@
|
||||
Signature: 8a477f597d28d172789f06886806bc55
|
||||
# This file is a cache directory tag created by cargo.
|
||||
# For information about cache directory tags see https://bford.info/cachedir/
|
0
day16/target/debug/.cargo-lock
Normal file
0
day16/target/debug/.cargo-lock
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
@ -0,0 +1,2 @@
|
||||
{"message":"function `print_map` is never used","code":{"code":"dead_code","explanation":null},"level":"warning","spans":[{"file_name":"src/main.rs","byte_start":2010,"byte_end":2019,"line_start":76,"line_end":76,"column_start":4,"column_end":13,"is_primary":true,"text":[{"text":"fn print_map(mat: &Vec<Vec<char>>) {","highlight_start":4,"highlight_end":13}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"`#[warn(dead_code)]` on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: function `print_map` is never used\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/main.rs:76:4\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m76\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0mfn print_map(mat: &Vec<Vec<char>>) {\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^^^^^^^\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(dead_code)]` on by default\u001b[0m\n\n"}
|
||||
{"message":"1 warning emitted","code":null,"level":"warning","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: 1 warning emitted\u001b[0m\n\n"}
|
@ -0,0 +1 @@
|
||||
9a41b0768220741b
|
@ -0,0 +1 @@
|
||||
{"rustc":3659767333214291318,"features":"[]","target":250502024769020866,"profile":11506243869495082934,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/day16-e1bddb71ea6cd219/dep-test-bin-day16"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
@ -0,0 +1 @@
|
||||
23e1d259d4912651
|
@ -0,0 +1 @@
|
||||
{"rustc":3659767333214291318,"features":"[]","target":250502024769020866,"profile":11736316127369858332,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/day16-e5a07f0ab55d4573/dep-bin-day16"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
@ -0,0 +1,2 @@
|
||||
{"message":"function `print_map` is never used","code":{"code":"dead_code","explanation":null},"level":"warning","spans":[{"file_name":"src/main.rs","byte_start":2010,"byte_end":2019,"line_start":76,"line_end":76,"column_start":4,"column_end":13,"is_primary":true,"text":[{"text":"fn print_map(mat: &Vec<Vec<char>>) {","highlight_start":4,"highlight_end":13}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"`#[warn(dead_code)]` on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: function `print_map` is never used\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/main.rs:76:4\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m76\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0mfn print_map(mat: &Vec<Vec<char>>) {\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^^^^^^^\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(dead_code)]` on by default\u001b[0m\n\n"}
|
||||
{"message":"1 warning emitted","code":null,"level":"warning","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: 1 warning emitted\u001b[0m\n\n"}
|
BIN
day16/target/debug/day16
Executable file
BIN
day16/target/debug/day16
Executable file
Binary file not shown.
1
day16/target/debug/day16.d
Normal file
1
day16/target/debug/day16.d
Normal file
@ -0,0 +1 @@
|
||||
/Users/shoofle/Projects/aoc_2023/day16/target/debug/day16: /Users/shoofle/Projects/aoc_2023/day16/src/main.rs
|
5
day16/target/debug/deps/day16-e1bddb71ea6cd219.d
Normal file
5
day16/target/debug/deps/day16-e1bddb71ea6cd219.d
Normal file
@ -0,0 +1,5 @@
|
||||
/Users/shoofle/Projects/aoc_2023/day16/target/debug/deps/day16-e1bddb71ea6cd219.rmeta: src/main.rs
|
||||
|
||||
/Users/shoofle/Projects/aoc_2023/day16/target/debug/deps/day16-e1bddb71ea6cd219.d: src/main.rs
|
||||
|
||||
src/main.rs:
|
BIN
day16/target/debug/deps/day16-e5a07f0ab55d4573
Executable file
BIN
day16/target/debug/deps/day16-e5a07f0ab55d4573
Executable file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5
day16/target/debug/deps/day16-e5a07f0ab55d4573.d
Normal file
5
day16/target/debug/deps/day16-e5a07f0ab55d4573.d
Normal file
@ -0,0 +1,5 @@
|
||||
/Users/shoofle/Projects/aoc_2023/day16/target/debug/deps/day16-e5a07f0ab55d4573: src/main.rs
|
||||
|
||||
/Users/shoofle/Projects/aoc_2023/day16/target/debug/deps/day16-e5a07f0ab55d4573.d: src/main.rs
|
||||
|
||||
src/main.rs:
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user