Live data from Hacker News

Peter Norvig's “pytudes” for Advent of Code 2020

github.com

91–96 of 96 posts

Re: Peter Norvig's “pytudes” for Advent of Code 2020

#91
post #44

Earlier quoted context omitted.

It's a bit overly clever. I am a huge fan of Peter Norvig (and he was once my skip-level boss), but I'd call this code out in a code review for being obtuse. Notice that the input, `nums`, is a set. So he's taking the intersection of two sets. One set always has one item, so the result will be a collection with either 0 or 1 items. It could have also been written as: first(x * (2020 - x) for x in nums if (2020 - x) i…

I am not sure I would advocate for this but, from Python 3.8, this is an instance where assignment expressions could allow the first code without duplication. first(x * y for x in nums if (y := 2020 - x) in nums and x != y)

I agree, tuvistavie! But my default machine has 3.7 installed, and I didn't want to get too far ahead of readers. Sometime next year I'll go to 3.8, and look forward to using ":="

Re: Peter Norvig's “pytudes” for Advent of Code 2020

#92
Day 5 part 1 solution is interesting. I had implemented it the obvious way doing a binary search. I didn't realize you could represent that string as binary and get the equivalent integer. That's really cool however I am not sure I get the idea behind why that actually works

Re: Peter Norvig's “pytudes” for Advent of Code 2020

#93
post #3

This is very well-written code. I don't think anyone would bring into question Norvig's technical skills, but I wouldn't think someone like him would spend much time at his job writing code, or have much free time to program as a hobby. As someone who aspires to a position similar to Norvig's (directing research at an organization that is frequently applied in real life), I think it's really cool to see him having ti…

If you haven't, you should check out the free course he gave at Udacity.

Thanks for the recommendation! It looks quite good. Assuming you're referencing this:

https://www.udacity.com/course/design-of-computer-programs--...

I have been meaning to brush up on my interview skills, and I've found the lack of structure in LeetCode's Monthly problem sets to be quite frustrating. Every time I'd get stuck on a certain problem, I'd dive deep into the techniques behind the solution just to discard that knowledge the next day, as the selection of problems was seemingly random.

Re: Peter Norvig's “pytudes” for Advent of Code 2020

#94
post #75

Earlier quoted context omitted.

Given that the comment says "Find 2 distinct numbers that sum to 2020", I expect duplicate entries are not allowed.

Yes, but I cannot find the same in the problem definition: "they need you to find the two entries that sum to 2020 and then multiply those two numbers together" https://adventofcode.com/2020/day/1

There are frequently non-stated properties of the input in Advent of Code that simplify the problem a bit.

Re: Peter Norvig's “pytudes” for Advent of Code 2020

#95
post #79

Earlier quoted context omitted.

Full quote > Family holiday preparations kept me from doing Part 2 on the night it was released, and unfortunately I didn't feel like coming back to it later: it seemed too tedious for too little reward. I thought it was inelegant that a solid block of # pixels would be considered a sea monster with waves. Phew - I'm not alone.

My computers are full of half finished projects if that makes you feel better. :)

Mine too, I even have a few Flash (.fla) project files (games) here coming through an array of backups

Re: Peter Norvig's “pytudes” for Advent of Code 2020

#96
post #67

I thought I spotted a bug on the very first day, part 2. def day1_2(nums): "Find 3 distinct numbers that sum to 2020, and return their product." return first(x * y * z for x, y in combinations(nums, 2) for z in nums & {2020 - x - y} if x != z != y) The last line (if x != z != y) returns true when x and y are equal and z is different. But x and y are already constrained to be different since nums is a set and itertool…

[deleted]
Post reply on HN