day 10 in under the wire

main
Shoofle 10 months ago
parent a5b5bcfc3b
commit daedef27ac
  1. 7
      day10/Cargo.lock
  2. 8
      day10/Cargo.toml
  3. 233
      day10/src/main.rs
  4. 1
      day10/target/.rustc_info.json
  5. 3
      day10/target/CACHEDIR.TAG
  6. 0
      day10/target/debug/.cargo-lock
  7. 1
      day10/target/debug/.fingerprint/day10-ef99a7eb2ce83b6e/bin-day10
  8. 1
      day10/target/debug/.fingerprint/day10-ef99a7eb2ce83b6e/bin-day10.json
  9. BIN
      day10/target/debug/.fingerprint/day10-ef99a7eb2ce83b6e/dep-bin-day10
  10. 1
      day10/target/debug/.fingerprint/day10-ef99a7eb2ce83b6e/invoked.timestamp
  11. BIN
      day10/target/debug/day10
  12. 1
      day10/target/debug/day10.d
  13. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e
  14. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.199s7gevh0vgmiqc.rcgu.o
  15. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.1ae898o8lj8sustx.rcgu.o
  16. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.1j40lxiyejui8ryd.rcgu.o
  17. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.1k9vj52w89c3jq6.rcgu.o
  18. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.1wgerpyqdw2xytip.rcgu.o
  19. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.25nlcwdlogl3yf6a.rcgu.o
  20. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.2fsdrl0u208d70cd.rcgu.o
  21. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.2fycbhtpdfyrw272.rcgu.o
  22. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.2hrpnh841w8lq023.rcgu.o
  23. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.2ivrykwh01cshjle.rcgu.o
  24. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.2k0qq7kear3ll639.rcgu.o
  25. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.2na8ur0lkkuwxxkn.rcgu.o
  26. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.2oyevq4al2yspltg.rcgu.o
  27. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.2sd1zkt69i9krrpd.rcgu.o
  28. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.2ud2z4duclncuo09.rcgu.o
  29. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.2uoyftg3gjwy1c41.rcgu.o
  30. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.2yflseci4obgixm6.rcgu.o
  31. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.2zymy6fmahanfbg0.rcgu.o
  32. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.315rzii04ph4k6iw.rcgu.o
  33. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.31xd9vg1b7112cpz.rcgu.o
  34. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.32eyu9rx0sdkcm2f.rcgu.o
  35. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.367eq8usug7va688.rcgu.o
  36. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.37321emsh4o0tdri.rcgu.o
  37. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.3eu06jz9hqhz394o.rcgu.o
  38. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.3hnx47kxv496dttb.rcgu.o
  39. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.3kj8n3786lz7jc7d.rcgu.o
  40. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.3mrec7ppaa1z5kz7.rcgu.o
  41. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.3n7rrmlrk54gkmzb.rcgu.o
  42. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.3ofv382lnqb0cxju.rcgu.o
  43. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.3t8jwx9g99rzhnp9.rcgu.o
  44. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.3uxm9kc26w6e47at.rcgu.o
  45. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.3xls46nqzou1gdnb.rcgu.o
  46. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.40zhyzfmjmvgu81y.rcgu.o
  47. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.44n7rq347wfzz0tj.rcgu.o
  48. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.49e2yeszkrxl6ean.rcgu.o
  49. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.4b21a5d000j0kmy0.rcgu.o
  50. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.4elazc1qitj8s8br.rcgu.o
  51. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.4plpbidm4km2xs3b.rcgu.o
  52. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.4qcey8ek5tzr46l5.rcgu.o
  53. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.4qp887xy1iu8yv9q.rcgu.o
  54. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.55gmqwmymuooxnln.rcgu.o
  55. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.5bc0an5x5y08ycx3.rcgu.o
  56. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.5dd7d5n32snfxwm9.rcgu.o
  57. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.5easfumweccyr9xn.rcgu.o
  58. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.5efhfr823vut311j.rcgu.o
  59. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.5enu9743kjmg8nwa.rcgu.o
  60. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.a7hdas9ixhub6nu.rcgu.o
  61. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.bt5rhyymbz25mns.rcgu.o
  62. 5
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.d
  63. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.eqcw2zsxpbeubys.rcgu.o
  64. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.iyp0yepkzax3w5i.rcgu.o
  65. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.qmz3txzrqjqvxtn.rcgu.o
  66. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.ryjc7oxysp9i01w.rcgu.o
  67. BIN
      day10/target/debug/deps/day10-ef99a7eb2ce83b6e.xy4fflwhgtnlvuy.rcgu.o
  68. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/199s7gevh0vgmiqc.o
  69. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/1ae898o8lj8sustx.o
  70. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/1j40lxiyejui8ryd.o
  71. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/1k9vj52w89c3jq6.o
  72. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/1wgerpyqdw2xytip.o
  73. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/25nlcwdlogl3yf6a.o
  74. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/2fsdrl0u208d70cd.o
  75. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/2fycbhtpdfyrw272.o
  76. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/2hrpnh841w8lq023.o
  77. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/2ivrykwh01cshjle.o
  78. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/2k0qq7kear3ll639.o
  79. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/2na8ur0lkkuwxxkn.o
  80. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/2oyevq4al2yspltg.o
  81. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/2sd1zkt69i9krrpd.o
  82. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/2ud2z4duclncuo09.o
  83. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/2uoyftg3gjwy1c41.o
  84. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/2yflseci4obgixm6.o
  85. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/2zymy6fmahanfbg0.o
  86. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/315rzii04ph4k6iw.o
  87. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/31xd9vg1b7112cpz.o
  88. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/32eyu9rx0sdkcm2f.o
  89. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/367eq8usug7va688.o
  90. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/37321emsh4o0tdri.o
  91. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/3eu06jz9hqhz394o.o
  92. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/3hnx47kxv496dttb.o
  93. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/3kj8n3786lz7jc7d.o
  94. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/3mrec7ppaa1z5kz7.o
  95. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/3n7rrmlrk54gkmzb.o
  96. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/3ofv382lnqb0cxju.o
  97. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/3t8jwx9g99rzhnp9.o
  98. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/3uxm9kc26w6e47at.o
  99. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/3xls46nqzou1gdnb.o
  100. BIN
      day10/target/debug/incremental/day10-1u07cj03f4d3w/s-grekatywez-1ghwd6m-3w2vdylsrljhs/40zhyzfmjmvgu81y.o
  101. Some files were not shown because too many files have changed in this diff Show More

