Live data from Hacker News

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

github.com

81–90 of 96 posts

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

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

How do people usually tackle AdventOfCode? Most elegant/concise solution or best performant?

Asking because for example most solutions to Day 1 I've seen are O(n^2)

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

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

How do people usually tackle AdventOfCode? Most elegant/concise solution or best performant? Asking because for example most solutions to Day 1 I've seen are O(n^2)

I aim for "first thing that I can get to work and doesn't take more than 20 seconds". Usually they run in under 2 (Common Lisp is my language of choice). Then for the part 2 portions I may have to optimize.

I sometimes go back and clean up my solutions, though I aim for a combination of clarity and performance if I do that, clarity first.

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

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

How do people usually tackle AdventOfCode? Most elegant/concise solution or best performant? Asking because for example most solutions to Day 1 I've seen are O(n^2)

Unless I'm really unhappy with my solution, I stick with the first thing I write that spits out the correct answer. Since a lot of the problems require you to do some potentially interesting optimization to get an answer in a reasonable amount of time, I don't bother optimizing the ones that don't.

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

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

I think bash is a little strong. There’s a lot of ways to view programming and to identify as a programmer. In many ways, it’s a lament of mine and a feeling of being an imposter that I don’t necessarily enjoy what many programmers seem to. I didn’t attack anything and only presented my personal opinion.

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

#85

How do you algorithmically code like this? In my software engineering career, I am a plumber at best. Would fail hard at anyone who would ask me to code anything more than fizz buzz under time pressure. That said, I've built some incredible production worthy and robust systems that move mountains as a plumber. I am damn good at that.

I wouldn't worry about it. Jobs that require this are few and far between - so the necessity isn't there. HN have a wideon for this leetcode stuff. In reality, unless it's your hobby, you don't need to be able.

> In reality, unless it's your hobby, you don't need to be able.

I agree with you completely here. I also feel like I fit the description of a plumber presented here. The most challenging algorithmic problems that I've had to confront in my career, which came when I was working in DSP for an RF company, were things that were tackled by the team -- a group of very talented and very experienced engineers -- and we worked on these problems collaboratively and over a period of time that is not measurable in minutes or hours.

But, having said that, isn't it also undeniable these things, these leetcode-style algorithms, are used to gatekeep entry to many of the "better" jobs in our field, despite the fact that we know that these things are not strictly necessary on the job? At the very least, this has been my experience and I read the same anecdotes on HN frequently.

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

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

when I saw the first() function, I thought it was some default python that was new to me. But he defines it above in his commonly used functions: def first(iterable, default=None) -> object: "Return first item in iterable, or default." return next(iter(iterable), default)

How to tell he's a Lisper. :) Be glad it wasn't car().

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

#87
post #50
post #24

Earlier quoted context omitted.

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…

> it doesn’t do any one thing the best and doesn’t present an interesting paradigm

That's absolutely true. But once you've been through the language paradigms, written Forth and Prolog and Haskell and APL and Lisp, you don't gain much by immersing in a new language.

At that point you start looking for languages where the things you loathe about them intersect minimally with what you work on. Python has relatively little to loathe and is very convenient. I still reach for it by default as well, and I was at one point best known for my Haskell work.

It has nothing to do with Google marketing. Norvig's established enough where he lends luster to Google, not vice versa.

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

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

That one was tedious though. It's easy to see what the solution is, but it just takes a lot of time to write it up.

I punted on part 2 of #20 as well, but came back to it the next day with a reasonable idea. Some of the tedious parts are easier to do by hand, like picking the corner of the map to start with on #20, or solving the uniqueness on #21.

I'm still looking forward to reviewing how Norvig did most of the problems.

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

#89
post #67

I thought I spotted a bug on the very first day, part 2. 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 itertool…

Good point, dmurray. It was a subtle point here, and probably I should have commented on it.

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

#90

Earlier quoted context omitted.

when I saw the first() function, I thought it was some default python that was new to me. But he defines it above in his commonly used functions: def first(iterable, default=None) -> object: "Return first item in iterable, or default." return next(iter(iterable), default)

How to tell he's a Lisper. :) Be glad it wasn't car().

madhadron, I'm a Common Lisper, so I'm good with `first` and `rest`.
Post reply on HN