diff options
author | J.J <thechairman@thechairman.info> | 2024-05-30 21:49:58 -0400 |
---|---|---|
committer | J.J <thechairman@thechairman.info> | 2024-05-30 21:49:58 -0400 |
commit | 231c2b688d1e6cf0846d46e883da30e042a9c6cf (patch) | |
tree | 98a6d3a461fe190b38b2cf33a708a1d01703fa70 /codingquest2024/src/day8 | |
parent | fe088aa5778dcdbaab4dd8d4a7395a91c444b45c (diff) | |
parent | a2c2b728ec6051323ed937f54816089cd2ae9d20 (diff) | |
download | gleam_aoc-231c2b688d1e6cf0846d46e883da30e042a9c6cf.tar.gz gleam_aoc-231c2b688d1e6cf0846d46e883da30e042a9c6cf.zip |
Merge branch 'main' of https://github.com/hunkyjimpjorps/AdventOfCode
Diffstat (limited to 'codingquest2024/src/day8')
-rw-r--r-- | codingquest2024/src/day8/solution.gleam | 26 |
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 + } +} |