7
day10/Cargo.lock generated

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day10"
version = "0.1.0"

@ -0,0 +1,8 @@
[package]
name = "day10"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

@ -0,0 +1,233 @@
use std::iter::*;
use std::fs;
use std::env;
#[derive(Debug, Copy, Clone, PartialEq)]
struct Coord {x: i32, y: i32}
#[derive(Debug, Copy, Clone, PartialEq)]
enum Dir {
North,
South,
West,
East
}
#[derive(Debug, Copy, Clone, PartialEq)]
struct Pipe {
a: Dir,
b: Dir
}
struct Grid<T: Copy> {
g: Vec<Vec<T>>
}
impl<T: Copy> Grid<T> {
fn get(&self, r: Coord) -> Option<T> {
if r.y < 0 || r.y >= self.g.len() as i32 {
return None;
}
if r.x < 0 || r.x >= self.g[0].len() as i32 {
return None;
}
Some(self.g[r.y as usize][r.x as usize])
}
fn set(&mut self, r: Coord, value: T) {
if r.y < 0 || r.y >= self.g.len() as i32 {
return ();
}
if r.x < 0 || r.x >= self.g[0].len() as i32 {
return ();
}
self.g[r.y as usize][r.x as usize] = value;
}
}
fn main() {
println!("Hello, AoC day 9!");
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 directions = vec![Dir::North, Dir::South, Dir::East, Dir::West];
let mut grid = Grid::<char> { g: Vec::new() };
let mut start = Coord { x: -1, y: -1};
// let's build that grid
for (y, line) in contents.lines().enumerate() {
let mut row = Vec::new();
for (x, c) in line.chars().enumerate() {
if c == 'S' {
start.x = x as i32;
start.y = y as i32;
}
row.push(c);
}
grid.g.push(row);
}
let mut starting_directions = Vec::new();
// now let's figure out what pipe the starting position should be
for direction in directions {
//figure out what a return pipe would look like
let ret = opposite(direction);
//step once in that direction
if let Some(next) = grid.get(step(start, direction)) {
println!("we're at {start:?}, looking {direction:?} at {next:?}");
if let Some(candidates) = connects(next) {
if candidates.0 == ret || candidates.1 == ret {
starting_directions.push(direction);
}
}
}
}
let true_s = match (starting_directions[0], starting_directions[1]) {
(Dir::South, Dir::East) => 'F',
(Dir::East, Dir::South) => 'F',
(Dir::North, Dir::West) => 'J',
(Dir::West, Dir::North) => 'J',
(Dir::North, Dir::East) => 'L',
(Dir::East, Dir::North) => 'L',
(Dir::South, Dir::West) => '7',
(Dir::West, Dir::South) => '7',
(Dir::North, Dir::South) => '|',
(Dir::South, Dir::North) => '|',
(Dir::East, Dir::West) => '-',
(Dir::West, Dir::East) => '-',
_ => 'S'
};
grid.set(start, true_s);
let mut summing_field = Grid::<i32> { g: Vec::new() };
for _y in 0..grid.g.len() {
let mut new_row = Vec::new();
for _x in 0..grid.g[0].len() {
new_row.push(0);
}
summing_field.g.push(new_row);
}
// now let's walk around the path and count the steps, then divide by two
let mut r = start;
let mut facing = starting_directions[0];
let mut steps = 0;
while steps == 0 || r != start {
r = step(r, facing);
// we just stepped to the new r, frmo the old r, in the direction facing
let new_facing = turn(facing, grid.get(r).expect("We were pointed in this direction. It should be fine."));
for z in 0..r.x+1 {
summing_field.g[r.y as usize][z as usize] += match facing {
Dir::North => 1,
Dir::South => -1,
Dir::East => 0,
Dir::West => 0
};
summing_field.g[r.y as usize][z as usize] += match new_facing {
Dir::North => 1,
Dir::South => -1,
Dir::East => 0,
Dir::West => 0
};
}
facing = new_facing;
steps += 1;
}
let mut r = start;
let mut facing = starting_directions[0];
let mut steps = 0;
while steps == 0 || r != start {
r = step(r, facing);
// we just stepped to the new r, frmo the old r, in the direction facing
facing = turn(facing, grid.get(r).expect("We were pointed in this direction. It should be fine."));
summing_field.set(r, 0);
steps += 1;
}
println!("map:");
for row in grid.g {
println!("{row:?}");
}
let mut sum = 0;
println!("summing field:");
for row in summing_field.g {
println!("{row:?}");
for x in row {
sum += x;
}
}
sum = sum / 2;
println!("{steps} steps around the loop!");
let halfway = steps / 2;
println!("halfway is {halfway}!");
println!("behold, this is the sum of sums!: {sum}");
}
fn step(r: Coord, direction: Dir) -> Coord {
match direction {
Dir::North => Coord { x: r.x, y: r.y-1 },
Dir::South => Coord { x: r.x, y: r.y+1 },
Dir::West => Coord { x: r.x-1, y: r.y },
Dir::East => Coord { x: r.x+1, y: r.y },
}
}
fn turn(going: Dir, x: char) -> Dir {
match (going, x) {
(Dir::North, 'F') => Dir::East,
(Dir::West, 'F') => Dir::South,
(Dir::South, 'J') => Dir::West,
(Dir::East, 'J') => Dir::North,
(Dir::South, 'L') => Dir::East,
(Dir::West, 'L') => Dir::North,
(Dir::East, '7') => Dir::South,
(Dir::North, '7') => Dir::West,
(Dir::North, '|') => Dir::North,
(Dir::South, '|') => Dir::South,
(Dir::East, '-') => Dir::East,
(Dir::West, '-') => Dir::West,
(_, 'S') => Dir::North,
(_d, _c) => panic!("\"Just don't worry about it. This won't happen.\" -- Shoofle Dot Net")
}
}
fn connects(x: char) -> Option<(Dir, Dir)> {
match x {
'F' => Some((Dir::South, Dir::East)),
'J' => Some((Dir::North, Dir::West)),
'L' => Some((Dir::North, Dir::East)),
'7' => Some((Dir::South, Dir::West)),
'|' => Some((Dir::North, Dir::South)),
'-' => Some((Dir::East, Dir::West)),
_ => None
}
}
fn opposite(x: Dir) -> Dir {
match x {
Dir::North => Dir::South,
Dir::South => Dir::North,
Dir::East => Dir::West,
Dir::West => Dir::East,
}
}

@ -0,0 +1 @@
{"rustc_fingerprint":11672801278650259402,"outputs":{"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":""},"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":""}},"successes":{}}

@ -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,0 +1 @@
{"rustc":3659767333214291318,"features":"[]","target":14519807996045575918,"profile":11736316127369858332,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/day10-ef99a7eb2ce83b6e/dep-bin-day10"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}

@ -0,0 +1 @@
This file has an mtime of when this was started.

Binary file not shown.

@ -0,0 +1 @@
/Users/shoofle/Projects/aoc_2023/day10/target/debug/day10: /Users/shoofle/Projects/aoc_2023/day10/src/main.rs

Binary file not shown.

@ -0,0 +1,5 @@
/Users/shoofle/Projects/aoc_2023/day10/target/debug/deps/day10-ef99a7eb2ce83b6e: src/main.rs
/Users/shoofle/Projects/aoc_2023/day10/target/debug/deps/day10-ef99a7eb2ce83b6e.d: src/main.rs
src/main.rs:

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save