blob: cb4d907ffeba47030b36c8f0fd0fbb3fbb04326e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
}
}
|