Finished day 10 in roc.

This commit is contained in:
peacememories 2022-12-18 00:49:23 +01:00
parent ba3fbd426e
commit 01909909be

View file

@ -26,6 +26,14 @@ connect = \firstEff, secondEff ->
{ state: res2.state, ticks: List.concat res1.ticks res2.ticks }
mapChunks : List a, Nat, (List a -> b) -> List b
mapChunks = \list, len, fn ->
listLen = List.len list
List.range {start: At 0, end: Before listLen, step: len}
|> List.map \start ->
List.sublist list {start, len}
|> fn
sequence : List Eff -> Eff
sequence = \list ->
List.walk list empty \effects, elem -> connect effects elem
@ -89,12 +97,25 @@ main =
[20, 60, 100, 140, 180, 220]
|> List.mapTry getStrength
|> Result.map List.sum
|> \str -> when str is
Ok num ->
num
Err _ ->
crash "Index out of bounds"
_ <- totalStrength
|> Num.toStr
|> Stdout.line
|> Task.await
when totalStrength is
Ok num ->
num
|> Num.toStr
|> Stdout.line
Err _ ->
crash "Index out of bounds"
image = cycles
|> mapChunks 40 \line ->
List.mapWithIndex line \x, column ->
if Num.abs (x - (Num.intCast column)) < 2 then
"#"
else
"."
|> Str.joinWith ""
|> Str.joinWith "\n"
Stdout.line image