diff --git a/projects/aoc/src/Main.hx b/projects/aoc/src/Main.hx index d2dfaa7f..4caade6d 100644 --- a/projects/aoc/src/Main.hx +++ b/projects/aoc/src/Main.hx @@ -3,7 +3,8 @@ package; import kiss.Kiss; import kiss.Prelude; import kiss.List; -import year2020.Solutions as Solutions2020; +import year2018.Solutions2018; +import year2020.Solutions2020; @:build(kiss.Kiss.build()) class Main {} diff --git a/projects/aoc/src/Main.kiss b/projects/aoc/src/Main.kiss index 3c9ab2f7..02d45f82 100644 --- a/projects/aoc/src/Main.kiss +++ b/projects/aoc/src/Main.kiss @@ -1,4 +1,6 @@ (load "UtilMacros.kiss") (defun :Void main [] + (year 2018 + (Solutions2018.run)) (year 2020 (Solutions2020.run))) \ No newline at end of file diff --git a/projects/aoc/src/year2018/Solutions.kiss b/projects/aoc/src/year2018/Solutions.kiss deleted file mode 100644 index eb590fb5..00000000 --- a/projects/aoc/src/year2018/Solutions.kiss +++ /dev/null @@ -1,165 +0,0 @@ -(defmacro day [num &rest body] - `(when (<= 0 (days.indexOf ,num)) - (print (+ "day " (Std.string ,num))) - ,@body)) - -(defmacro dayTodo [num] - `(day ,num (print "TODO"))) - -(defun run [:kiss.List days] - (day 1 - (let [p (SummingTuples.pairWithSum 2020 [1721 979 366 299 675 1456])] - (assert (and (has p 1721) (has p 299)) "pairWithSum is broken")) - (let [[a b] (SummingTuples.pairWithSum 2020 (Util.readInts "src/year2020/inputs/day1-1.txt"))] - (assert (= 545379 (* a b)) "pairWithSum is broken")) - (let [t (SummingTuples.trioWithSum 2020 [1721 979 366 299 675 1456])] - (assert (and (has t 675) (has t 366) (has t 979)) - "trioWithSum is broken")) - (let [[a b c] (SummingTuples.trioWithSum 2020 (Util.readInts "src/year2020/inputs/day1-1.txt"))] - (assert (= 257778836 (* a b c)) - "trioWithSum is broken"))) - - (day 2 - (assert (Passwords.validateInputLine "1-3 a: abcde" Passwords.parsePasswordCheck1)) - (assert !(Passwords.validateInputLine "1-3 b: cdefg" Passwords.parsePasswordCheck1)) - (assert (Passwords.validateInputLine "2-9 c: ccccccccc" Passwords.parsePasswordCheck1)) - (assert (= 655 (count (map (Util.readLines "src/year2020/inputs/day2-1.txt") (.bind Passwords.validateInputLine _ Passwords.parsePasswordCheck1)) (lambda [v] v)))) - (assert (Passwords.validateInputLine "1-3 a: abcde" Passwords.parsePasswordCheck2)) - (assert !(Passwords.validateInputLine "1-3 b: cdefg" Passwords.parsePasswordCheck2)) - (assert !(Passwords.validateInputLine "2-9 c: ccccccccc" Passwords.parsePasswordCheck2)) - (assert (= 673 (count (map (Util.readLines "src/year2020/inputs/day2-1.txt") (.bind Passwords.validateInputLine _ Passwords.parsePasswordCheck2)) (lambda [v] v))))) - - (day 3 - (deflocal exampleHillTile [ - "..##......." - "#...#...#.." - ".#....#..#." - "..#.#...#.#" - ".#...##..#." - "..#.##....." - ".#.#.#....#" - ".#........#" - "#.##...#..." - "#...##....#" - ".#..#...#.#"]) - (assert (= "..#.##.####" (Toboggan.pathString exampleHillTile 0 0 3 1))) - (assert (= 2 (Toboggan.pathTrees exampleHillTile 0 0 1 1))) - (assert (= 3 (Toboggan.pathTrees exampleHillTile 0 0 5 1))) - (assert (= 4 (Toboggan.pathTrees exampleHillTile 0 0 7 1))) - (assert (= 2 (Toboggan.pathTrees exampleHillTile 0 0 1 2))) - (assert (= 289 (Util.countChar "#" (Toboggan.pathString (Util.readLines "src/year2020/inputs/day3-1.txt") 0 0 3 1)))) - (assert (= 5522401584 (let [hillTile (Util.readLines "src/year2020/inputs/day3-1.txt")] - (apply * (for args [[0 0 1 1] [0 0 3 1] [0 0 5 1] [0 0 7 1] [0 0 1 2]] (apply (Toboggan.pathTrees.bind hillTile) args))))))) - - (day 4 - (assert (= 2 (Passports.countValidPassports (Stream.fromFile "src/year2020/inputs/day4-example.txt")))) - (assert (= 250 (Passports.countValidPassports (Stream.fromFile "src/year2020/inputs/day4-1.txt")))) - (assert (= 158 (Passports.countValidPassports (Stream.fromFile "src/year2020/inputs/day4-1.txt") "strict")))) - - (day 5 - (assert (= 567 (Seating.seatId "BFFFBBFRRR"))) - (let [:kiss.List seatIds (map (Util.readLines "src/year2020/inputs/day5-1.txt") Seating.seatId)] - (seatIds.sort (lambda [a b] (- a b))) - (assert (= 947 (nth seatIds -1))) - (deflocal &mut lastId -1) - (deflocal &mut myId -1) - (doFor id seatIds - (when (and (<= 0 lastId) !(= lastId (- id 1))) - (set myId (- id 1)) - (break)) - (set lastId id)) - (assert (= 636 myId)))) - - (day 6 - (assert (= 6 (Customs.countAnyYes ["abcx" "abcy" "abcz"]))) - (assert (= 6683 (apply + (map (Util.readParagraphLines "src/year2020/inputs/day6-1.txt") Customs.countAnyYes)))) - (assert (= 6 (apply + (map (Util.readParagraphLines "src/year2020/inputs/day6-example2.txt") Customs.countAllYes)))) - (assert (= 3122 (apply + (map (Util.readParagraphLines "src/year2020/inputs/day6-1.txt") Customs.countAllYes))))) - - (day 7 - (deflocal parentMap (new ParentMap)) - (deflocal childMap (new ChildMap)) - (doFor line (Util.readLines "src/year2020/inputs/day7.txt") - (Bags.parseRule line parentMap childMap)) - (deflocal :Map shinyGoldParents (new Map)) - (Bags.findIndirectContainers "shiny gold" childMap shinyGoldParents) - (assert (= 172 (count shinyGoldParents))) - (assert (= 39645 (Bags.totalChildBags "shiny gold" parentMap)))) - - (day 8 - (let [example (new BootCodeExample)] - (example.setBreakHandler (lambda [example] (assert (= 5 .accumulator example)))) - (example.run)) - (let [bootCode (new BootCodeReal)] - (bootCode.setBreakHandler (lambda [bootCode] (assert (= 2058 bootCode.accumulator)))) - (bootCode.run)) - /* (print "BootCodeFixExample") - (let [bootCode (new BootCodeFixExample)] - (bootCode.setBreakHandler - (lambda [bootCodeFork] - (if (= bootCodeFork.instructionPointer (bootCodeFork.instructionCount)) - (print (+ "answer could be " (Std.string bootCodeFork.accumulator) " forked at " (Std.string bootCodeFork.forkedAt))) - (print "hit an infinite loop")))) - (bootCode.addBreakPoint (bootCode.instructionCount)) - (bootCode.run)) - (print "BootCodeFixReal") - (let [bootCode (new BootCodeFix)] - (bootCode.setBreakHandler - (lambda [bootCodeFork] - (if (= bootCodeFork.instructionPointer (bootCodeFork.instructionCount)) - (print (+ "answer could be " (Std.string bootCodeFork.accumulator) " forked at " (Std.string (+ 1 bootCodeFork.forkedAt)))) - (print "hit an infinite loop")))) - (bootCode.addBreakPoint (bootCode.instructionCount)) - (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)))))) - - (day 10 - (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) - dist (Adapters.distribution diffs)] - (assert (= 1998 (* (dictGet dist 1) (dictGet dist 3))))) - (let [memoized (memoize Adapters.arrangementCount)] - (set Adapters.arrangementCount #|cast memoized|#)) - (assert (= "347250213298688" (Int64.toStr (Adapters.arrangementCount adapters 0)))))) - - (day 11 - (let [example (new FerrySimExample) - real (new FerrySimReal)] - (example.run) - (example.simulate) - (assert (= 71 (example.countFullSeats))) - (real.run) - (real.fullSimulate) - (assert (= 2329 (real.countFullSeats))))) - - (day 12 - (let [script (new EvasionScript)] - (script.run) - (assert (= 441 (+ (Math.abs script.x) (Math.abs script.y)))))) - - (dayTodo 13) - (dayTodo 14) - (dayTodo 15) - (dayTodo 16) - (dayTodo 17) - (dayTodo 18) - (dayTodo 19) - (dayTodo 20) - (dayTodo 21) - (dayTodo 22) - (dayTodo 23) - (dayTodo 24) - (dayTodo 25)) \ No newline at end of file diff --git a/projects/aoc/src/year2018/Solutions.hx b/projects/aoc/src/year2018/Solutions2018.hx similarity index 87% rename from projects/aoc/src/year2018/Solutions.hx rename to projects/aoc/src/year2018/Solutions2018.hx index 1bbcc6b4..d2b70412 100644 --- a/projects/aoc/src/year2018/Solutions.hx +++ b/projects/aoc/src/year2018/Solutions2018.hx @@ -8,4 +8,4 @@ import kiss.Stream; import Util; @:build(kiss.Kiss.build()) -class Solutions {} +class Solutions2018 {} diff --git a/projects/aoc/src/year2018/Solutions2018.kiss b/projects/aoc/src/year2018/Solutions2018.kiss new file mode 100644 index 00000000..611cd070 --- /dev/null +++ b/projects/aoc/src/year2018/Solutions2018.kiss @@ -0,0 +1,34 @@ +(load "../UtilMacros.kiss") + +(defun run [] + (day 1 + (let [inputs + (.slice (.split (sys.io.File.getContent "src/year2018/inputs/day1.txt") "\n") 0 -1) + numbers + (.map inputs Std.parseInt)] + (assert (= 529 (apply + numbers))))) + + (dayTodo 2) + (dayTodo 3) + (dayTodo 4) + (dayTodo 5) + (dayTodo 6) + (dayTodo 7) + (dayTodo 8) + (dayTodo 9) + (dayTodo 10) + (dayTodo 11) + (dayTodo 12) + (dayTodo 13) + (dayTodo 14) + (dayTodo 15) + (dayTodo 16) + (dayTodo 17) + (dayTodo 18) + (dayTodo 19) + (dayTodo 20) + (dayTodo 21) + (dayTodo 22) + (dayTodo 23) + (dayTodo 24) + (dayTodo 25)) \ No newline at end of file diff --git a/projects/aoc/src/year2020/Solutions.hx b/projects/aoc/src/year2020/Solutions2020.hx similarity index 95% rename from projects/aoc/src/year2020/Solutions.hx rename to projects/aoc/src/year2020/Solutions2020.hx index 1c3b8f8f..9be12e9d 100644 --- a/projects/aoc/src/year2020/Solutions.hx +++ b/projects/aoc/src/year2020/Solutions2020.hx @@ -24,4 +24,4 @@ import year2020.Evasion; #end @:build(kiss.Kiss.build()) -class Solutions {} +class Solutions2020 {} diff --git a/projects/aoc/src/year2020/Solutions.kiss b/projects/aoc/src/year2020/Solutions2020.kiss similarity index 100% rename from projects/aoc/src/year2020/Solutions.kiss rename to projects/aoc/src/year2020/Solutions2020.kiss diff --git a/projects/aoc2018/build.hxml b/projects/aoc2018/build.hxml deleted file mode 100644 index 26ea1755..00000000 --- a/projects/aoc2018/build.hxml +++ /dev/null @@ -1,4 +0,0 @@ --lib kiss --cp src ---main aoc2018.Main ---interp \ No newline at end of file diff --git a/projects/aoc2018/haxelib.json b/projects/aoc2018/haxelib.json deleted file mode 100644 index 7a777608..00000000 --- a/projects/aoc2018/haxelib.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "main": "aoc2018.Main", - "name": "aoc2018", - "description": "", - "classPath": "src/", - "dependencies": { - "kiss": "" - }, - "url": "https://github.com/NQNStudios/kisslang", - "contributors": [ - "Angad Singh" - ], - "version": "0.0.0", - "releasenote": "", - "tags": [], - "license": "LGPL" -} \ No newline at end of file diff --git a/projects/aoc2018/src/aoc2018/Main.hx b/projects/aoc2018/src/aoc2018/Main.hx deleted file mode 100644 index a3a5d8ea..00000000 --- a/projects/aoc2018/src/aoc2018/Main.hx +++ /dev/null @@ -1,7 +0,0 @@ -package aoc2018; - -import kiss.Kiss; -import kiss.Prelude; - -@:build(kiss.Kiss.build()) -class Main {} diff --git a/projects/aoc2018/src/aoc2018/Main.kiss b/projects/aoc2018/src/aoc2018/Main.kiss deleted file mode 100644 index 815ba6b0..00000000 --- a/projects/aoc2018/src/aoc2018/Main.kiss +++ /dev/null @@ -1,8 +0,0 @@ -(defun :Void main [] - (let [ - inputs (.slice (.split (sys.io.File.getContent "src/aoc2018/input_day1.txt") "\n") 0 -1) - numbers (.map inputs Std.parseInt) - ] - (print (apply + numbers)) - ) -) diff --git a/projects/aoc2018/src/aoc2018/input_day1.txt b/projects/aoc2018/src/aoc2018/input_day1.txt deleted file mode 100644 index 8d6a976b..00000000 --- a/projects/aoc2018/src/aoc2018/input_day1.txt +++ /dev/null @@ -1,951 +0,0 @@ --10 --12 -+1 -+14 -+11 --19 --4 -+10 -+10 --12 --13 --10 --8 -+11 -+3 --10 -+8 -+5 --14 -+7 -+12 -+12 -+14 --1 -+17 --5 -+9 --15 -+8 --16 -+9 -+6 -+17 --11 -+19 -+11 --9 --1 --8 --16 --5 -+6 -+2 -+6 -+12 -+15 -+16 --6 --8 --5 -+11 --9 -+19 -+19 --5 --12 --17 --20 -+9 --6 --2 -+20 -+15 --8 -+15 -+19 --5 --17 --9 -+1 --9 --11 --19 --1 --15 -+18 --4 -+19 -+3 -+21 -+5 --1 -+8 -+9 -+9 --16 -+17 --15 -+18 -+14 -+8 --13 --2 --15 -+13 -+19 --13 -+5 -+16 -+16 -+7 -+8 --19 -+3 --12 -+18 --16 --19 -+8 --16 -+20 -+15 --5 --17 -+15 -+14 --2 -+18 --6 -+5 -+16 -+13 --8 --9 --1 -+13 -+18 --2 -+16 --4 -+19 -+6 -+14 --6 --16 --10 --5 --15 -+11 -+10 -+18 -+8 --2 -+15 --9 -+7 -+10 -+9 --6 -+1 --17 --12 -+19 -+14 --9 --18 -+20 -+12 -+10 -+14 -+6 -+9 --18 -+4 -+15 -+15 -+3 -+9 --4 --19 -+8 -+16 -+19 --12 --1 -+16 -+11 -+13 --8 -+4 -+18 -+10 --11 -+18 --8 -+19 --4 --5 --12 --3 --10 --11 --18 --7 -+3 -+14 -+18 -+2 --7 --12 -+14 -+12 -+13 --1 -+13 --1 -+15 -+13 --1 --17 --4 -+17 --3 -+13 -+5 --19 -+17 -+10 -+6 --15 -+11 -+16 -+11 -+20 -+19 -+5 --11 --2 --12 --6 --11 --14 -+5 -+10 --23 -+14 --11 -+22 --1 --14 --35 --23 -+11 -+4 -+10 --6 -+19 --5 -+4 --13 --7 -+11 --24 --17 -+9 --17 -+11 -+2 --4 --10 --24 -+14 -+15 -+19 -+7 --2 -+11 --13 --8 --8 --14 --17 -+6 -+8 --16 --18 -+1 --21 --14 -+8 --2 -+20 --19 -+9 --15 --6 --7 -+4 --3 --8 -+16 -+15 --26 -+18 --22 --16 --3 --17 --18 -+4 -+5 -+3 --1 -+3 -+2 -+3 -+7 --5 -+20 --11 -+15 --6 --19 --24 --6 --20 -+13 --4 --18 -+15 -+9 -+16 -+12 --5 -+16 -+9 --4 --14 --9 --19 --5 --16 --16 -+5 --4 -+12 --15 --15 --14 -+4 --18 --12 --4 -+6 -+9 --12 -+14 -+9 --6 -+3 -+8 -+4 -+7 --14 --15 --18 -+12 --19 --14 --15 --16 -+15 --8 -+14 --4 --21 -+7 --12 --2 --10 --6 -+14 -+14 --9 --14 --16 -+2 -+7 -+5 --15 --15 -+19 --16 --5 --16 --19 -+9 --27 --8 -+6 -+1 --14 --9 --50 --9 --21 -+5 --20 --19 -+6 --11 -+6 -+1 --17 --14 --2 -+8 --4 -+16 -+1 --3 --9 -+20 -+15 --22 --3 --13 --12 --25 -+5 --13 --2 --8 --11 -+17 -+3 --7 -+13 -+1 -+18 --13 -+1 -+7 --15 --43 --6 --10 --9 --20 --7 --8 --15 --9 -+13 --9 -+24 -+13 -+5 --8 --15 --4 --4 --4 --14 --21 -+16 -+15 --14 --20 --20 --15 --19 --41 -+16 -+3 -+8 --22 --30 -+8 -+40 -+15 -+24 --7 -+22 -+10 -+15 -+9 -+28 -+14 -+2 -+14 -+6 -+17 -+1 -+30 -+5 --2 -+46 -+24 -+46 --3 --7 -+35 -+16 -+13 --21 -+28 -+13 --25 -+180 -+25 -+5 --9 -+23 --5 --2 -+13 --12 -+2 --25 --5 -+18 --24 -+45 -+17 --7 -+22 --152 --11 -+4 -+50 -+129 --7 -+22 -+109 --56 -+80 -+29 --75060 --2 --14 -+7 --17 --5 -+6 --3 -+18 -+19 --14 --12 --6 -+9 --5 --13 --6 --3 --15 -+13 -+3 --18 --11 -+16 --2 -+10 --14 --7 -+19 --20 -+15 -+10 -+12 -+10 -+16 --11 -+14 --5 -+14 -+11 --5 -+1 --13 -+1 -+18 --10 -+25 -+13 --17 -+15 --18 -+1 --6 --12 -+5 --7 -+18 --6 --18 --17 --5 --15 --1 --15 -+1 --12 -+9 -+16 -+8 -+5 -+1 -+9 -+18 --13 --30 --27 --19 -+2 --16 --19 --10 --18 -+21 -+18 --5 -+14 -+9 --6 -+2 --16 --11 -+1 -+18 --4 -+19 -+7 -+6 --8 -+25 --50 -+6 --21 -+6 --2 -+14 --11 -+10 --9 -+16 -+25 --61 --17 --14 -+13 -+3 --14 --4 --1 -+9 --1 --4 --5 -+7 --15 -+7 -+16 -+6 --2 --11 --11 --13 -+11 --12 --13 --8 -+3 --13 -+16 --1 --14 -+19 -+4 -+10 -+12 -+26 -+6 -+4 -+24 --31 -+9 --10 --23 --13 -+3 --18 --9 --6 -+1 --2 -+15 --10 --17 --17 -+15 -+9 -+4 -+19 --4 -+12 -+11 --25 -+16 -+4 --2 -+39 -+49 -+9 -+96 -+4 -+19 -+3 -+11 -+25 -+14 -+11 --5 --26 --8 --16 -+11 -+2 -+2 --1 --10 --45 --160 --31 --3 --43 --18 -+19 -+3 -+4 -+11 --16 --19 --22 -+6 -+2 -+10 --11 --17 -+7 -+1 -+15 -+17 --19 -+6 --26 --7 --9 -+19 -+2 -+6 --22 -+2 --8 -+5 -+7 -+9 -+8 --16 -+2 --19 --19 --3 -+16 -+5 -+4 --18 --11 --19 -+16 --15 -+7 --1 --9 --19 -+11 --17 --5 -+7 --11 -+16 --19 -+5 -+21 --2 -+12 -+14 --7 -+18 --8 -+10 --11 --17 -+3 --13 -+19 --3 -+10 -+17 -+17 --18 -+7 --2 --2 -+12 --6 -+19 --20 --15 --11 --27 -+8 -+18 -+9 --1 --2 -+19 -+7 -+12 -+32 -+14 -+13 --9 --14 -+20 -+18 --4 --49 --6 --10 --7 --4 --9 --6 --37 --21 --2 -+5 -+12 -+4 --33 --4 --13 --4 -+13 --19 --7 --16 --1 --1 -+8 --14 --15 -+11 --10 --14 --22 --11 -+10 --3 -+7 -+9 --15 -+16 --7 --1 -+2 -+20 -+11 --1 -+6 --2 -+3 -+3 -+2 --20 --10 -+11 --10 -+13 --1 -+20 -+7 -+7 -+5 -+1 -+4 --13 -+15 --3 -+2 --4 --3 --1 -+13 --15 --14 --2 --6 -+3 -+13 --19 --11 -+8 --21 --2 --23 --18 -+20 -+7 -+6 --28 -+7 --33 -+13 --16 --18 --10 --18 -+13 -+8 --14 --13 --2 -+4 --14 --7 --18 --20 --4 --5 -+8 --4 -+16 -+21 -+20 --8 --14 --2 --14 --22 -+14 -+36 -+32 --28 -+1 --21 -+8 -+14 -+75784 diff --git a/projects/aoc2018/test.sh b/projects/aoc2018/test.sh deleted file mode 100644 index 0ee8ae95..00000000 --- a/projects/aoc2018/test.sh +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/bash - -haxe build.hxml \ No newline at end of file