Solve AOC day 9
This commit is contained in:
@@ -89,5 +89,14 @@
|
|||||||
(bootCode.setBreakHandler (lambda [:BootCodeFix bootCodeFork] (when (= bootCodeFork.instructionPointer (bootCodeFork.instructionCount)) (print .accumulator (the BootCodeFix bootCodeFork)))))
|
(bootCode.setBreakHandler (lambda [:BootCodeFix bootCodeFork] (when (= bootCodeFork.instructionPointer (bootCodeFork.instructionCount)) (print .accumulator (the BootCodeFix bootCodeFork)))))
|
||||||
(bootCode.addBreakPoint (bootCode.instructionCount))
|
(bootCode.addBreakPoint (bootCode.instructionCount))
|
||||||
(bootCode.run))
|
(bootCode.run))
|
||||||
|
|
||||||
|
// Day 9
|
||||||
|
(assert (= 127 (XMAS.firstOffender 5
|
||||||
|
[35 20 15 25 47 40 62 55 65 95 102 117 150 182 127 219 299 277 309 576])))
|
||||||
|
(assert (= 133015568 (XMAS.firstOffender 25 (Util.readInts "src/year2020/inputs/day9.txt"))))
|
||||||
|
(assert (= "[15,25,47,40]" (.toString (SummingTuples.contiguousSumTuple 127
|
||||||
|
[35 20 15 25 47 40 62 55 65 95 102 117 150 182 127 219 299 277 309 576]))))
|
||||||
|
(let [tuple (SummingTuples.contiguousSumTuple 133015568 (Util.readInts "src/year2020/inputs/day9.txt"))]
|
||||||
|
(assert (= 16107959 (+ (apply min tuple) (apply max tuple)))))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -14,4 +14,16 @@
|
|||||||
pairThatSatisfies (pairWithSum requiredForTrio numbers)]
|
pairThatSatisfies (pairWithSum requiredForTrio numbers)]
|
||||||
(when pairThatSatisfies
|
(when pairThatSatisfies
|
||||||
(return [number (nth pairThatSatisfies 0) (nth pairThatSatisfies 1)]))))
|
(return [number (nth pairThatSatisfies 0) (nth pairThatSatisfies 1)]))))
|
||||||
|
null)
|
||||||
|
|
||||||
|
(defun contiguousSumTuple [sum :kiss.List<Int> numbers]
|
||||||
|
(doFor i (range numbers.length)
|
||||||
|
(deflocal &mut testSum (nth numbers i))
|
||||||
|
(doFor j (range (+ i 1) numbers.length)
|
||||||
|
(set testSum (+ testSum (nth numbers j)))
|
||||||
|
(cond
|
||||||
|
((= testSum sum)
|
||||||
|
(return (numbers.slice i (+ j 1))))
|
||||||
|
((> testSum sum)
|
||||||
|
(break)))))
|
||||||
null)
|
null)
|
7
projects/aoc/src/year2020/XMAS.hx
Normal file
7
projects/aoc/src/year2020/XMAS.hx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package year2020;
|
||||||
|
|
||||||
|
import kiss.Prelude;
|
||||||
|
import year2020.SummingTuples;
|
||||||
|
|
||||||
|
@:build(kiss.Kiss.build("src/year2020/XMAS.kiss"))
|
||||||
|
class XMAS {}
|
5
projects/aoc/src/year2020/XMAS.kiss
Normal file
5
projects/aoc/src/year2020/XMAS.kiss
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
(defun firstOffender [preambleLength :kiss.List<Int> input]
|
||||||
|
(doFor idx (range preambleLength input.length)
|
||||||
|
(unless (SummingTuples.pairWithSum (nth input idx) (input.slice (- idx preambleLength) idx))
|
||||||
|
(return (nth input idx))))
|
||||||
|
(print null))
|
1000
projects/aoc/src/year2020/inputs/day9.txt
Normal file
1000
projects/aoc/src/year2020/inputs/day9.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user