-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday17_part01.fs
34 lines (29 loc) · 1.08 KB
/
day17_part01.fs
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
27
28
29
30
31
32
33
34
module day17_part01
open AdventOfCode_2015.Modules
let parseContent(lines: string array) =
lines |> Array.map int
let findCombinationsMemoized target numbers =
let memo = System.Collections.Generic.Dictionary<_, _>()
let rec inner target numbers =
match target, numbers with
| 0, _ -> [ [] ]
| _, [] -> []
| _, x :: xs ->
if x > target then
inner target xs
else
let key = (target, numbers)
if memo.ContainsKey(key) then
memo[key]
else
let withX = inner (target - x) xs |> List.map (fun subset -> x :: subset)
let withoutX = inner target xs
let result = withX @ withoutX
memo[key] <- result
result
inner target numbers
let execute =
let input = "./day17/day17_input.txt"
let content = LocalHelper.GetLinesFromFile input
let containers = parseContent content |> List.ofArray
(findCombinationsMemoized 150 containers).Length