Solve arrangement count for AOC Day 10pt2
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package year2020;
|
||||
|
||||
import haxe.Int64;
|
||||
import kiss.Prelude;
|
||||
import year2020.Util;
|
||||
|
||||
|
@@ -8,4 +8,15 @@
|
||||
(if (dist.exists num)
|
||||
(+ 1 (dictGet dist num))
|
||||
1)))
|
||||
dist))
|
||||
dist))
|
||||
|
||||
(defun arrangementCount [:kiss.List<Int> ratings startingIndex]
|
||||
(if (= startingIndex (- ratings.length 1)) 1
|
||||
(let [&mut :Int64 sum 0
|
||||
startingRating (nth ratings startingIndex)
|
||||
potentialNextAdapters (filter
|
||||
(for i (range (+ 1 startingIndex) (+ 4 startingIndex)) i)
|
||||
(lambda [index] (and (< index ratings.length) (<= (nth ratings index) (+ 3 startingRating)))))]
|
||||
(doFor subCount (map potentialNextAdapters (arrangementCount.bind ratings))
|
||||
(set sum (Int64.add sum subCount)))
|
||||
sum)))
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package year2020;
|
||||
|
||||
import haxe.ds.Map;
|
||||
import haxe.Int64;
|
||||
import StringTools;
|
||||
import kiss.Prelude;
|
||||
import kiss.Stream;
|
||||
|
@@ -116,8 +116,9 @@
|
||||
(assert (= 16107959 (+ (apply min tuple) (apply max tuple)))))
|
||||
|
||||
// Day 10
|
||||
(let [adapters (Util.readInts "src/year2020/inputs/day10.txt")]
|
||||
(.sort adapters Reflect.compare)
|
||||
(assert (Int64.eq 8 (Adapters.arrangementCount (sort [0 22 16 10 15 5 1 11 7 19 6 12 4]) 0)))
|
||||
(assert (Int64.eq 19208 (Adapters.arrangementCount (sort [0 52 28 33 18 42 31 14 46 20 48 47 24 23 49 45 19 38 39 11 1 32 25 35 8 17 7 9 4 2 34 10 3]) 0)))
|
||||
(let [adapters (sort (Util.readInts "src/year2020/inputs/day10.txt"))]
|
||||
(adapters.unshift 0)
|
||||
(adapters.push (+ 3 (last adapters)))
|
||||
(let [diffs (Adapters.differences adapters)
|
||||
|
Reference in New Issue
Block a user