aboutsummaryrefslogtreecommitdiff
path: root/codingquest2024/src/day8
diff options
context:
space:
mode:
authorH.J <thechairman@thechairman.info>2024-03-22 14:30:51 -0400
committerH.J <thechairman@thechairman.info>2024-03-22 14:30:51 -0400
commita2c2b728ec6051323ed937f54816089cd2ae9d20 (patch)
tree21fcb2be2d16c5155641f747eba3edb17d284d7e /codingquest2024/src/day8
parente09491b19729a8848ea11662fb1173f5c466e910 (diff)
downloadgleam_aoc-a2c2b728ec6051323ed937f54816089cd2ae9d20.tar.gz
gleam_aoc-a2c2b728ec6051323ed937f54816089cd2ae9d20.zip
Codingquest complete
Diffstat (limited to 'codingquest2024/src/day8')
-rw-r--r--codingquest2024/src/day8/solution.gleam26
1 files changed, 26 insertions, 0 deletions
diff --git a/codingquest2024/src/day8/solution.gleam b/codingquest2024/src/day8/solution.gleam
new file mode 100644
index 0000000..cb4d907
--- /dev/null
+++ b/codingquest2024/src/day8/solution.gleam
@@ -0,0 +1,26 @@
+import gleam/io
+import gleam/int
+import gleam/list
+import utilities/memo
+
+const options = [40, 12, 2, 1]
+
+const distance = 856
+
+pub fn main() {
+ use cache <- memo.create()
+ solve(distance, cache)
+ |> io.debug
+}
+
+fn solve(target, cache) {
+ use <- memo.memoize(cache, target)
+ case target {
+ 0 -> 1
+ _ ->
+ options
+ |> list.filter(fn(n) { n <= target })
+ |> list.map(fn(n) { solve(target - n, cache) })
+ |> int.sum
+ }
+}