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

Wild #2

Open
alper opened this issue Dec 16, 2020 · 1 comment
Open

Wild #2

alper opened this issue Dec 16, 2020 · 1 comment

Comments

@alper
Copy link

alper commented Dec 16, 2020

Totally wild that this could be done in a fold. Kudos!

(7..target).fold(4, |last, i| i - seen.insert(last, i).unwrap_or(i))

@AxlLind
Copy link
Owner

AxlLind commented Dec 16, 2020

Thanks, I appreciate it! This implementation definitely wasn't my initial one but the more I looked at it the more it simplified into a single fold at the end 😅 The fact that HashMap::insert() returns the previous value is really what made it so clean.

@AxlLind AxlLind closed this as completed Dec 16, 2020
@AxlLind AxlLind reopened this Dec 22, 2020
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

No branches or pull requests

2 participants