Skip to content

Commit

Permalink
Implement day10
Browse files Browse the repository at this point in the history
  • Loading branch information
Oberacda committed Dec 11, 2023
1 parent 9fe3d34 commit 917a3dc
Show file tree
Hide file tree
Showing 12 changed files with 668 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["day01", "day02", "day03", "day04", "day05", "day06", "day07", "day08", "day09"]
members = ["day01", "day02", "day03", "day04", "day05", "day06", "day07", "day08", "day09", "day10"]

[workspace.package]
authors = ["David Oberacker <[email protected]>"]
Expand All @@ -15,6 +15,7 @@ rayon = "1.8.0"
num = "0.4"
itertools = "0.12.0"
ranges = "0.3.3"
ndarray = "0.15.6"

[profile.release]
incremental = true
Expand Down
22 changes: 22 additions & 0 deletions day10/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "day10"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
description.workspace = true
publish.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "day10"
path = "src/lib.rs"

[[bin]]
name = "day10_part1"

[[bin]]
name = "day10_part2"

[dependencies]
ndarray.workspace = true
anyhow.workspace = true
140 changes: 140 additions & 0 deletions day10/resources/input.txt

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions day10/resources/test_input01.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.....
.S-7.
.|.|.
.L-J.
.....
5 changes: 5 additions & 0 deletions day10/resources/test_input02.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-L|F7
7S-7|
L|7||
-L-J|
L|-JF
5 changes: 5 additions & 0 deletions day10/resources/test_input03.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
7-F7-
.FJ|7
SJLL7
|F--J
LJ.LJ
9 changes: 9 additions & 0 deletions day10/resources/test_input04.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
...........
.S-------7.
.|F-----7|.
.||.....||.
.||.....||.
.|L-7.F-J|.
.|..|.|..|.
.L--J.L--J.
...........
10 changes: 10 additions & 0 deletions day10/resources/test_input05.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.F----7F7F7F7F-7....
.|F--7||||||||FJ....
.||.FJ||||||||L7....
FJL7L7LJLJ||LJ.L-7..
L--J.L7...LJS7F-7L7.
....F-J..F7FJ|L7L7L7
....L7.F7||L7|.L7L7|
.....|FJLJ|FJ|F7|.LJ
....FJL-7.||.||||...
....L---J.LJ.LJLJ...
10 changes: 10 additions & 0 deletions day10/resources/test_input06.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FF7FSF7F7F7F7F7F---7
L|LJ||||||||||||F--J
FL-7LJLJ||||||LJL-77
F--JF--7||LJLJ7F7FJ-
L---JF-JLJ.||-FJLJJ7
|F|F-JF---7F7-L7L|7|
|FFJF7L7F-JF7|JL---7
7-L-JL7||F7|L7F-7F7|
L.L7LFJ|||||FJL7||LJ
L7JLJL-JLJLJL--JLJ.L
56 changes: 54 additions & 2 deletions day10/src/bin/day10_part1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
fn main() {
println!("Hello, world!");
use std::time::Instant;
use anyhow::Result;
use day10::{get_farthest_tile_in_loop_distance, parse_input};

fn main() -> Result<()>{
let input = include_str!("../../resources/input.txt");
let now = Instant::now();
let tiles = parse_input(input)?;
println!("{}", tiles);

let result = get_farthest_tile_in_loop_distance(&tiles)?;
let elapsed = now.elapsed();
println!("Result: {}, Elapsed: {:?}", result, elapsed);
Ok(())
}

#[cfg(test)]
mod tests {
use day10::get_farthest_tile_in_loop_distance;
use super::*;

#[test]
fn run_test_input01() -> Result<()>{

let input = include_str!("../../resources/test_input01.txt");
let tiles = parse_input(input)?;
println!("{}", tiles);
let result = get_farthest_tile_in_loop_distance(&tiles)?;
assert_eq!(result, 4);
Ok(())
}

#[test]
fn run_test_input02() -> Result<()>{

let input = include_str!("../../resources/test_input02.txt");
let tiles = parse_input(input)?;
println!("{}", tiles);
let result = get_farthest_tile_in_loop_distance(&tiles)?;
assert_eq!(result, 4);
Ok(())
}


#[test]
fn run_test_input03() -> Result<()>{

let input = include_str!("../../resources/test_input03.txt");
let tiles = parse_input(input)?;
println!("{}", tiles);
let result = get_farthest_tile_in_loop_distance(&tiles)?;
assert_eq!(result, 8);
Ok(())
}
}
49 changes: 47 additions & 2 deletions day10/src/bin/day10_part2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
fn main() {
println!("Hello, world!");
use std::time::Instant;
use anyhow::Result;
use day10::{get_encased_cells_count, parse_input};

fn main() -> Result<()>{
let input = include_str!("../../resources/input.txt");
let now = Instant::now();
let tiles = parse_input(input)?;
let result = get_encased_cells_count(&tiles)?;
let elapsed = now.elapsed();
println!("Result: {}, Elapsed: {:?}", result, elapsed);
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn run_test_input04() -> Result<()>{

let input = include_str!("../../resources/test_input04.txt");
let tiles = parse_input(input)?;
let result = get_encased_cells_count(&tiles)?;
assert_eq!(result, 4);
Ok(())
}

#[test]
fn run_test_input05() -> Result<()>{

let input = include_str!("../../resources/test_input05.txt");
let tiles = parse_input(input)?;
let result = get_encased_cells_count(&tiles)?;
assert_eq!(result, 8);
Ok(())
}


#[test]
fn run_test_input06() -> Result<()>{

let input = include_str!("../../resources/test_input06.txt");
let tiles = parse_input(input)?;
let result = get_encased_cells_count(&tiles)?;
assert_eq!(result, 10);
Ok(())
}
}
Loading

0 comments on commit 917a3dc

Please sign in to comment.