Live data from Hacker News

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

github.com

71–80 of 96 posts

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

#71
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

Yeah, from my experience NPM/JS and Cargo/Rust win that competition by a landslide. Python has a very powerful standard library.

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

#73
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…

> I was also simply curious why Norvig seems to like Python so much

Why aren't you satisfied with his own explanations that you already knew about?

"I looked around for a language that was closer to the pseudocode in the book, and discovered Python was the closest. [...] Python is an excellent language for my intended use. It is easy to use (interactive with no compile-link-load-run cycle), which is important for my pedagogical purposes."

"I looked for the language that was most like our pseudocode, and found that Python was the best match. Then I had to teach myself enough Python to implement the examples from the textbook. I found that Python was very nice for certain types of small problems, and had the libraries I needed to integrate with lots of other stuff, at Google and elsewhere on the net."

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

#74
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.

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

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

#75
post #61

Earlier quoted context omitted.

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.

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

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

#76
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…

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)

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

#77
post #4

Always look forward to these so I can compare my solutions afterwards. Sometimes it's almost frustrating to see how clean and concise the mess I made could have been, but I do learn a lot. It's like he gets as close to golfing as possible, without the obfuscation. Too bad he punted on 20... one of the few difficult problems this year. Usually the hard problems are where you really see the contrast between his solutio…

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.

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

#78
post #64
post #60

Earlier quoted context omitted.

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.

[deleted]

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

#79
post #4

Always look forward to these so I can compare my solutions afterwards. Sometimes it's almost frustrating to see how clean and concise the mess I made could have been, but I do learn a lot. It's like he gets as close to golfing as possible, without the obfuscation. Too bad he punted on 20... one of the few difficult problems this year. Usually the hard problems are where you really see the contrast between his solutio…

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. :)

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

#80
post #4

Always look forward to these so I can compare my solutions afterwards. Sometimes it's almost frustrating to see how clean and concise the mess I made could have been, but I do learn a lot. It's like he gets as close to golfing as possible, without the obfuscation. Too bad he punted on 20... one of the few difficult problems this year. Usually the hard problems are where you really see the contrast between his solutio…

Interesting he thought it was tedious - I thought this one was actually the closest to being like a real world software engineering task! No mathematical tricks or lateral thinking, just a gnarly problem that requires planning and breaking down into more manageable pieces. I actually really enjoyed it for that.
Post reply on HN