-
Notifications
You must be signed in to change notification settings - Fork 8
Days 08-10 solved in python #84
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
Conversation
Day08/python
Revert "Day08/python"
* Update test.sh
* Solution for day09 * cleanup * Added solution to test.sh
* day10 solution * Added puzzle io * Update test.sh
Arxcis
left a comment
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.
08,09,10 delivered with glans! 🤩
| if s > magic_number: | ||
| break |
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.
Aha najs optimization 👏
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.
if not any(s == lines[p+25] for s in map(sum, itertools.combinations(lines[p: p+25], 2))):This one is pretty cool too imo:
because any accepts iterators, hence also generators or generator expressions, such as above, it will not exhaust the for loop when s==lines[p+25] is met for any single instance of s. mapalso behaves the same way, meaning that I'm effectively...
- not summing any more combinations than neccessary, and
- not creating any more combinations from the preamable.
making that line more effective than my original loop:
for p in range(len(lines) - 26):
found=False
for a, b in itertools.combinations(lines[p: p+25], 2):
if a + b == lines[p + 25]:
found = True
break # This break won't break me out of the outer loop, which is what I really want,
if found: # hence the 'found' check in the outer loop
break # writing it all in a function would also work - using `return` to jump out of the inner loopThere 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.
Aha. So any and map are lazy-evaluating when working on generators.
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.
Essentially, yeah 🦖
Didn't take the time to sit down and get these solutions added on the day, but here they are!