diff --git a/.gitignore b/.gitignore index 19095cd..730b8f8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ build/ *~ *.swp *.log +*.bak *.agda *.agdai /*.js @@ -12,3 +13,8 @@ mkday.py tmp min.js.gz src/Revision.newt +.calva +.clj-kondo +.joyride +.lsp +.vscode diff --git a/Makefile b/Makefile index 59e38c9..cb0d8c5 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,7 @@ test: newt.js aoctest: newt.js scripts/aoc + scripts/aoc25 # Misc diff --git a/aoc2025/Day1.newt.golden b/aoc2025/Day1.newt.golden new file mode 100644 index 0000000..8be69c9 --- /dev/null +++ b/aoc2025/Day1.newt.golden @@ -0,0 +1,6 @@ +aoc2025/day1/eg.txt +part1 3 +part2 6 +aoc2025/day1/input.txt +part1 1100 +part2 6358 diff --git a/aoc2025/Day11.newt.golden b/aoc2025/Day11.newt.golden new file mode 100644 index 0000000..e909439 --- /dev/null +++ b/aoc2025/Day11.newt.golden @@ -0,0 +1,11 @@ +aoc2025/day11/eg.txt +part1 5 +svr missing {"tag":0} +part2 0 +aoc2025/day11/eg2.txt +you missing {"tag":0} +part1 0 +part2 2 +aoc2025/day11/input.txt +part1 636 +part2 509312913844956 diff --git a/aoc2025/Day12.newt.golden b/aoc2025/Day12.newt.golden new file mode 100644 index 0000000..0eba3d6 --- /dev/null +++ b/aoc2025/Day12.newt.golden @@ -0,0 +1,6 @@ +aoc2025/day12/eg.txt +[7, 7, 7, 7, 7, 7] +3 rows, 0 easy, 3 maybe, 0 impossible +aoc2025/day12/input.txt +[7, 5, 7, 6, 7, 7] +1000 rows, 479 easy, 0 maybe, 521 impossible diff --git a/aoc2025/Day2.newt.golden b/aoc2025/Day2.newt.golden new file mode 100644 index 0000000..0298356 --- /dev/null +++ b/aoc2025/Day2.newt.golden @@ -0,0 +1,6 @@ +aoc2025/day2/eg.txt +part1 1227775554 +part2 4174379265 +aoc2025/day2/input.txt +part1 18893502033 +part2 26202168557 diff --git a/aoc2025/Day3.newt.golden b/aoc2025/Day3.newt.golden new file mode 100644 index 0000000..54c2554 --- /dev/null +++ b/aoc2025/Day3.newt.golden @@ -0,0 +1,6 @@ +aoc2025/day3/eg.txt +part1 357 +part2 3121910778619 +aoc2025/day3/input.txt +part1 17452 +part2 173300819005913 diff --git a/aoc2025/Day4.newt.golden b/aoc2025/Day4.newt.golden new file mode 100644 index 0000000..6c892ee --- /dev/null +++ b/aoc2025/Day4.newt.golden @@ -0,0 +1,6 @@ +aoc2025/day4/eg.txt +part1 13 +part2 43 +aoc2025/day4/input.txt +part1 1569 +part2 9280 diff --git a/aoc2025/Day5.newt.golden b/aoc2025/Day5.newt.golden new file mode 100644 index 0000000..7f1ea50 --- /dev/null +++ b/aoc2025/Day5.newt.golden @@ -0,0 +1,6 @@ +aoc2025/day5/eg.txt +part1 3 +part2 14 +aoc2025/day5/input.txt +part1 862 +part2 357907198933892 diff --git a/aoc2025/Day6.newt.golden b/aoc2025/Day6.newt.golden new file mode 100644 index 0000000..b967987 --- /dev/null +++ b/aoc2025/Day6.newt.golden @@ -0,0 +1,6 @@ +aoc2025/day6/eg.txt +part1 4277556 +part2 3263827 +aoc2025/day6/input.txt +part1 5346286649122 +part2 10389131401929 diff --git a/aoc2025/Day7.newt.golden b/aoc2025/Day7.newt.golden new file mode 100644 index 0000000..4f15957 --- /dev/null +++ b/aoc2025/Day7.newt.golden @@ -0,0 +1,10 @@ +aoc2025/day7/eg.txt +rows 15 +cols 14 +part1 21 +part2 40 +aoc2025/day7/input.txt +rows 141 +cols 140 +part1 1587 +part2 5748679033029 diff --git a/aoc2025/Day8.newt.golden b/aoc2025/Day8.newt.golden new file mode 100644 index 0000000..eafb2fa --- /dev/null +++ b/aoc2025/Day8.newt.golden @@ -0,0 +1,6 @@ +aoc2025/day8/eg.txt +part1 40 +part2 25272 +aoc2025/day8/input.txt +part1 123234 +part2 9259958565 diff --git a/aoc2025/Day9.newt.golden b/aoc2025/Day9.newt.golden new file mode 100644 index 0000000..ce70ea7 --- /dev/null +++ b/aoc2025/Day9.newt.golden @@ -0,0 +1,6 @@ +aoc2025/day9/eg.txt +part1 6 50 +part2 24 +aoc2025/day9/input.txt +part1 1222 4777816465 +part2 1410501884 diff --git a/aoc2025/Parser.newt b/aoc2025/Parser.newt new file mode 100644 index 0000000..5f9cfe0 --- /dev/null +++ b/aoc2025/Parser.newt @@ -0,0 +1,75 @@ +module Parser + +import Prelude +import Aoc + +Parser : U → U +Parser a = List Char → Either String (a × List Char) + +instance Monad Parser where + pure a = \ cs => Right (a, cs) + bind ma mab = \ cs => ma cs >>= uncurry mab + +instance Alternative Parser where + pa <|> pb = \ cs => case pa cs of + Left msg => pb cs + res => res + +instance Functor Parser where + map f pa = \ cs => case pa cs of + Left msg => Left msg + Right (a, cs) => Right (f a, cs) + +instance Applicative Parser where + return a = pure a + pa <*> pb = pa >>= (\ f => map f pb) + + +fail : ∀ a. String -> Parser a +fail msg = \ cs => Left msg + +-- TODO, case builder isn't expanding Parser Unit to count lambdas +eof : Parser Unit +eof = \case + Nil => Right (MkUnit, Nil) + _ => Left "expected eof" + +satisfy : (Char → Bool) → Parser Char +satisfy pred = \case + Nil => Left "unexpected EOF" + (c :: cs) => if pred c then Right (c, cs) else Left ("did not expect " ++ show c ++ " - " ++ pack cs) + +match : Char → Parser Char +match d = satisfy (_==_ d) + +any : Parser Char +any = satisfy (λ _ => True) + +some many : ∀ a. Parser a → Parser (List a) +many p = some p <|> pure Nil +some p = do + v <- p + vs <- many p + pure (v :: vs) + +string : String → Parser Unit +string str = go (unpack str) + where + go : List Char → Parser Unit + go Nil = pure MkUnit + go (c :: cs) = match c >> go cs + +number : Parser Int +number = stringToInt ∘ pack <$> some (satisfy isDigit) + -- do + -- digs <- some (satisfy isDigit) + -- pure $ stringToInt $ pack digs + +optional : ∀ a. Parser a → Parser (Maybe a) +optional pa = Just <$> pa <|> pure Nothing + +ws : Parser Unit +ws = many (match ' ') >> pure MkUnit + +token : String → Parser Unit +token str = string str >> ws diff --git a/scripts/aoc25 b/scripts/aoc25 new file mode 100755 index 0000000..42fe35e --- /dev/null +++ b/scripts/aoc25 @@ -0,0 +1,36 @@ +#!/bin/sh +mkdir -p tmp +echo "Test AoC 2025 solutions" +NCC="node newt.js" +total=0 +failed=0 +for fn in aoc2025/Day*.newt; do + total=$((total + 1)) + echo Test $fn + bn=$(basename $fn) + $NCC $fn -o out.js > tmp/${bn}.compile + if [ $? != "0" ]; then + echo Compile failed for $fn + failed=$((failed + 1)) + continue + fi + # if there is a golden file, run the code and compare output + if [ -f ${fn}.golden ]; then + node out.js > tmp/${bn}.out + if [ $? != "0" ]; then + echo Run failed for $fn + failed=$((failed + 1)) + continue + fi + if ! diff -q tmp/${bn}.out ${fn}.golden; then + echo "Output mismatch for $fn" + failed=$((failed + 1)) + if [ $1 = "--fix" ]; then + cp tmp/${bn}.out ${fn}.golden + fi + fi + fi +done + +echo "Total tests: $total" +echo "Failed tests: $failed"