refactoring aoc
This commit is contained in:
@@ -259,6 +259,7 @@ class Helpers {
|
||||
ReaderExpDef: ReaderExpDef
|
||||
},
|
||||
Operand: {
|
||||
toDynamic: Operand.toDynamic,
|
||||
fromDynamic: Operand.fromDynamic
|
||||
}
|
||||
});
|
||||
|
@@ -20,6 +20,13 @@ class KissInterp extends Interp {
|
||||
this.nullForUnknownVar = nullForUnknownVar;
|
||||
|
||||
variables.set("Prelude", Prelude);
|
||||
variables.set("kiss", {
|
||||
Operand: {
|
||||
fromDynamic: Operand.fromDynamic,
|
||||
toDynamic: Operand.toDynamic
|
||||
}
|
||||
});
|
||||
trace(variables["kiss"]);
|
||||
variables.set("Lambda", Lambda);
|
||||
variables.set("Std", Std);
|
||||
variables.set("Keep", ExtraElementHandling.Keep);
|
||||
|
@@ -192,7 +192,11 @@ class Macros {
|
||||
conditionInterp.variables.set(flag, value);
|
||||
}
|
||||
try {
|
||||
var conditionHScript = parser.parseString(Prelude.convertToHScript(conditionStr));
|
||||
var hscriptStr = Prelude.convertToHScript(conditionStr);
|
||||
#if test
|
||||
Prelude.print(hscriptStr);
|
||||
#end
|
||||
var conditionHScript = parser.parseString(hscriptStr);
|
||||
return if (Prelude.truthy(conditionInterp.execute(conditionHScript))) {
|
||||
thenExp;
|
||||
} else {
|
||||
|
@@ -25,7 +25,7 @@ abstract Operand(Either<String, Float>) from Either<String, Float> to Either<Str
|
||||
// Doing this one implicitly just wasn't working in conjunction with Lambda.fold
|
||||
|
||||
/* @:from */
|
||||
public inline static function fromDynamic(d:Dynamic):Operand {
|
||||
public static function fromDynamic(d:Dynamic):Operand {
|
||||
return switch (Type.typeof(d)) {
|
||||
case TInt | TFloat: Right(0.0 + d);
|
||||
// Treating true and false as operands can be useful for equality. In practice, no one should use them
|
||||
|
@@ -1,9 +1,3 @@
|
||||
(defun :Void main []
|
||||
(let [args (Sys.args)
|
||||
[&mut days years] (for arg args
|
||||
(case arg
|
||||
("all" [])
|
||||
(otherwise (map (arg.split ",") Std.parseInt))))]
|
||||
(set days (or days (for i (range 1 26) i)))
|
||||
(when (or (= 0 years.length) (<= 0 (years.indexOf 2020)))
|
||||
(Solutions2020.run days))))
|
||||
(year 2020
|
||||
(Solutions2020.run)))
|
@@ -1,4 +1,4 @@
|
||||
package year2020;
|
||||
package;
|
||||
|
||||
import sys.io.File;
|
||||
import kiss.Prelude;
|
||||
|
7
projects/aoc/src/UtilMacros.kiss
Normal file
7
projects/aoc/src/UtilMacros.kiss
Normal file
@@ -0,0 +1,7 @@
|
||||
(defmacro day [num &rest body]
|
||||
`(#when (+ "day" (Std.string ,num))
|
||||
(print (+ "day " (Std.string ,num)))
|
||||
,@body))
|
||||
|
||||
(defmacro dayTodo [num]
|
||||
`(day ,num (print "TODO")))
|
@@ -2,7 +2,6 @@ package year2020;
|
||||
|
||||
import haxe.Int64;
|
||||
import kiss.Prelude;
|
||||
import year2020.Util;
|
||||
|
||||
using StringTools;
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package year2020;
|
||||
|
||||
import kiss.Prelude;
|
||||
import year2020.Util;
|
||||
|
||||
using StringTools;
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package year2020;
|
||||
|
||||
import kiss.Prelude;
|
||||
import year2020.Util;
|
||||
|
||||
using StringTools;
|
||||
|
||||
|
@@ -3,5 +3,7 @@ package year2020;
|
||||
import kiss.EmbeddedScript;
|
||||
import kiss.Prelude;
|
||||
|
||||
#if (day12 && year2020)
|
||||
@:build(kiss.EmbeddedScript.build("EvasionDSL.kiss", "inputs/day12.txt"))
|
||||
class EvasionScript extends EmbeddedScript {}
|
||||
#end
|
||||
|
@@ -2,7 +2,6 @@ package year2020;
|
||||
|
||||
import kiss.Prelude;
|
||||
import kiss.Operand;
|
||||
import year2020.Util;
|
||||
|
||||
using StringTools;
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package year2020;
|
||||
|
||||
import kiss.Prelude;
|
||||
import year2020.Util;
|
||||
|
||||
using StringTools;
|
||||
|
||||
|
@@ -5,7 +5,6 @@ import haxe.Int64;
|
||||
import StringTools;
|
||||
import kiss.Prelude;
|
||||
import kiss.Stream;
|
||||
import year2020.Util;
|
||||
import year2020.SummingTuples;
|
||||
import year2020.Passwords;
|
||||
import year2020.Toboggan;
|
||||
|
@@ -1,12 +1,6 @@
|
||||
(defmacro day [num &rest body]
|
||||
`(when (<= 0 (days.indexOf ,num))
|
||||
(print (+ "day " (Std.string ,num)))
|
||||
,@body))
|
||||
(load "../UtilMacros.kiss")
|
||||
|
||||
(defmacro dayTodo [num]
|
||||
`(day ,num (print "TODO")))
|
||||
|
||||
(defun run [:kiss.List<Int> days]
|
||||
(defun run []
|
||||
(day 1
|
||||
(let [p (SummingTuples.pairWithSum 2020 [1721 979 366 299 675 1456])]
|
||||
(assert (and (has p 1721) (has p 299)) "pairWithSum is broken"))
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package year2020;
|
||||
|
||||
import kiss.Prelude;
|
||||
import year2020.Util;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class Toboggan {}
|
||||
|
@@ -1,9 +0,0 @@
|
||||
package year2020;
|
||||
|
||||
import sys.io.File;
|
||||
import kiss.Prelude;
|
||||
|
||||
using StringTools;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class Util {}
|
@@ -1,24 +0,0 @@
|
||||
(defun readLines [file]
|
||||
(.filter
|
||||
(.map
|
||||
// TODO implement escape sequences in kiss string literals
|
||||
(.split (.replace (File.getContent file) #|"\r"|# "") #|"\n"|#)
|
||||
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))))
|
||||
|
||||
// TODO won't need to specify type here if last is not a quickNth
|
||||
(defun :kiss.List<Int> readInts [file] (let [lines (readLines file)] (lines.map Std.parseInt)))
|
||||
|
||||
(defun countChar [char str]
|
||||
(count (str.split "") (lambda [c] ?(= c char))))
|
@@ -1,5 +1,15 @@
|
||||
#! /bin/bash
|
||||
|
||||
DAYS=${1:-all}
|
||||
YEARS=${2:-all}
|
||||
haxe -D test -lib kiss -cp src --run Main $DAYS $YEARS
|
||||
DAYS=${1:-1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25}
|
||||
YEARS=${2:-2018,2019,2020}
|
||||
DEFINITIONS="-D test"
|
||||
IFS=',' read -ra SPLIT_DAYS <<< "$DAYS"
|
||||
for day in "${SPLIT_DAYS[@]}"; do
|
||||
DEFINITIONS="$DEFINITIONS -D day$day"
|
||||
done
|
||||
IFS=',' read -ra SPLIT_YEARS <<< "$YEARS"
|
||||
for year in "${SPLIT_YEARS[@]}"; do
|
||||
DEFINITIONS="$DEFINITIONS -D year$year"
|
||||
done
|
||||
echo $DEFINITIONS
|
||||
haxe -D test -D days=$DAYS -D years=$YEARS $DEFINITIONS build.hxml
|
Reference in New Issue
Block a user