Live data from Hacker News

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

github.com

61–70 of 96 posts

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

#61
post #44

Can someone please explain how `for y in nums & {2020 - x} ` in his day 1 solution?

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…

The "x == y" test looks like a bug to me, unless duplicate entries are not allowed. For example [1010,1010,1721,979,366,299,675,1456] should return 1010 * 1010, not 1721 * 299.

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

#62
Probably the most indicative part of Norvig's code beauty is the requirements file [0]. With python developers being infamous for importing obscure/questionable libraries for even a simple task, I love how Norvig solved all these with just native libraries and the staples numpy/plt.

[0]: https://github.com/norvig/pytudes/blob/master/requirements.t...

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

#63

Probably the most indicative part of Norvig's code beauty is the requirements file [0]. With python developers being infamous for importing obscure/questionable libraries for even a simple task, I love how Norvig solved all these with just native libraries and the staples numpy/plt. [0]: https://github.com/norvig/pytudes/blob/master/requirements.t...

Why do you think python has that reputation? I don't associate it with python, I associate that with npm/js

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

#64
post #60
post #54

Earlier quoted context omitted.

I think it's because you sound condescending when sharing your opinions and seem to be insisting that others should agree with your sentiment.

Mind pointing out where? I asked a pretty simple question and got answers insinuating I said things I didn’t. Of course we all enjoy things for different reasons. I don’t insist on anything. People are free to disagree on whatever and have their own stance. If people like Advent of Code, that’s great. I have looked into it before, and it’s not for me. And I was also simply curious why Norvig seems to like Python so m…

In a thread about Peter Norvig solving AoC problems in Python, you bashed on 1) Peter Norvig, 2) AoC and 3) Python. You're entitled to your opinion, of course, but your comment reads like someone jumping into an enthusiastic conversation among Star Wars fans to tell everyone how much you dislike Star Wars. I'm sure you didn't intend it that way (based on your later comments), but that's how it comes across.

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

#66
post #41
post #22

Even as a software engineer who studied mathematics, I just can't get excited about the type of problems found in Advent of Code and other such things, like Project Euler. Those problems amount to little puzzles and tricks and algorithms that have little to no context. What I find interesting about computing and programming is the representation and exploration of ideas. Also, I can't help but wonder. Why does the Di…

As someone who has studied maths Proj Euler is infinitely more interesting especially in the harder questions. For me, most of time spent in advent of code is basically about parsing a blob of text. Project Euler inspires much more interesting ideas. Mostly it is number theory and algebra.

The same could be said for actual advent calendars - if you go around any supermarket you could get much better chocolate for a kid than any advent calendar will have and it'll doubtless be cheaper too. But when you're a certain age there's something particularly magical about the experience of waking up in the morning, finding the little door for today, opening it up and having the little (vaguely) christmas-themed chocolate shape.

As an adult, I have to say that for me doing AoC brought back a little of that magic. It helped that the problems unlocked at 6am in my timezone so I'd wake up, hack on the problem for an hour or so then walk my dog and get ready for work. It was also nice having a collective experience, knowing that not only 5-6 of my colleagues but thousands of other people across the globe were all going through the same problem at the same time. I really liked that feeling.

So yeah Project Euler has very compact, well-written, well-designed, challenging problems in spades ... but AoC is a very specific sort of event that I must admit I look forward to more and more each year :-)

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

#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 itertools combinations picks distinct elements from the iterable. If the test had been x != y != z it would have been a bug.

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

#68
This was precisely the kind of thing I was looking for. I've done AOC for a few years, and did OK this year (got 2 stars on all but 3 days, and one star on all but 2), but being able to compare my ramshackle, simplistic code to something like this is the project for a month - break down one a day.... I'll do this in february, so thanks for posting that, OP!

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

#69
post #61
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…

The "x == y" test looks like a bug to me, unless duplicate entries are not allowed. For example [1010,1010,1721,979,366,299,675,1456] should return 1010 * 1010, not 1721 * 299.

[deleted]

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

#70
post #63

Probably the most indicative part of Norvig's code beauty is the requirements file [0]. With python developers being infamous for importing obscure/questionable libraries for even a simple task, I love how Norvig solved all these with just native libraries and the staples numpy/plt. [0]: https://github.com/norvig/pytudes/blob/master/requirements.t...

Why do you think python has that reputation? I don't associate it with python, I associate that with npm/js

[deleted]
Post reply on HN