Skip to content

Commit

Permalink
refactor: Implemented Problem day18
Browse files Browse the repository at this point in the history
  • Loading branch information
jortrr committed Aug 10, 2024
1 parent c6582f5 commit 8bf38bf
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .aocf/cache/aoc2023_18.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"title": "Lavaduct Lagoon",
"stars": 2,
"solution": {
"first": "48652",
"second": "45757884535661"
"second": "45757884535661",
"first": "48652"
},
"input": "L 4 (#248a72)\nU 3 (#295c13)\nL 4 (#49e802)\nU 5 (#5ff8b3)\nR 3 (#0df642)\nU 2 (#15b973)\nR 5 (#6cfb92)\nU 11 (#4e3cd3)\nL 4 (#422dd0)\nD 5 (#303fe3)\nL 7 (#6225e0)\nD 2 (#58bd63)\nL 9 (#6225e2)\nD 8 (#2b1703)\nL 6 (#422dd2)\nD 9 (#2eb9b3)\nL 2 (#10f270)\nD 10 (#0677b3)\nL 4 (#190450)\nU 11 (#55b4e3)\nL 4 (#361732)\nU 3 (#034663)\nL 4 (#37f902)\nU 6 (#19bb73)\nR 8 (#6e1030)\nU 8 (#4cad93)\nL 4 (#2509d0)\nU 6 (#1e1e61)\nL 5 (#3d3b90)\nU 8 (#28ec81)\nL 2 (#3f9200)\nU 5 (#437871)\nL 6 (#174bc0)\nD 5 (#3b58a1)\nL 11 (#064a60)\nU 5 (#539da3)\nL 4 (#1ea0d0)\nD 7 (#1909b3)\nL 2 (#296a52)\nD 9 (#6780c3)\nL 3 (#296a50)\nU 11 (#356893)\nL 2 (#0eb430)\nU 5 (#019203)\nL 5 (#4eea10)\nU 4 (#436533)\nL 4 (#20aeb0)\nU 4 (#2fb883)\nL 6 (#5046c0)\nU 11 (#392293)\nR 8 (#2567a0)\nU 3 (#57ee03)\nR 12 (#270540)\nU 2 (#358173)\nR 6 (#289e40)\nU 2 (#77b991)\nR 4 (#016c10)\nU 11 (#351091)\nR 2 (#714f90)\nU 6 (#4add71)\nL 11 (#00eab0)\nD 5 (#2f8361)\nL 8 (#192200)\nU 5 (#1416c1)\nL 13 (#775d30)\nU 3 (#3d3d63)\nL 8 (#6e4710)\nU 3 (#28cfd3)\nL 8 (#389880)\nU 5 (#28cfd1)\nL 7 (#4cd750)\nD 5 (#1d56e3)\nL 3 (#2789e2)\nD 5 (#5d7573)\nR 9 (#1b1372)\nD 5 (#1965a3)\nR 4 (#111052)\nD 2 (#5a2861)\nR 10 (#37f1c2)\nD 3 (#0b7ad1)\nR 5 (#012162)\nU 5 (#226f43)\nR 4 (#583cd2)\nD 5 (#4333f3)\nR 5 (#0eb952)\nD 3 (#22a273)\nL 2 (#34c5d0)\nD 3 (#355f11)\nL 5 (#13a460)\nD 4 (#355f13)\nL 6 (#3e2900)\nU 4 (#28d423)\nL 8 (#042432)\nD 3 (#4378f3)\nL 6 (#18a200)\nD 5 (#16a843)\nL 5 (#18a202)\nD 7 (#46fdd3)\nL 5 (#2a4802)\nD 5 (#2a4d23)\nL 5 (#6049d2)\nD 4 (#0a4023)\nL 4 (#09afb2)\nU 4 (#687713)\nL 5 (#4b85f2)\nD 4 (#0e1a53)\nL 8 (#331b60)\nU 6 (#270d83)\nL 6 (#331b62)\nU 6 (#25dba3)\nL 6 (#412e82)\nD 6 (#5e2e73)\nL 8 (#1de802)\nU 6 (#1e7143)\nL 4 (#4e7e82)\nU 3 (#160d63)\nL 5 (#19d230)\nU 3 (#36a4a3)\nR 3 (#19d232)\nU 6 (#4c63b3)\nR 10 (#0d2862)\nU 5 (#0ec351)\nR 11 (#593c62)\nU 6 (#12de21)\nR 2 (#08d482)\nU 4 (#277081)\nR 3 (#10eee0)\nU 4 (#382b91)\nL 4 (#512200)\nU 7 (#1279f1)\nL 3 (#229312)\nU 6 (#422721)\nR 6 (#71ddd2)\nU 6 (#093871)\nR 13 (#0d5622)\nD 5 (#093873)\nR 7 (#4c34e2)\nU 6 (#5b1743)\nR 2 (#4779a2)\nD 6 (#1cc6e3)\nR 7 (#3c13a0)\nU 5 (#3b60f3)\nR 4 (#3c13a2)\nU 9 (#229f83)\nR 3 (#0a6ff2)\nD 2 (#06d231)\nR 8 (#0298b2)\nD 11 (#4eb6a1)\nR 7 (#0298b0)\nU 8 (#438ce1)\nR 7 (#0e69e2)\nU 5 (#2d3e73)\nR 8 (#40b2c2)\nU 6 (#64cb53)\nL 2 (#40b2c0)\nU 3 (#0215c3)\nL 3 (#2cbf42)\nU 4 (#00c523)\nL 7 (#1fc3d2)\nD 4 (#68a633)\nL 5 (#1fc3d0)\nU 5 (#149853)\nL 5 (#2cbf40)\nU 9 (#0b9613)\nL 3 (#1e7f00)\nU 8 (#2fc533)\nL 7 (#3d7180)\nU 3 (#33f3a3)\nR 9 (#66d340)\nU 2 (#0fa1f1)\nR 4 (#0546c0)\nD 6 (#4c00b3)\nR 8 (#483b50)\nU 6 (#4c00b1)\nR 4 (#2fc7c0)\nU 2 (#0fa1f3)\nR 7 (#377280)\nU 6 (#200c43)\nR 5 (#429ef0)\nU 3 (#3a90f1)\nR 5 (#226142)\nU 4 (#2740c1)\nR 5 (#41ac62)\nU 3 (#275423)\nR 2 (#3ba072)\nU 11 (#275421)\nR 4 (#27ea92)\nD 8 (#402001)\nR 2 (#3456c0)\nD 6 (#5a4541)\nR 3 (#4d1400)\nU 4 (#5a4543)\nR 6 (#462de0)\nU 8 (#3fcdb1)\nR 6 (#1f2d90)\nU 6 (#4e7851)\nR 3 (#41eb30)\nD 6 (#4e7853)\nR 4 (#1aa1c0)\nD 10 (#0a4073)\nR 6 (#2134b2)\nD 7 (#164e43)\nR 4 (#200c72)\nD 5 (#3beca3)\nR 6 (#7445e0)\nU 3 (#2cda83)\nR 4 (#7445e2)\nU 3 (#475553)\nL 5 (#200c70)\nU 10 (#23fb33)\nR 5 (#2134b0)\nU 7 (#3c98d3)\nL 4 (#4cfc80)\nU 5 (#0f0e71)\nR 8 (#3c1d22)\nU 10 (#23a311)\nR 6 (#05da32)\nD 5 (#6229c1)\nR 5 (#41f750)\nD 8 (#1f4191)\nR 3 (#3530f0)\nD 13 (#4d3941)\nR 3 (#6215e0)\nD 9 (#2fe911)\nR 6 (#05cf90)\nU 4 (#25c901)\nR 2 (#335232)\nU 12 (#271371)\nR 2 (#335230)\nU 5 (#2bd1d1)\nL 9 (#1ffad0)\nU 6 (#6f6bc1)\nR 9 (#099600)\nU 5 (#13bee1)\nR 3 (#5aa820)\nU 3 (#3546c1)\nR 6 (#4dd5f0)\nD 11 (#495be1)\nR 6 (#60c8e0)\nU 11 (#4bd201)\nR 4 (#367f30)\nD 4 (#43dbc1)\nR 6 (#4bb740)\nU 12 (#07ce11)\nR 6 (#4b4d70)\nD 12 (#3e29e1)\nR 5 (#313fc0)\nU 4 (#293d51)\nR 4 (#1b4860)\nU 11 (#514571)\nR 4 (#5c11a2)\nU 4 (#444841)\nR 8 (#5c11a0)\nU 2 (#3e6c51)\nR 11 (#16dab0)\nU 7 (#26baf1)\nR 2 (#32e240)\nU 5 (#26baf3)\nR 6 (#2f0a70)\nU 6 (#11a821)\nR 3 (#527fc0)\nU 7 (#468b31)\nR 6 (#0641a0)\nU 10 (#20f351)\nR 7 (#547a90)\nU 12 (#1dbf11)\nR 2 (#17d0d2)\nU 10 (#159981)\nR 6 (#634e12)\nU 5 (#4ff021)\nR 10 (#006122)\nD 6 (#6589a3)\nR 3 (#1a74f2)\nD 2 (#19b911)\nR 12 (#3ed5f2)\nD 5 (#28ab31)\nR 3 (#09dd82)\nD 5 (#614c01)\nR 6 (#284d32)\nD 9 (#06b521)\nR 8 (#4dfad2)\nD 7 (#5b0f61)\nR 2 (#0fff22)\nD 5 (#1e6ff1)\nR 2 (#47b352)\nD 9 (#29c291)\nR 5 (#352ef2)\nD 3 (#042d11)\nR 4 (#262542)\nD 7 (#042d13)\nR 4 (#21e8f2)\nD 3 (#18cc21)\nR 3 (#16ed70)\nU 9 (#270ea1)\nR 7 (#4391e0)\nU 9 (#270ea3)\nR 4 (#22bdd0)\nD 3 (#3b72b1)\nR 7 (#1fd4b2)\nD 8 (#01bfe1)\nL 7 (#3d18a2)\nD 7 (#20dac1)\nR 4 (#67d990)\nD 4 (#1acd93)\nL 7 (#017410)\nD 2 (#6e4923)\nL 7 (#10bdd0)\nD 13 (#0650b3)\nL 2 (#072660)\nU 13 (#221151)\nL 6 (#41d720)\nD 3 (#5bc831)\nL 4 (#252450)\nD 9 (#118de1)\nR 6 (#05b1d0)\nD 4 (#247721)\nR 9 (#2b6b10)\nU 4 (#60da41)\nR 10 (#470c42)\nD 3 (#4fdc91)\nR 2 (#470c40)\nD 8 (#189db1)\nL 5 (#4a1f70)\nD 7 (#07e141)\nL 3 (#2524b0)\nD 5 (#2a6ce1)\nL 11 (#1a2e50)\nD 2 (#4f08c1)\nL 3 (#3b7ec0)\nD 9 (#65e011)\nL 8 (#24b9a0)\nD 6 (#196c61)\nL 5 (#540b20)\nD 6 (#243801)\nL 2 (#397ce0)\nD 3 (#411a41)\nL 12 (#397ce2)\nD 2 (#526d51)\nL 2 (#5b5810)\nD 5 (#2e96d3)\nL 8 (#6c4f80)\nU 6 (#274453)\nL 3 (#077010)\nU 5 (#37f603)\nR 5 (#73bf92)\nU 4 (#29ee73)\nR 11 (#5ffd40)\nU 5 (#3e12d3)\nL 4 (#4b4e32)\nU 12 (#114e01)\nL 2 (#45d0b2)\nU 4 (#114e03)\nL 6 (#4b8b02)\nU 9 (#3eff03)\nL 4 (#6968d0)\nU 4 (#3d4d33)\nL 6 (#1dd0e0)\nD 2 (#436023)\nL 9 (#58b812)\nD 6 (#423003)\nL 7 (#2e81a2)\nD 3 (#3d9e13)\nL 11 (#305450)\nD 6 (#2667f3)\nL 7 (#3a8470)\nD 8 (#293191)\nR 3 (#207ee0)\nD 4 (#293193)\nR 3 (#2c4360)\nD 4 (#2667f1)\nR 7 (#250ee0)\nU 4 (#70e1c3)\nR 4 (#2907d0)\nD 6 (#0b69a1)\nR 6 (#3babc0)\nD 6 (#7698c3)\nR 2 (#2752c0)\nD 3 (#7698c1)\nL 4 (#2dc550)\nD 11 (#4ec121)\nL 8 (#199d00)\nU 11 (#33f261)\nL 7 (#3b4e30)\nD 5 (#24e991)\nL 6 (#0aaeb2)\nU 9 (#15a993)\nL 5 (#59ed02)\nU 2 (#15a991)\nL 5 (#2c0432)\nU 10 (#337e81)\nL 7 (#248670)\nD 2 (#511d31)\nL 3 (#52ebc0)\nD 13 (#511d33)\nL 4 (#192db0)\nD 7 (#3dcf11)\nL 2 (#285030)\nD 3 (#15acc1)\nL 6 (#3a6c70)\nD 5 (#36f281)\nL 4 (#44fd02)\nU 5 (#4e8821)\nL 4 (#473972)\nU 5 (#2ab9f1)\nL 8 (#60aaa0)\nU 5 (#35c651)\nL 3 (#4736b2)\nU 10 (#4741d1)\nL 3 (#1973f2)\nU 5 (#1b5031)\nL 3 (#3c6532)\nD 5 (#49bd31)\nL 4 (#5e3f60)\nD 3 (#4a2011)\nL 4 (#2ba190)\nD 6 (#4a2013)\nL 3 (#653430)\nD 7 (#10dda1)\nL 11 (#2532d2)\nD 3 (#675311)\nL 4 (#27d642)\nD 6 (#02cae1)\nL 10 (#466652)\nD 7 (#34cef3)\nR 3 (#263692)\nD 7 (#34cef1)\nR 8 (#2c59d2)\nD 5 (#31afe1)\nL 8 (#091562)\nD 5 (#12c861)\nR 4 (#47a772)\nD 5 (#68a5b1)\nL 7 (#1f79a2)\nD 4 (#3b3c13)\nR 10 (#0e7122)\nD 4 (#087363)\nR 4 (#3e26c2)\nU 13 (#4953f3)\nR 3 (#5ac862)\nU 3 (#4953f1)\nR 3 (#13cfe2)\nD 5 (#087361)\nR 11 (#57f7a2)\nD 4 (#3b3c11)\nL 11 (#6dcb32)\nD 7 (#35e653)\nR 6 (#525282)\nD 5 (#3dac93)\nR 9 (#377082)\nD 6 (#2afda1)\nR 10 (#3e6422)\nD 10 (#220471)\nR 10 (#37ebf2)\nD 2 (#4d0213)\nR 5 (#2fa2f2)\nD 4 (#30df53)\nR 5 (#617e00)\nU 6 (#536393)\nR 5 (#496510)\nD 6 (#5f6733)\nR 4 (#3bf9b0)\nD 3 (#5f6731)\nR 4 (#48d940)\nD 3 (#35a5d3)\nR 4 (#284a82)\nD 9 (#445b23)\nL 4 (#2535c2)\nD 4 (#3f8b43)\nR 2 (#41a002)\nD 7 (#20b143)\nR 3 (#63ae42)\nU 8 (#328b03)\nR 9 (#383210)\nU 3 (#1ce143)\nR 7 (#383212)\nU 6 (#2ed603)\nR 5 (#00c512)\nU 6 (#6dea43)\nR 6 (#00c510)\nU 7 (#0f0643)\nR 3 (#4292a2)\nU 7 (#684961)\nR 3 (#03de80)\nU 5 (#46e0b1)\nR 6 (#3d4ae2)\nD 5 (#1d5fc1)\nR 7 (#3d4ae0)\nU 13 (#470ab1)\nR 5 (#03de82)\nU 4 (#282c71)\nR 6 (#5520f2)\nD 5 (#2f0981)\nR 2 (#5520f0)\nD 12 (#4081a1)\nR 6 (#22a272)\nU 5 (#284c53)\nR 8 (#081202)\nD 5 (#0b7831)\nR 4 (#3e4552)\nD 13 (#0b7833)\nR 5 (#38e092)\nU 11 (#284c51)\nR 2 (#550082)\nU 2 (#175033)\nR 6 (#036dc2)\nD 3 (#068791)\nR 9 (#3ff6f2)\nD 5 (#4a5783)\nR 13 (#4d5f92)\nD 6 (#3e3423)\nL 12 (#4f62d2)\nD 7 (#5e4363)\nL 3 (#0f7032)\nU 7 (#285261)\nL 12 (#4ea392)\nD 5 (#4c2dc1)\nL 4 (#0d2822)\nD 5 (#4c2dc3)\nR 9 (#518da2)\nD 2 (#41b3b1)\nR 7 (#023270)\nD 3 (#13d6e1)\nR 11 (#0874c0)\nD 3 (#2026c1)\nR 4 (#68f3a0)\nD 7 (#2026c3)\nL 8 (#208470)\nD 4 (#09bd81)\nL 3 (#193a10)\nD 7 (#5f3491)\nL 4 (#08cad2)\nD 10 (#068793)\nL 10 (#48acb2)\nD 4 (#20e341)\nL 7 (#6137a2)\nD 8 (#20e343)\nL 7 (#0bf292)\nD 7 (#5b5f13)\nL 8 (#2b2532)\nD 3 (#034073)\nL 5 (#3c7bb2)\nD 11 (#09c643)\nL 3 (#0d6e52)\nU 3 (#569d23)\nL 5 (#63fed0)\nU 4 (#162193)\nL 4 (#2eb310)\nU 3 (#655e23)\nL 10 (#42f8e0)\nU 4 (#341983)\nR 14 (#3dbbc0)\nU 5 (#551b13)\nL 5 (#2a94f0)\nU 6 (#05ae53)\nL 2 (#09db90)\nU 5 (#2c9e13)\nL 8 (#4c6d10)\nD 10 (#40ffb3)\nL 3 (#306c30)\nD 2 (#338911)\nL 6 (#4bed00)\nD 7 (#338913)\nR 7 (#12aae0)\nD 4 (#459613)\nL 7 (#75d3a2)\nD 7 (#37ad61)\nL 6 (#6dcf92)\nD 4 (#3b7703)\nR 9 (#0ee2b2)\nD 4 (#514c13)\nR 6 (#0ee2b0)\nD 3 (#2863b3)\nL 8 (#52eee2)\nD 8 (#2fc771)\nL 7 (#5be782)\nD 4 (#2f39a1)\nL 6 (#5be780)\nU 4 (#5625b1)\nL 2 (#5588c2)\nU 14 (#37ad63)\nL 3 (#0681e2)\nU 4 (#085481)\nL 3 (#037432)\nU 12 (#31ed51)\nL 4 (#6791e2)\nD 5 (#3546d3)\nL 6 (#4419e2)\nD 10 (#3546d1)\nL 4 (#2c1a72)\nD 10 (#5bead1)\nL 3 (#3b3252)\nD 9 (#3390c1)\nL 3 (#1d78c2)\nD 5 (#488d71)\nR 10 (#244042)\nD 2 (#10d1e1)\nR 5 (#3fd582)\nD 5 (#5025a1)\nL 3 (#381b70)\nD 11 (#771831)\nL 7 (#2abf50)\nU 11 (#17be81)\nL 5 (#1eb3c0)\nD 5 (#3d9c61)\nL 5 (#5f4de2)\nD 8 (#278361)\nL 2 (#2b95b2)\nD 9 (#2cb0b1)\nL 4 (#4a0182)\nD 6 (#2c6bb3)\nL 2 (#499642)\nD 5 (#4c76d3)\nL 8 (#2fe412)\nU 9 (#07b893)\nL 2 (#236d52)\nU 8 (#3956a3)\nL 7 (#34f252)\nU 3 (#52bbf1)\nL 7 (#189470)\nU 4 (#54b661)\nL 9 (#189472)\nU 7 (#0110f1)\nL 3 (#409bf2)\nU 3 (#46d3e3)\nL 5 (#4c0f82)\nU 11 (#215e73)\nL 4 (#4c0f80)\nU 7 (#4050f3)\nL 9 (#39b192)\nU 7 (#28b043)\nL 3 (#011270)\nU 7 (#1f6693)\nR 7 (#73c390)\nU 2 (#2c4113)\nR 5 (#0321c0)\nU 8 (#2f2903)\nL 12 (#5ab560)\nU 3 (#4dd983)\nL 6 (#38b7d2)\nU 12 (#03c8c3)\n",
"brief": {
Expand Down
88 changes: 50 additions & 38 deletions src/day18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use hex_color::HexColor;

mod grid;
mod macros;
mod problem;
use problem::*;

type Int = i64;

Expand Down Expand Up @@ -178,42 +180,52 @@ impl Polygon {
}
}

