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…
Peter Norvig's “pytudes” for Advent of Code 2020
41–50 of 96 posts
Re: Peter Norvig's “pytudes” for Advent of Code 2020
#42Can someone please explain how `for y in nums & {2020 - x} ` in his day 1 solution?
def day1_1(nums):
"Find 2 distinct numbers that sum to 2020, and return their product."
return first(x * y
for x in nums
for y in nums & {2020 - x}
if x != y)
`nums` is a set of integers
`nums & {2020 - x}` Finds all the numbers that are in the set of `nums` and the set of `{2020 - x}` - this basically extracts a number, `y`, for which `x+y = 2020`.So for each x in nums, he extracts a number from nums that, added to x, equals 2020. If there is such a number y, he checks if it is the same as x, and only if it is different, does he yield in his generator, as the product of y and x.
It's succint, but not exactly readable, imho.
Re: Peter Norvig's “pytudes” for Advent of Code 2020
#43Earlier quoted context omitted.
Here's his (Norvig's) previous answer on "Why Python" as a HN comment he made ~10 years ago: https://news.ycombinator.com/item?id=1803815 Also: https://norvig.com/python-lisp.html
Thanks for those, but I have read them already. His comments on his book and Python are not really relevant in today's world and are more of a historical interest. Also, I don't really understand the timeline from his comment and am not familiar enough with the book to know its history. Did the first edition use Python? (I am aware of his and Russell's prior AI book.)
I think you may be somewhat confused there. What book are you talking about?
Edit: I also wonder why his remarks ten or twenty years ago about Python being close to pseudocode "are not really relevant in today's world".
Re: Peter Norvig's “pytudes” for Advent of Code 2020
#44Can someone please explain how `for y in nums & {2020 - x} ` in his day 1 solution?
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) in nums and x != (2020 - x))
But that has a lot of duplication, so it'd probably be best to just use an imperative approach here and do something like: def day1_1(nums):
"Find 2 distinct numbers that sum to 2020, and return their product."
for x in nums:
y = 2020 - x
if x == y:
continue
if y in nums:
return x * yRe: Peter Norvig's “pytudes” for Advent of Code 2020
#45Earlier quoted context omitted.
...Because he finds it fun? We don't have to all enjoy the same things. In this particular case also, if you read his code, I would be surprised if you don't learn something.
That's fine, but it addresses a bunch of things I didn't say. I'm sure I would learn something if I read through the code in more detail, but that's true of a ton of things and time is what it is. I merely commented on what I personally find interesting and uninteresting. Also, even I, a non-Director of Research at Google and non-computer scientist, don't particular enjoy using the language I use on a day-to-day basi…
Re: Peter Norvig's “pytudes” for Advent of Code 2020
#46Earlier quoted context omitted.
Thanks for those, but I have read them already. His comments on his book and Python are not really relevant in today's world and are more of a historical interest. Also, I don't really understand the timeline from his comment and am not familiar enough with the book to know its history. Did the first edition use Python? (I am aware of his and Russell's prior AI book.)
> Did the first edition use Python? I think you may be somewhat confused there. What book are you talking about? Edit: I also wonder why his remarks ten or twenty years ago about Python being close to pseudocode "are not really relevant in today's world".
Re: Peter Norvig's “pytudes” for Advent of Code 2020
#47Earlier quoted context omitted.
That's fine, but it addresses a bunch of things I didn't say. I'm sure I would learn something if I read through the code in more detail, but that's true of a ton of things and time is what it is. I merely commented on what I personally find interesting and uninteresting. Also, even I, a non-Director of Research at Google and non-computer scientist, don't particular enjoy using the language I use on a day-to-day basi…
Why should we care what you find interesting or uninteresting?
Why are these comments so hostile?
Re: Peter Norvig's “pytudes” for Advent of Code 2020
#48Even 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…
Re: Peter Norvig's “pytudes” for Advent of Code 2020
#49Earlier quoted context omitted.
> Did the first edition use Python? I think you may be somewhat confused there. What book are you talking about? Edit: I also wonder why his remarks ten or twenty years ago about Python being close to pseudocode "are not really relevant in today's world".
What am I confused about other than what I asked? There’s two books. The first is Paradigms of Artificial Intelligence Programming , which used Common Lisp, and the second is Artificial Intelligence: A Modern Approach , which to my knowledge primarily uses or encourages Python. I was trying to place what time Norvig was referring to in the linked comment. He mentions his book, which I assumed to be the modern approac…
In the HN comment he says "the Lisp code that Russell and I had online" so I don't think it's difficult to guess it's indeed AIMA he's talking about.
I don't think that the book, in any of the four editions, "primarily uses or encourages Python". I have not checked them all, but I expect the book to still use pseudocode exclusively. Elsewhere, they provide implementations in different languages: https://github.com/aimacode
Re: Peter Norvig's “pytudes” for Advent of Code 2020
#50Even 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…
Is Python uninteresting?
But my question was trying to understand if Python has some hidden mojo that Norvig really likes or if he uses it like this publicly because he’s a top leader at a company that also uses it heavily. People listen to people like that in positions like his, and if he did all his solutions in Julia, F#, or whatever, that’d probably route a good amount of attention to those other languages that Google and his book doesn’t really use or hire for.