diff --git a/aoc2024/Day17.newt b/aoc2024/Day17.newt index c1c620f..da44ba2 100644 --- a/aoc2024/Day17.newt +++ b/aoc2024/Day17.newt @@ -72,7 +72,7 @@ step mach@(M a b c mem ip out) = 5 => let o = combo op % itobi 8 in step (M a b c mem (ip + 2) (out :< bitoi o)) 6 => let b = a >>> combo op in step (M a b c mem (ip + 2) out) 7 => let c = a >>> combo op in step (M a b c mem (ip + 2) out) - _ => ? + _ => mach where combo : Int → BigInt combo 4 = a diff --git a/aoc2024/Day20.newt b/aoc2024/Day20.newt index 376c129..0049584 100644 --- a/aoc2024/Day20.newt +++ b/aoc2024/Day20.newt @@ -72,10 +72,7 @@ calcCheats start dists fuel threshold = go (toList start) 0 -- only '.' have dist tryCand : Int → Point → Point → Int tryCand l pt cand = case lookupMap cand dists of - Just (_, dist) => - let d = manh pt cand in - if fuel < d then (let x = (trace "X" (pt, cand, d)) in ?) else - if l + manh pt cand + dist <= threshold then 1 else 0 + Just (_, dist) => if l + manh pt cand + dist <= threshold then 1 else 0 Nothing => 0 go : List (Point × Int) → Int → Int diff --git a/aoc2024/Day21.newt b/aoc2024/Day21.newt index 682bd94..806e4ce 100644 --- a/aoc2024/Day21.newt +++ b/aoc2024/Day21.newt @@ -78,7 +78,7 @@ pathCost from to kp = case lookupMap (from, to) kp.costs of Just (_, cost) => (kp, cost) Nothing => - let (path :: paths) = getPaths kp.interdit from to | _ => ? in + let (path :: paths) = getPaths kp.interdit from to | _ => fatalError "empty path list" in case kp of (KP n s i c Nothing) => (kp, 1) (KP n s i c (Just kp')) => diff --git a/aoc2024/Day21monad.newt b/aoc2024/Day21monad.newt index aa7f7ab..6c29817 100644 --- a/aoc2024/Day21monad.newt +++ b/aoc2024/Day21monad.newt @@ -106,7 +106,7 @@ pathCost from to = do case lookupMap (from, to) (.costs kp) of Just (_, cost) => pure {State Keypad} cost Nothing => - let (path :: paths) = getPaths (.interdit kp) from to | _ => ? in + let (path :: paths) = getPaths (.interdit kp) from to | _ => fatalError "empty paths" in case kp of (KP n s i c Nothing) => pure 1 (KP n s i c (Just kp')) => do diff --git a/aoc2024/Day24.newt b/aoc2024/Day24.newt index 28d7d2b..41905f9 100644 --- a/aoc2024/Day24.newt +++ b/aoc2024/Day24.newt @@ -132,7 +132,7 @@ swapPins a g (MkG i1 i2 op out) = else MkG i1 i2 op out fail : ∀ a. String -> a -fail msg = let x = trace "FAIL" msg in ? +fail msg = fatalError msg check : List Gate → List Int → String → Either (String × String) Unit check gates Nil carry = Right MkUnit diff --git a/aoc2024/Day9.newt b/aoc2024/Day9.newt index fd05c3b..bf29c88 100644 --- a/aoc2024/Day9.newt +++ b/aoc2024/Day9.newt @@ -21,7 +21,7 @@ part1 : List File -> Int part1 fs = go 0 0 fs $ reverse fs where go : Int -> Int -> List File -> List File -> Int - go pos csum Nil bwd = ? + go pos csum Nil bwd = fatalError "Shouldn't happen" go pos csum fwd Nil = csum go pos csum ((id, 0, 0) :: fwd) bwd = go pos csum fwd bwd go pos csum fwd ((id, 0, _) :: bwd) = go pos csum fwd bwd diff --git a/newt/Prelude.newt b/newt/Prelude.newt index 9de81c9..834123c 100644 --- a/newt/Prelude.newt +++ b/newt/Prelude.newt @@ -580,10 +580,13 @@ elem v (x :: xs) = if v == x then True else elem v xs pfunc trace uses (debugStr) : ∀ a. String -> a -> a := `(_, msg, a) => { console.log(msg,Prelude_debugStr(_,a)); return a }` mapMaybe : ∀ a b. (a → Maybe b) → List a → List b -mapMaybe f Nil = Nil -mapMaybe f (x :: xs) = case f x of - Just y => y :: mapMaybe f xs - Nothing => mapMaybe f xs +mapMaybe {a} {b} f xs = go Lin xs + where + go : SnocList b → List a → List b + go acc Nil = acc <>> Nil + go acc (x :: xs) = case f x of + Just y => go (acc :< y) xs + Nothing => go acc xs zip : ∀ a b. List a → List b → List (a × b) zip (x :: xs) (y :: ys) = (x,y) :: zip xs ys @@ -781,10 +784,6 @@ find : ∀ a. (a → Bool) → List a → Maybe a find f Nil = Nothing find f (x :: xs) = if f x then Just x else find f xs -any : ∀ a. (a → Bool) → List a → Bool -any f Nil = False -any f (x :: xs) = if f x then True else any f xs - -- TODO this would be faster, but less pure as a primitive -- fastConcat might be a good compromise joinBy : String → List String → String diff --git a/src/Lib/CompileExp.newt b/src/Lib/CompileExp.newt index a78a8e9..7f8eba2 100644 --- a/src/Lib/CompileExp.newt +++ b/src/Lib/CompileExp.newt @@ -76,6 +76,9 @@ arityForName fc nm = do (Just (PrimFn t arity used)) => pure arity +any : ∀ a. (a → Bool) → List a → Bool +any f Nil = False +any f (x :: xs) = if f x then True else any f xs -- need to eta out extra args, fill in the rest of the apps -- NOW - maybe eta here instead of Compile.newt, drop number on CApp