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…
Peter Norvig's “pytudes” for Advent of Code 2020
61–70 of 96 posts
Re: Peter Norvig's “pytudes” for Advent of Code 2020
#62[0]: https://github.com/norvig/pytudes/blob/master/requirements.t...
Re: Peter Norvig's “pytudes” for Advent of Code 2020
#63Probably 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
#64Earlier 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…
Re: Peter Norvig's “pytudes” for Advent of Code 2020
#65Re: Peter Norvig's “pytudes” for Advent of Code 2020
#66Even 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.
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 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
#68Re: Peter Norvig's “pytudes” for Advent of Code 2020
#69Earlier 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
#70Probably 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