diff options
author | Marvin Borner | 2024-04-09 19:36:50 +0200 |
---|---|---|
committer | Marvin Borner | 2024-04-09 19:38:26 +0200 |
commit | 11b942c9ad3142b9661f213588fdb03b0405f08b (patch) | |
tree | da54f1761d16b55331297a8e664535b4e07a4cf0 /samples | |
parent | 2e0a67b6219052b57a9ca5db666038c31ea0cec9 (diff) |
Added test for AOC samples
(although 2018 is actually broken)
Diffstat (limited to 'samples')
-rw-r--r-- | samples/aoc/2015/01/output.check | 1 | ||||
-rw-r--r-- | samples/aoc/2015/02/input | 2 | ||||
-rw-r--r-- | samples/aoc/2015/02/output.check | 1 | ||||
-rw-r--r-- | samples/aoc/2015/02/solve.bruijn | 14 | ||||
-rw-r--r-- | samples/aoc/2016/01/input | 2 | ||||
-rw-r--r-- | samples/aoc/2016/01/output.check | 1 | ||||
-rw-r--r-- | samples/aoc/2016/01/solve.bruijn | 12 | ||||
-rw-r--r-- | samples/aoc/2017/01/input | 2 | ||||
-rw-r--r-- | samples/aoc/2017/01/output.check | 1 | ||||
-rw-r--r-- | samples/aoc/2017/01/solve.bruijn | 21 | ||||
-rw-r--r-- | samples/aoc/2018/01/output.check | 1 | ||||
-rw-r--r-- | samples/aoc/2019/01/output.check | 1 | ||||
-rw-r--r-- | samples/aoc/2020/01/output.check | 1 | ||||
-rw-r--r-- | samples/aoc/2021/01/output.check | 1 | ||||
-rw-r--r-- | samples/aoc/2022/01/output.check | 1 | ||||
-rw-r--r-- | samples/aoc/2022/02/output.check | 1 | ||||
-rw-r--r-- | samples/aoc/2023/01/output.check | 1 | ||||
-rw-r--r-- | samples/aoc/2023/02/output.check | 1 | ||||
-rwxr-xr-x | samples/test_all.sh | 21 |
19 files changed, 61 insertions, 25 deletions
diff --git a/samples/aoc/2015/01/output.check b/samples/aoc/2015/01/output.check new file mode 100644 index 0000000..1af61be --- /dev/null +++ b/samples/aoc/2015/01/output.check @@ -0,0 +1 @@ +?> <-1t : 5t> diff --git a/samples/aoc/2015/02/input b/samples/aoc/2015/02/input new file mode 100644 index 0000000..5d2a1f2 --- /dev/null +++ b/samples/aoc/2015/02/input @@ -0,0 +1,2 @@ +2x3x4 +1x1x10 diff --git a/samples/aoc/2015/02/output.check b/samples/aoc/2015/02/output.check new file mode 100644 index 0000000..f23db1b --- /dev/null +++ b/samples/aoc/2015/02/output.check @@ -0,0 +1 @@ +?> <101t : 48t> diff --git a/samples/aoc/2015/02/solve.bruijn b/samples/aoc/2015/02/solve.bruijn new file mode 100644 index 0000000..96bd9e0 --- /dev/null +++ b/samples/aoc/2015/02/solve.bruijn @@ -0,0 +1,14 @@ +:import std/Combinator . +:import std/String . +:import std/Math . +:import std/Char C + +parse (split-list-by (C.eq? 'x')) → (map string→number) + +main trim → lines → (map parse) → (φ cons part1 part2) + part1 foldl \(g add [φ add surface slack (^0 ⋅ ^(~0) : (^(~0) ⋅ ^(~(~0)) : {}(^(~(~0)) ⋅ ^0)))]) (+0) + surface foldl \(g add (mul (+2))) (+0) + slack lmin + part2 foldl \(g add (φ add ribbon bow)) (+0) + ribbon sort-asc → (take (+2)) → sum → (mul (+2)) + bow product diff --git a/samples/aoc/2016/01/input b/samples/aoc/2016/01/input index bb9f2a2..3ead1d8 100644 --- a/samples/aoc/2016/01/input +++ b/samples/aoc/2016/01/input @@ -1 +1 @@ -R5,L5,R5,R3 +L3,R1,L4,L1,L2,R4,L3,L3,R2,R3,L5,R1,R3,L4,L1,L2,R2,R1,L4,L4,R2,L5,R3,R2,R1,L1,L2,R2,R2,L1,L1,R2,R1,L3,L5,R4,L3,R3,R3,L5,L190,L4,R4,R51,L4,R5,R5,R2,L1,L3,R1,R4,L3,R1,R3,L5,L4,R2,R5,R2,L1,L5,L1,L1,R78,L3,R2,L3,R5,L2,R2,R4,L1,L4,R1,R185,R3,L4,L1,L1,L3,R4,L4,L1,R5,L5,L1,R5,L1,R2,L5,L2,R4,R3,L2,R3,R1,L3,L5,L4,R3,L2,L4,L5,L4,R1,L1,R5,L2,R4,R2,R3,L1,L1,L4,L3,R4,L3,L5,R2,L5,L1,L1,R2,R3,L5,L3,L2,L1,L4,R4,R4,L2,R3,R1,L2,R1,L2,L2,R3,R3,L1,R4,L5,L3,R4,R4,R1,L2,L5,L3,R1,R4,L2,R5,R4,R2,L5,L3,R4,R1,L1,R5,L3,R1,R5,L2,R1,L5,L2,R2,L2,L3,R3,R3,R1 diff --git a/samples/aoc/2016/01/output.check b/samples/aoc/2016/01/output.check new file mode 100644 index 0000000..3aa74a0 --- /dev/null +++ b/samples/aoc/2016/01/output.check @@ -0,0 +1 @@ +?> 12t diff --git a/samples/aoc/2016/01/solve.bruijn b/samples/aoc/2016/01/solve.bruijn index efdaaaa..e48c5ec 100644 --- a/samples/aoc/2016/01/solve.bruijn +++ b/samples/aoc/2016/01/solve.bruijn @@ -15,17 +15,17 @@ direction! [^0 : (S.string→number ~0)] ⧗ (List Char) → Direction # rotation : (x : y) start ((+0) : ((+0) : (+0))) ⧗ State -move [[go ((C.eq? ^0 'R' ++‣ --‣) ^1)]] ⧗ State → Direction → State +move [[go (C.eq? ^0 'R' ++‣ --‣ ^1)]] ⧗ State → Direction → State go [0 : (even? 0 y x)] - x (^(~2) + (p ~1)) : ~(~2) - p ((0 % (+4)) =? (+3)) -‣ [0] + x ^(~2) + (p ~1) : ~(~2) + p 0 % (+4) =? (+3) -‣ [0] y ^(~2) : (~(~2) + (p ~1)) - p ((0 % (+4)) =? (+2)) -‣ [0] + p 0 % (+4) =? (+2) -‣ [0] :test (move start (direction! "R42")) ((+1) : ((+42) : (+0))) part1 (P.uncurry …+…) ∘ ~‣ ∘ (foldl move start) ⧗ (List Direction) → State main [parts coords] - coords direction! <$> (split-list-by [C.eq? 0 ','] (init 0)) - parts [(part1 0)] + coords direction! <$> (split-list-by (C.eq? ',') (init 0)) + parts [part1 0] diff --git a/samples/aoc/2017/01/input b/samples/aoc/2017/01/input index 8f237ab..1d95b9e 100644 --- a/samples/aoc/2017/01/input +++ b/samples/aoc/2017/01/input @@ -1 +1 @@ -12131415 +91212129 diff --git a/samples/aoc/2017/01/output.check b/samples/aoc/2017/01/output.check new file mode 100644 index 0000000..a46999a --- /dev/null +++ b/samples/aoc/2017/01/output.check @@ -0,0 +1 @@ +?> <9t : 6t> diff --git a/samples/aoc/2017/01/solve.bruijn b/samples/aoc/2017/01/solve.bruijn index db29872..7dfef5a 100644 --- a/samples/aoc/2017/01/solve.bruijn +++ b/samples/aoc/2017/01/solve.bruijn @@ -4,20 +4,9 @@ :import std/Char C :import std/Pair P -self [[((zip 0) ∘ (drop 1) ∘ cycle) 0]] ⧗ Number → (List Number) → (List (Pair Number Number)) +self [[(zip 0) ∘ (drop 1) ∘ cycle 0]] -part1 sum ∘ eqs ∘ pairs - sum foldl [[^0 + 1]] (+0) - eqs filter (P.uncurry …=?…) - pairs self (+1) - -part2 [(sum ∘ eqs ∘ pairs) 0] - sum foldl [[^0 + 1]] (+0) - eqs filter (P.uncurry …=?…) - pairs self /²(length 0) - -:test (part1 ((+1) : ((+1) : ((+2) : {}(+2))))) ((+3)) - -main [parts nums] - nums C.char→number <$> ^(lines 0) - parts [(part1 0) : (part2 0)] +main [φ (cons ⋔ solve) part1 part2 (C.char→number <$> (trim 0))] + solve (filter (P.uncurry eq?)) → (foldl \(g add head) (+0)) + part1 self (+1) + part2 self /²(length 0) diff --git a/samples/aoc/2018/01/output.check b/samples/aoc/2018/01/output.check new file mode 100644 index 0000000..ede73be --- /dev/null +++ b/samples/aoc/2018/01/output.check @@ -0,0 +1 @@ +?> <1t : [36m[[0m[91m0[0m[36m][0m> diff --git a/samples/aoc/2019/01/output.check b/samples/aoc/2019/01/output.check new file mode 100644 index 0000000..00b4ad3 --- /dev/null +++ b/samples/aoc/2019/01/output.check @@ -0,0 +1 @@ +?> <34241t : 51316t> diff --git a/samples/aoc/2020/01/output.check b/samples/aoc/2020/01/output.check new file mode 100644 index 0000000..8f5213d --- /dev/null +++ b/samples/aoc/2020/01/output.check @@ -0,0 +1 @@ +?> <514579t : 241861950t> diff --git a/samples/aoc/2021/01/output.check b/samples/aoc/2021/01/output.check new file mode 100644 index 0000000..65f231e --- /dev/null +++ b/samples/aoc/2021/01/output.check @@ -0,0 +1 @@ +?> <7t : 5t> diff --git a/samples/aoc/2022/01/output.check b/samples/aoc/2022/01/output.check new file mode 100644 index 0000000..2bef9a3 --- /dev/null +++ b/samples/aoc/2022/01/output.check @@ -0,0 +1 @@ +?> <24000t : 45000t> diff --git a/samples/aoc/2022/02/output.check b/samples/aoc/2022/02/output.check new file mode 100644 index 0000000..f93a9da --- /dev/null +++ b/samples/aoc/2022/02/output.check @@ -0,0 +1 @@ +?> <15t : 12t> diff --git a/samples/aoc/2023/01/output.check b/samples/aoc/2023/01/output.check new file mode 100644 index 0000000..b12b656 --- /dev/null +++ b/samples/aoc/2023/01/output.check @@ -0,0 +1 @@ +?> 142t diff --git a/samples/aoc/2023/02/output.check b/samples/aoc/2023/02/output.check new file mode 100644 index 0000000..8fd48a9 --- /dev/null +++ b/samples/aoc/2023/02/output.check @@ -0,0 +1 @@ +?> <8t : 2286t> diff --git a/samples/test_all.sh b/samples/test_all.sh index 45b85ae..e6086d5 100755 --- a/samples/test_all.sh +++ b/samples/test_all.sh @@ -5,6 +5,10 @@ if [ -z "$1" ]; then exit 1 fi +# ================= +# Euler/Fun/Rosetta +# ================= + echo "# useful for run the tests of all samples at once" >All.bruijn echo >>All.bruijn @@ -22,4 +26,19 @@ if cat /dev/null | bruijn -v All.bruijn -r "$1" | tee /dev/fd/2 | grep -q "ERROR exit 1 fi -# hyperfine --warmup 5 --runs 20 "cat /dev/null | bruijn -r $1 All.bruijn" +# === +# AOC +# === + +FILES="$(find aoc -type f -name "*.bruijn")" + +for f in $FILES; do + dir="$(dirname "$f")" + cat "$dir/input" | bruijn -r "$1" "$f" | tail -n1 >temp.out + cmp temp.out "$dir/output.check" || ( + echo "AOC check $f failed" + exit 1 + ) +done + +rm -f temp.out |