Skip to content
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

Merged
merged 1 commit into from
Nov 30, 2024
Merged

Conversation

Anton-4
Copy link
Contributor

@Anton-4 Anton-4 commented Nov 30, 2024

No description provided.

@@ -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).
Copy link
Contributor Author

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

Comment on lines +68 to +99

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
```
Copy link
Contributor Author

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

Copy link
Owner

@lukewilliamboswell lukewilliamboswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@lukewilliamboswell lukewilliamboswell merged commit 8f90b6f into lukewilliamboswell:main Nov 30, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants