Live data from Hacker News

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

github.com

41–50 of 96 posts

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

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

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

#42

Can 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

#43
post #37
post #27

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

> 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

#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) 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 * y

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

#45
post #33
post #31

Earlier 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…

Why should we care what you find interesting or uninteresting?

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

#46
post #43
post #37

Earlier 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".

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 approach one. The first edition came out in 1995 and the second in 2003. Python came out first in 1991, and he joined Google in 2001. His comment makes it hard to know when he was referring to (and thus even what book), and what I don’t know is if the first edition of the modern approach book used Python or if that came later in the second edition (without going and finding copies of the editions myself).

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

#47
post #33

Earlier 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?

You’re of course free not to care. That’s absurd. But isn’t this a website designed for people to say what they find interesting or not?

Why are these comments so hostile?

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

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

Norvig is a teacher. His first choice was Lisp for a long time. He chooses Python because it is a good enough alternative for his teaching. You can find his motivation here: http://www.norvig.com/python-lisp.html

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

#49
post #46
post #43

Earlier 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…

Artificial Intelligence: A Modern Approach is "his and Russell's prior AI book". It seemed as if you were talking about a different book.

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

#50
post #24
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…

Is Python uninteresting?

I personally don’t think it is because in the face of many modern languages, it doesn’t do any one thing the best and doesn’t present an interesting paradigm. Is there something it does interesting that I can’t find in languages like F#, Racket, or Elixir?

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.

Post reply on HN