TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

306 点作者 ff7f00超过 4 年前

17 条评论

solaxun超过 4 年前
Always look forward to these so I can compare my solutions afterwards. Sometimes it&#x27;s almost frustrating to see how clean and concise the mess I made could have been, but I do learn a lot. It&#x27;s like he gets as close to golfing as possible, without the obfuscation.<p>Too bad he punted on 20... one of the few difficult problems this year. Usually the hard problems are where you <i>really</i> see the contrast between his solutions and the rest of us plebs. Do I sense a hit of frustration in his comment? ;)<p>&quot;too tedious for too little reward....&quot; &quot;sea monster as characters inelegant&quot;
评论 #25682973 未加载
评论 #25685706 未加载
评论 #25685153 未加载
评论 #25682569 未加载
评论 #25685869 未加载
评论 #25681701 未加载
systemvoltage超过 4 年前
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&#x27;ve built some incredible production worthy and robust systems that move mountains as a plumber. I am damn good at that.
评论 #25680807 未加载
评论 #25680738 未加载
评论 #25681047 未加载
评论 #25680736 未加载
评论 #25683146 未加载
评论 #25681413 未加载
dwrodri超过 4 年前
This is very well-written code. I don&#x27;t think anyone would bring into question Norvig&#x27;s technical skills, but I wouldn&#x27;t think someone like him would spend much time at his job writing code, or have much free time to program as a hobby.<p>As someone who aspires to a position similar to Norvig&#x27;s (directing research at an organization that is frequently applied in real life), I think it&#x27;s really cool to see him having time to do stuff like this.
评论 #25681264 未加载
评论 #25681545 未加载
edelans超过 4 年前
If you like this, you will love <a href="https:&#x2F;&#x2F;github.com&#x2F;mebeim&#x2F;aoc&#x2F;tree&#x2F;master&#x2F;2020" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mebeim&#x2F;aoc&#x2F;tree&#x2F;master&#x2F;2020</a><p>The guy created very clean python solutions, and very insigthful walkthrough (although a bit wordy some times). It was my go to repo after validating my solutions on AoC (he managed to publish daily during the whole challenge !).
thundergolfer超过 4 年前
This is another vote of confidence for type annotations. There still seems to be a debate between highly experienced Pythonistas whether typing is good or not.<p>In this case I think they work really well, and aren&#x27;t stuck in places where they&#x27;re not needed.
评论 #25681401 未加载
sundarurfriend超过 4 年前
HTML view of the noteboook, in case Github is failing to load it for anyone else: <a href="http:&#x2F;&#x2F;archive.today&#x2F;Xzyse" rel="nofollow">http:&#x2F;&#x2F;archive.today&#x2F;Xzyse</a> (originally from <a href="https:&#x2F;&#x2F;htmtopdf.herokuapp.com&#x2F;ipynbviewer&#x2F;" rel="nofollow">https:&#x2F;&#x2F;htmtopdf.herokuapp.com&#x2F;ipynbviewer&#x2F;</a> , just didn&#x27;t want to HN hug them).
monksdream超过 4 年前
Probably the most indicative part of Norvig&#x27;s code beauty is the requirements file [0]. With python developers being infamous for importing obscure&#x2F;questionable libraries for even a simple task, I love how Norvig solved all these with just native libraries and the staples numpy&#x2F;plt.<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;norvig&#x2F;pytudes&#x2F;blob&#x2F;master&#x2F;requirements.txt" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;norvig&#x2F;pytudes&#x2F;blob&#x2F;master&#x2F;requirements.t...</a>
评论 #25683394 未加载
raverbashing超过 4 年前
I just find Norvig&#x27;s style of &quot;functional Python&quot; lovely in its own way (with noted disregard of Pep8 and other &quot;best practices&quot;)
ZoomZoomZoom超过 4 年前
It&#x27;s heartwarming to see he skipped d20p2.
评论 #25680828 未加载
dmurray超过 4 年前
I thought I spotted a bug on the very first day, part 2.<p><pre><code> def day1_2(nums): &quot;Find 3 distinct numbers that sum to 2020, and return their product.&quot; return first(x * y * z for x, y in combinations(nums, 2) for z in nums &amp; {2020 - x - y} if x != z != y) </code></pre> The last line (if x != z != y) returns true when x and y are equal and z is different.<p>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.
评论 #25688626 未加载
评论 #25705101 未加载
djaychela超过 4 年前
This was precisely the kind of thing I was looking for. I&#x27;ve done AOC for a few years, and did OK this year (got 2 stars on all but 3 days, and one star on all but 2), but being able to compare my ramshackle, simplistic code to something like this is the project for a month - break down one a day.... I&#x27;ll do this in february, so thanks for posting that, OP!
emmelaich超过 4 年前
&gt; cat = &#x27;&#x27;.join()<p>Love it. There&#x27;s so many bits of Python I&#x27;ve written where I should have had something like this.
评论 #25681822 未加载
评论 #25681993 未加载
avl999超过 4 年前
Day 5 part 1 solution is interesting. I had implemented it the obvious way doing a binary search. I didn&#x27;t realize you could represent that string as binary and get the equivalent integer. That&#x27;s really cool however I am not sure I get the idea behind why that actually works
yeswecatan超过 4 年前
Can someone please explain how `for y in nums &amp; {2020 - x} ` in his day 1 solution?
评论 #25682622 未加载
评论 #25682604 未加载
评论 #25682544 未加载
akho超过 4 年前
The &#x27;timing&#x27; section is disappointing. All very clean though.
johndoe42377超过 4 年前
Norvig&#x27;s code is gold, even back from the times of PAIP (which is still definitely a must read).<p>His &quot;poker&quot; course (on YouTube) is also golden standard.<p>Why? The background in math, basic data structures and logic, so one know the range and boundaries of what is possible. Plus careful attention to details, like it is in any art.
bmitc超过 4 年前
Even as a software engineer who studied mathematics, I just can&#x27;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.<p>Also, I can&#x27;t help but wonder. Why does the Director of Google Research and a computer scientist use his personal time to code, what looks like exclusively, in Python rather than other interesting languages? Is it a bit of marketing for Google and&#x2F;or his book, or does he just like Python?
评论 #25682303 未加载
评论 #25682735 未加载
评论 #25681821 未加载
评论 #25681869 未加载
评论 #25682135 未加载
评论 #25681809 未加载
评论 #25681976 未加载
评论 #25682582 未加载
评论 #25681816 未加载