Solve AOC day 6
This commit is contained in:
@@ -34,6 +34,7 @@ class Helpers {
|
||||
}
|
||||
|
||||
public static function parseTypePath(path:String, from:ReaderExp):TypePath {
|
||||
// TODO function types with generic argument types are broken
|
||||
var genericParts = path.split("<");
|
||||
var typeParams:Array<TypeParam> = null;
|
||||
if (genericParts.length > 1) {
|
||||
|
@@ -70,8 +70,17 @@ class Kiss {
|
||||
Sys.println(nextExp.def.toString());
|
||||
#end
|
||||
var field = readerExpToField(nextExp, k);
|
||||
if (field != null)
|
||||
if (field != null) {
|
||||
#if test
|
||||
switch (field.kind) {
|
||||
case FVar(_, expr) | FFun({ret: _, args: _, expr: expr}):
|
||||
Sys.println(expr.toString());
|
||||
default:
|
||||
throw CompileError.fromExp(nextExp, 'cannot print the expression of generated field $field');
|
||||
}
|
||||
#end
|
||||
classFields.push(field);
|
||||
}
|
||||
case None:
|
||||
stream.dropWhitespace(); // If there was a comment, drop whitespace that comes after
|
||||
}
|
||||
@@ -141,7 +150,7 @@ class Kiss {
|
||||
throw CompileError.fromExp(exp, 'conversion not implemented');
|
||||
};
|
||||
#if test
|
||||
Sys.println(expr.toString());
|
||||
// Sys.println(expr.toString()); // For very fine-grained codegen inspection--slows compilation a lot.
|
||||
#end
|
||||
return expr;
|
||||
}
|
||||
|
9
projects/aoc/src/year2020/Customs.hx
Normal file
9
projects/aoc/src/year2020/Customs.hx
Normal 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 {}
|
14
projects/aoc/src/year2020/Customs.kiss
Normal file
14
projects/aoc/src/year2020/Customs.kiss
Normal 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)))
|
@@ -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 {}
|
||||
|
@@ -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)))))
|
||||
|
||||
|
@@ -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]
|
||||
|
2179
projects/aoc/src/year2020/inputs/day6-1.txt
Normal file
2179
projects/aoc/src/year2020/inputs/day6-1.txt
Normal file
File diff suppressed because it is too large
Load Diff
15
projects/aoc/src/year2020/inputs/day6-example2.txt
Normal file
15
projects/aoc/src/year2020/inputs/day6-example2.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
abc
|
||||
|
||||
a
|
||||
b
|
||||
c
|
||||
|
||||
ab
|
||||
ac
|
||||
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
|
||||
b
|
Reference in New Issue
Block a user