-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
updates + improvements #4
Conversation
@@ -32,14 +32,12 @@ SOLVING PART 2: 209ms | |||
--- | |||
``` | |||
|
|||
This package assumes you have a [roc-lang/basic-cli](https://github.com/roc-lang/basic-cli) app (although that is not strictly necessary). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may confuse the new people
|
||
Example implementation: | ||
``` | ||
part1 : Str -> Result Str Str | ||
part1 = \input -> | ||
numbers = parseNumbers input | ||
|
||
combined = | ||
List.joinMap numbers \x -> | ||
List.map numbers \y -> | ||
{ x, y, sum: x + y, mul: x * y } | ||
|
||
when List.keepIf combined \c -> c.sum == 2020 is | ||
[first, ..] -> Ok "$(Num.toStr first.x) * $(Num.toStr first.y) = $(Num.toStr first.mul)" | ||
_ -> Err "expected at least one pair to have sum of 2020" | ||
|
||
part2 : Str -> Result Str Str | ||
part2 = \input -> | ||
numbers = parseNumbers input | ||
|
||
combined = | ||
List.joinMap numbers \x -> | ||
List.joinMap numbers \y -> | ||
List.map numbers \z -> | ||
{ x, y, z, sum: x + y + z, mul: x * y * z } | ||
|
||
when List.keepIf combined \c -> c.sum == 2020 is | ||
[first, ..] -> Ok "$(Num.toStr first.x) * $(Num.toStr first.y) * $(Num.toStr first.z) = $(Num.toStr first.mul)" | ||
_ -> Err "expected at least one triple to have sum of 2020" | ||
|
||
parseNumbers = \input -> input |> Str.splitOn "\n" |> List.keepOks Str.toU64 | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems helpful for first timers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
No description provided.