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
Peter Norvig's “pytudes” for Advent of Code 2020
71–80 of 96 posts
Re: Peter Norvig's “pytudes” for Advent of Code 2020
#72Re: Peter Norvig's “pytudes” for Advent of Code 2020
#73Earlier 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…
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
#74Earlier 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.
Re: Peter Norvig's “pytudes” for Advent of Code 2020
#75Earlier 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.
"they need you to find the two entries that sum to 2020 and then multiply those two numbers together"
Re: Peter Norvig's “pytudes” for Advent of Code 2020
#76Can 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…
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
#77Always 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…
> 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
#78Earlier 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.
Re: Peter Norvig's “pytudes” for Advent of Code 2020
#79Always 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
#80Always 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…