Day5, add SortedMap

This commit is contained in:
2024-12-05 16:13:12 -08:00
parent 21b03368d4
commit ccbd617671
11 changed files with 268 additions and 42 deletions

View File

@@ -2,6 +2,10 @@ module Aoc
import Prelude
-- `by` is the first argument for use in `map`
nums' : String String List Int
nums' by s = map stringToInt $ filter (_/=_ "") $ split (trim s) by
nums : String List Int
nums s = map stringToInt $ filter (_/=_ "") $ split (trim s) " "
@@ -25,13 +29,3 @@ indexOf? {a} z xs = go Z z xs
go ix z Nil = Nothing
go ix z (x :: xs) =
if z == x then Just ix else go (S ix) z xs
-- if_then_else shorthand
-- Lean version uses a decidable instead of Bool
ite : a. Bool a a a
ite c t e = if c then t else e
-- probably not super efficient, but it works
qsort : a. (a a Bool) List a List a
qsort lt Nil = Nil
qsort lt (x :: xs) = qsort lt (filter (λ y => not $ lt x y) xs) ++ x :: qsort lt (filter (lt x) xs)