fn main() {
println!("Hello, World! from src/day18.rs!");
// Part 1 - Example
let dig_plan = vec_of_strings![
"R 6 (#70c710)",
"D 5 (#0dc571)",
"L 2 (#5713f0)",
"D 2 (#d2c081)",
"R 2 (#59c680)",
"D 2 (#411b91)",
"L 5 (#8ceee2)",
"U 2 (#caa173)",
"L 1 (#1b58a2)",
"U 2 (#caa171)",
"R 2 (#7807d2)",
"U 3 (#a77fa3)",
"L 2 (#015232)",
"U 2 (#7a21e3)",
];
let polygon = Polygon::from_dig_plan(&dig_plan, false);
dbg!(&polygon);
polygon.print();
let a = polygon.calc_area();
test!(62, a);
// Part 1
let i = aoc::get(2023, 18);
let polygon = Polygon::from_dig_plan(&i, false);
let a = polygon.calc_area();
test!(48652, a);
// Part 2 - Example
let polygon = Polygon::from_dig_plan(&dig_plan, true);
//dbg!(&polygon);
let a = polygon.calc_area();
test!(952408144115 as i64, a);
// Part 2
let polygon = Polygon::from_dig_plan(&i, true);
let a = polygon.calc_area();
test!(45757884535661 as i64, a);
struct DayEighteen {}

impl Problem for DayEighteen {
const YEAR: Year = 2023;
const DAY: Day = 18;
const PART_ONE_EXAMPLE_EXPECTED: Answer = 62;
const PART_ONE_EXPECTED: Answer = 48652;
const PART_TWO_EXAMPLE_EXPECTED: Answer = 952408144115;
const PART_TWO_EXPECTED: Answer = 45757884535661;

fn example_input() -> ExampleInput {
"
R 6 (#70c710)
D 5 (#0dc571)
L 2 (#5713f0)
D 2 (#d2c081)
R 2 (#59c680)
D 2 (#411b91)
L 5 (#8ceee2)
U 2 (#caa173)
L 1 (#1b58a2)
U 2 (#caa171)
R 2 (#7807d2)
U 3 (#a77fa3)
L 2 (#015232)
U 2 (#7a21e3)
"
}

fn solve_part_one(input: Input, is_example: bool) -> Answer {
let dig_plan = input.lines().map(|s| s.to_string()).collect();
let polygon = Polygon::from_dig_plan(&dig_plan, false);
debug!(is_example, &polygon);
if is_example {
polygon.print();
}
let a = polygon.calc_area();
a
}

fn solve_part_two(input: Input, _is_example: bool) -> Answer {
let dig_plan = input.lines().map(|s| s.to_string()).collect();
let polygon = Polygon::from_dig_plan(&dig_plan, true);
let a = polygon.calc_area();
a
}
}

run!(DayEighteen);
4 changes: 3 additions & 1 deletion src/problem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ pub trait Problem {
line.trim_start() // Trim leading spaces from non-empty lines
}
})
.collect::<Vec<_>>()[1..]
.skip(1) // Skip first
.take(Self::example_input().lines().count() - 2) // Skip last
.collect::<Vec<_>>()
.join("\n")
}

Expand Down

0 comments on commit 8bf38bf

Please sign in to comment.