Solve AOC day 6

This commit is contained in:
2020-12-06 09:51:29 -07:00
parent 7314e1ef32
commit 14a5e8d1d1
9 changed files with 2251 additions and 3 deletions

View File

@@ -0,0 +1,9 @@
package year2020;
import kiss.Prelude;
import year2020.Util;
using StringTools;
@:build(kiss.Kiss.build("src/year2020/Customs.kiss"))
class Customs {}

View File

@@ -0,0 +1,14 @@
(defun countAnyYes [:Array<String> group]
(countWhereYes group (lambda [c] (< 0 c))))
(defun countAllYes [:Array<String> group]
(countWhereYes group (lambda [c] (= c group.length))))
(defun countWhereYes [:Array<String> group predicate]
(let [yesDict (new Map<String,Int>)]
(doFor person group
(doFor question (person.split "")
(dict-set yesDict question
(+ 1
(if (yesDict.exists question) (dict-get yesDict question) 0)))))
(count yesDict predicate)))

View File

@@ -9,6 +9,7 @@ import year2020.SummingTuples;
import year2020.Passwords;
import year2020.Toboggan;
import year2020.Passports;
import year2020.Customs;
@:build(kiss.Kiss.build("src/year2020/Solutions.kiss"))
class Solutions {}

View File

@@ -46,4 +46,13 @@
// Day 4
(assert (= 2 (Passports.countValidPassports (new Stream "src/year2020/inputs/day4-example.txt"))))
(assert (= 250 (Passports.countValidPassports (new Stream "src/year2020/inputs/day4-1.txt"))))
(assert (= 158 (Passports.countValidPassports (new Stream "src/year2020/inputs/day4-1.txt") "strict"))))
(assert (= 158 (Passports.countValidPassports (new Stream "src/year2020/inputs/day4-1.txt") "strict")))
// TODO Day 5
// 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 + (print (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)))))

View File

@@ -6,6 +6,17 @@
StringTools.trim)
(lambda [l] (< 0 l.length))))
(defun readParagraphLines [file]
(.filter
(for paragraph
(.split
(.replace (File.getContent file) #|"\r"|# "")
#|"\n\n"|#)
(.filter
(paragraph.split #|"\n"|#)
(lambda [line] (< 0 line.length))))
(lambda [lines] (< 0 lines.length))))
(defun readInts [file] (let [lines (readLines file)] (lines.map Std.parseInt)))
(defun countChar [char str]

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,15 @@
abc
a
b
c
ab
ac
a
a
a
a
b