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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Advent of Code 2023 is nigh

297 点作者 i13e超过 1 年前

44 条评论

gh123man超过 1 年前
I challenge myself to do it in bash one liners. I came up with a clever and shockingly simple solution to part2 using expansion and substitution.<p><pre><code> cat 1.txt | sed -E &#x27;s&#x2F;(one)&#x2F;\11\1&#x2F;g; s&#x2F;(two)&#x2F;\12\1&#x2F;g; s&#x2F;(three)&#x2F;\13\1&#x2F;g; s&#x2F;(four)&#x2F;\14\1&#x2F;g; s&#x2F;(five)&#x2F;\15\1&#x2F;g; s&#x2F;(six)&#x2F;\16\1&#x2F;g; s&#x2F;(seven)&#x2F;\17\1&#x2F;g; s&#x2F;(eight)&#x2F;\18\1&#x2F;g; s&#x2F;(nine)&#x2F;\19\1&#x2F;g;&#x27; | sed -e &#x27;s&#x2F;[^0-9]&#x2F;&#x2F;g&#x27; | awk &#x27;{print substr($0,1,1) substr($0,length,1)}&#x27; | tr &#x27;\n&#x27; &#x27;+&#x27; | sed &#x27;s&#x2F;\(.*\)+&#x2F;\1\n&#x2F;&#x27; | bc</code></pre>
评论 #38495000 未加载
评论 #38492260 未加载
shever73超过 1 年前
As others have said, part 2 of today&#x27;s was really difficult. I finally solved it using Python regex `overlapped=true`, but it was very tricky. The irritation of having all of the test cases passing, but it failing for my challenge input!<p>I hope it doesn&#x27;t scare off newcomers, but I already know a few who have given up on part 2.
评论 #38489647 未加载
评论 #38489214 未加载
评论 #38489402 未加载
评论 #38488369 未加载
评论 #38489478 未加载
评论 #38493905 未加载
评论 #38490102 未加载
评论 #38489152 未加载
评论 #38488571 未加载
评论 #38496267 未加载
Chobilet超过 1 年前
Without going into spoilers, its interesting that people jumped to regex to solve this. For me that was a fairly non intuitive when I first saw the problem(both parts).<p>What jumped to me is the problem statement indicated a finite number of states and I crafted a solution based on that information. But its really cool to see how we all jump to different implementations.
评论 #38490782 未加载
评论 #38489110 未加载
评论 #38490331 未加载
评论 #38490189 未加载
评论 #38489746 未加载
bradley13超过 1 年前
Seems to me that people made part 2 harder than it us. Just define an array containing the digits: &quot;one&quot;, &quot;two&quot;, and so forth. Then check for substring matches, position by position. Maybe not elegant, but effective.
评论 #38489342 未加载
评论 #38494115 未加载
MandieD超过 1 年前
A bit off-topic, but does anyone know if Hanukkah of Data[0] is happening again this year?<p>[0] <a href="https:&#x2F;&#x2F;hanukkah.bluebird.sh&#x2F;about&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;hanukkah.bluebird.sh&#x2F;about&#x2F;</a>
评论 #38489391 未加载
Foivos超过 1 年前
The main difficulty of part 2 is that there are edge cases that are not covered by the examples. I have appended the example list with some edge cases, so use this list instead:<p>two1nine eightwothree abcone2threexyz xtwone3four 4nineeightseven2 zoneight234 7pqrstsixteen eighthree sevenine oneight xtwone3four three7one7 eightwothree oooneeone eight7eight
评论 #38490538 未加载
63超过 1 年前
Day one part 2 was relatively rough. Things I learned from it: rust regex crate doesn&#x27;t support look-ahead, rust onig crate is currently broken in many ways and shouldn&#x27;t be used (the version in crates.io doesn&#x27;t compile and the version on GitHub is failing tests and look-ahead isn&#x27;t working). It was a very frustrating time for me. After 2 hours of troubleshooting the above I used the same approach in python and it took 2 minutes to write. So annoying.
评论 #38488061 未加载
评论 #38489951 未加载
评论 #38488217 未加载
评论 #38490057 未加载
评论 #38492017 未加载
CobrastanJorji超过 1 年前
Advent of Code means a lot to me. The problems are fun, sure, but something about it really boosts my winter. I&#x27;ve noticed that I get a lot more productive with my hobbies in the weeks following AoC.<p>I think maybe it&#x27;s as simple as living on the west coast and getting used to getting amped and doing some big, adrenaline-filled, social, fun activity at 9 PM every night. It gets me used to being PRODUCTIVE in the evening and not just settling down to watch TV.<p>Anyway, whatever the cause, I care a lot about AoC. It makes my Decembers a whole lot happier.
评论 #38492396 未加载
matjazdrolc超过 1 年前
I ended up using parser combinator library nom. It&#x27;s not something I use daily, therefore parsing became a puzzle on its own.<p>Nom already has a parser for numbers. However, I didn&#x27;t find an elegant way to take at most one digit. In the end I used take_while_m_n, and mapped it with u64::from_str().<p>Another challenge was absence of something such as find_all, that would repeatedly try to parse beginning from each character and then return all matches. I ended up writing my own combinator.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;drola&#x2F;AdventOfCode2023&#x2F;blob&#x2F;main&#x2F;src&#x2F;bin&#x2F;day_01_trebuchet.rs#L37">https:&#x2F;&#x2F;github.com&#x2F;drola&#x2F;AdventOfCode2023&#x2F;blob&#x2F;main&#x2F;src&#x2F;bin&#x2F;...</a>
评论 #38491087 未加载
评论 #38497478 未加载
aaaronic超过 1 年前
I think the edge cases were entirely unclear in day 1, part 2. I had to redo it in a &quot;dumb&quot;&#x2F;brute-force way to avoid using fancy regex tricks I don&#x27;t know.<p>It&#x27;s quite clear the small sample data was chosen intentionally to not cover them.
评论 #38490021 未加载
评论 #38489394 未加载
评论 #38492366 未加载
评论 #38496794 未加载
dataengineer56超过 1 年前
It&#x27;s a tough day 1, I hope it doesn&#x27;t scare off too many people. Normally day 1 is just some variation of &quot;add numbers in a list&quot;, but this year has a mean pt 2 and a few traps for people to fall into.<p>I wonder how long the global leaderboard will stay up before it gets hidden due to people solving with ChatGPT?
评论 #38488868 未加载
评论 #38486519 未加载
评论 #38490785 未加载
评论 #38486471 未加载
kif超过 1 年前
I don&#x27;t know if I&#x27;ll even bother this year. Their puzzles start feeling like chores by the 10th problem or so and I drop out. Maybe I&#x27;ll learn a new language to spice it up this year.
评论 #38489502 未加载
评论 #38490272 未加载
评论 #38490635 未加载
评论 #38491838 未加载
评论 #38507539 未加载
mikewarot超过 1 年前
In times past, it was Pascal that was my language of choice[1]. This year, I&#x27;m going to use a <i>virtual</i> BitGrid[2]. Here&#x27;s the repo[3] Hopefully I can finish the 2023 problems before next November, I have nothing but the simulator. Nothing to convert text to code, do I&#x2F;O, etc.<p>Oh boy.... Day 1 A... and I have to figure out how to feed text into a bitgrid, and get it out the other side... before I can even think about parsing it, making integers, and adding them, then converting back to text.<p>BitGrid - a sea of LUTs with latches, completely parallel down to the bit processing. Each LUT has 4 bits of input, and 4 independent bits out to each cardinal direction. Clocking in 2 phases, like colors on a chess board, to eliminate undefined behavior or timing issues.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;mikewarot&#x2F;Advent_of_Code_in_Pascal">https:&#x2F;&#x2F;github.com&#x2F;mikewarot&#x2F;Advent_of_Code_in_Pascal</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;mikewarot&#x2F;Bitgrid">https:&#x2F;&#x2F;github.com&#x2F;mikewarot&#x2F;Bitgrid</a><p>[3] <a href="https:&#x2F;&#x2F;github.com&#x2F;mikewarot&#x2F;Advent_of_Code_in_BitGrid">https:&#x2F;&#x2F;github.com&#x2F;mikewarot&#x2F;Advent_of_Code_in_BitGrid</a>
Waterluvian超过 1 年前
Every year I want to love this. Every year I get four days in before it feels like work.<p>I think I’m just the wrong audience, but I really do want something this well-produced but with perhaps a very shallow diff little curve, bordering on just effortless fun.
评论 #38487281 未加载
评论 #38489189 未加载
评论 #38488333 未加载
评论 #38490790 未加载
kristaps超过 1 年前
Last year there were people solving the puzzles with LLMs, but I don&#x27;t think I saw anyone get past day 5 or so.<p>I&#x27;m interested in how well it goes this year.<p>Please reply if you are trying yourself or can link to public attempts by others
评论 #38489145 未加载
评论 #38488785 未加载
评论 #38490181 未加载
ttrrooppeerr超过 1 年前
I will be doing this advent challenge this year instead: <a href="https:&#x2F;&#x2F;adventofchess.com&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;adventofchess.com&#x2F;</a><p>Looking forward to read your write-ups!
评论 #38489988 未加载
评论 #38487686 未加载
评论 #38488201 未加载
评论 #38488528 未加载
bryancoxwell超过 1 年前
I think I’d like to try this year’s in a language I haven’t touched before. What languages should I consider if I want something paradigmatically different from Go, Python, etc?
评论 #38487398 未加载
评论 #38487741 未加载
评论 #38486971 未加载
评论 #38489564 未加载
评论 #38487160 未加载
评论 #38487057 未加载
评论 #38488269 未加载
评论 #38486844 未加载
评论 #38488687 未加载
评论 #38490660 未加载
评论 #38491461 未加载
评论 #38486843 未加载
评论 #38486906 未加载
评论 #38486854 未加载
评论 #38487657 未加载
评论 #38488336 未加载
评论 #38487014 未加载
评论 #38487793 未加载
ni507超过 1 年前
As every year, I stumbled upon the Advent of Code, but this year was a bit different as I found a way to solve the puzzle using our API client. The other years I got demotivated very quickly as I had to create some I&#x2F;O functions, copy the files, etc. So I came up with the idea to solve it using Kreya&#x27;s scripting feature and it was a joy. Created a blog post [1] as maybe other people feel the same way :)<p>[1] <a href="https:&#x2F;&#x2F;kreya.app&#x2F;blog&#x2F;solving-advent-of-code-with-kreya&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;kreya.app&#x2F;blog&#x2F;solving-advent-of-code-with-kreya&#x2F;</a>
greymalik超过 1 年前
I&#x27;ve never done AoC before. It seems like the success criteria is primarily about getting the correct answer, and secondarily about submitting a solution as quickly as possible if you want to be on the leaderboard. Is that right?<p>Is there any centralized place for seeing other people&#x27;s solutions? I&#x27;d like to be able to learn from how others approach the problem, and what more elegant or performant solutions exist than the one I came up with.
评论 #38487183 未加载
评论 #38490355 未加载
评论 #38487202 未加载
评论 #38490825 未加载
评论 #38489545 未加载
anonyfox超过 1 年前
This year might be the gpt4 speedrun mode.<p>I still prefer to do it manually since casually tackling it is a great way to learn a new language or refresh past knowledge!
评论 #38486523 未加载
评论 #38486469 未加载
评论 #38486453 未加载
codr7超过 1 年前
Most solutions I see are just blobs of code, which makes me wonder what their process looks like.<p>I like to solve these kinds of problems in Lisp, which means I&#x27;m working in a REPL and dividing and conquering the problem to be able to test one piece of the solution at a time.<p>The result is that my code tends to be mainly independent functions that I finally string together to solve the problem.
评论 #38497689 未加载
评论 #38493594 未加载
laweijfmvo超过 1 年前
&gt; failed to authenticate. (access_token request returned 429 Too Many Requests)<p>Hope it&#x27;s just a temporary issue!
评论 #38490180 未加载
评论 #38489858 未加载
calibas超过 1 年前
Part 2 seemed fairly easy until I noticed &quot;twone&quot;.<p>I used Rust and <i>match_indices</i> to get the answer.
deafpolygon超过 1 年前
I solved the 2nd part pretty neatly in javascript today... I&#x27;m not a great programmer by any stretch but, maybe someone can take a peek and tell me what I can improve? This is my first time with JS-- I dislike the idea of it, but I know I should program in it before I write it off.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;deafpolygon&#x2F;advent-of-code&#x2F;blob&#x2F;main&#x2F;2023&#x2F;day01&#x2F;index.js">https:&#x2F;&#x2F;github.com&#x2F;deafpolygon&#x2F;advent-of-code&#x2F;blob&#x2F;main&#x2F;2023...</a>
rrishi超过 1 年前
Genuinely curios why people are so into AoC ... Feels leetcode-y
评论 #38488085 未加载
评论 #38488009 未加载
评论 #38488533 未加载
评论 #38488007 未加载
评论 #38488462 未加载
评论 #38488038 未加载
评论 #38488346 未加载
评论 #38488257 未加载
评论 #38493359 未加载
评论 #38489310 未加载
评论 #38490924 未加载
Tainnor超过 1 年前
Day 1 part 2 was harder than is common for the first day. I ended up using parser combinators (attoparsec for Haskell), which morally feels like the &quot;right&quot; way to do this (so you don&#x27;t have to manually keep track of how much you&#x27;ve read or somehow abuse regex lookaheads), but I don&#x27;t know the library well and it took me some time to implement it correctly.
subset超过 1 年前
First time trying a code golf solution, managed to do Part 2 in 231 characters.<p><pre><code> p=&quot;one two three four five six seven eight nine&quot;.split();sum(int(x[0]+x[-1])for x in[&quot;&quot;.join([[&quot;&quot;,s[0]][s[0].isdigit()],str(p.index(w)+1)][s.startswith(w)]for s in[l[i:]for i in range(len(l))]for w in p)for l in open(&quot;input.txt&quot;)])</code></pre>
ohnoerik超过 1 年前
I&#x27;m going to see how far I can go with Terraform this year. Part 1 was fine, but Part 2 was a bit challenging at first.
评论 #38497188 未加载
AdamH12113超过 1 年前
Advice from 7 years of doing (and sometimes completing!) the Advent of Code:<p>1. Look at the example input.<p>2. Run your code on the example input.<p>3. Seriously -- make extra super 100% sure your code works on the example input. Write some boilerplate code to make it easy to switch between your input and the example input.<p>4. Think about possible edge cases in the input -- there will probably be some. Looking at your input in a text editor can help uncover them.<p>5. If part 1 is simple, it&#x27;s just there to test your input processing, and part 2 will be the real puzzle.<p>6. If part 1 is solvable with brute force, part 2 probably won&#x27;t be. But sometimes it&#x27;s helpful to brute-force part 1 just to see what the question is.<p>7. Many problems that involve the word &quot;shortest&quot; or &quot;fastest&quot; are good candidates for a breadth-first search. Make sure you know how to do that.<p>8. Test your code as you go. Printing the output of intermediate steps to the console is a great way of catching bugs.<p>9. There&#x27;s going to be some hideous puzzle, probably involving a maze, which is too hard for a simple BFS and requires heavy pruning of alternatives. If you know how to do this kind of puzzle, please tell me how; they get me every time. :-(<p>10. Don&#x27;t even look at the leaderboard times. Those people are nuts.
评论 #38489401 未加载
评论 #38489318 未加载
imperialdrive超过 1 年前
Gosh I&#x27;m feeling extra special this morning as an absolute infant beginner tinkerer that figured solution in powershell to part II after a few minutes of closing my eyes, but I highly doubt I&#x27;ll be able to say that about the next one if they get harder. The example was so excellently written though, which helped a ton.
artzmeister超过 1 年前
common lispers unite
评论 #38488708 未加载
usgroup超过 1 年前
A Prolog Definite Clause Grammar (DCG) solution:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;emiruz&#x2F;adventofcode2023&#x2F;blob&#x2F;main&#x2F;day01&#x2F;part2.prolog">https:&#x2F;&#x2F;github.com&#x2F;emiruz&#x2F;adventofcode2023&#x2F;blob&#x2F;main&#x2F;day01&#x2F;p...</a>
cannabis_sam超过 1 年前
Man, this feels like a frustratingly good way to get back into Haskell, and on the cutting edge of GHC to boot…<p>Or should I take the plunge and do it in rust?<p>(If only I was unemployed and could do this in agda&#x2F;idris&#x2F;lean…)
评论 #38545400 未加载
NooneAtAll3超过 1 年前
my screen isn&#x27;t big enough vertically - on default zoom place for first several days gets hidden below the bottom<p>was so strange to see absolutely empty page until I thought of scrolling down
gyosko超过 1 年前
Always relevant: <a href="https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;adventofcode&#x2F;comments&#x2F;zjwovn&#x2F;so_youre_trying_to_get_onto_the_leaderboard_huh&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;adventofcode&#x2F;comments&#x2F;zjwovn&#x2F;so_you...</a>
drewcoo超过 1 年前
&quot;Nigh&quot; is off by at least one, depending when this is all read.
评论 #38499650 未加载
w0m超过 1 年前
yay
berkes超过 1 年前
Part two was exceptionally hard.<p>Many people on reddit reporting they were hit by one edge case that&#x27;s not covered in the examples. But my implementation passed these edge cases too. I was hit by another edge case. So there are at least two edge-cases (which are in the actual data) that aren&#x27;t covered in the examples or the description.
评论 #38486978 未加载
评论 #38487054 未加载
评论 #38486914 未加载
评论 #38488335 未加载
评论 #38488357 未加载
评论 #38487025 未加载
评论 #38487647 未加载
评论 #38486823 未加载
评论 #38488073 未加载
zehaeva超过 1 年前
Another year and another Advent of Code that I don&#x27;t have enough time in my life to do.<p>One year I&#x27;ll actually finish!
评论 #38486870 未加载
评论 #38488081 未加载
brightball超过 1 年前
Shameless Plug: If anybody is doing Advent of Code and wants to win tickets to the 2024 Carolina Code Conference (Greenville, SC in August) we&#x27;re doing a ticket challenge. 22 tickets up for grabs with lots of ways to win. Entry details here.<p><a href="https:&#x2F;&#x2F;blog.carolina.codes&#x2F;p&#x2F;advent-of-carolina-code-ticket-challenge" rel="nofollow noreferrer">https:&#x2F;&#x2F;blog.carolina.codes&#x2F;p&#x2F;advent-of-carolina-code-ticket...</a>
评论 #38488113 未加载
rschiavone超过 1 年前
Opening up a tab to quickly solve the problem with ChatGPT in order to climb the leaderboard is the modern Tragedy of the Commons.
评论 #38486711 未加载
评论 #38486603 未加载
评论 #38488091 未加载
sertbdfgbnfgsd超过 1 年前
Maybe I&#x27;m too stupid for this<p>&gt; Consider your entire calibration document. What is the sum of all of the calibration values?<p>Where is the document? Where do I download it?
评论 #38489073 未加载
nikolay超过 1 年前
Python should be excluded! I force myself to use Go, but it&#x27;s just not competitive.
评论 #38490873 未加载
stiray超过 1 年前
I am looking at advent of code for years but never tried.<p>Why? As they would like to force you to login with GitHub, Google, Twitter or Reddit account.<p>I will wait for the next year, maybe 2024 Advent of Code will be less intrusive.<p>If not... I can live without it.<p>A hint to the authors for simple load&#x2F;save, far simpler than what you have now, without use of intrusive 3rd party providers: use Digest::SHA qw(hmac_sha256_hex); $digest=hmac_sha256_hex(&quot;levelX:true,...&quot;, $key);<p>(And no, I wont workaround them. This is why we got into such situation - as we were still using intrusive services instead boycotting them, it is matter of principle not of technical workaround)
评论 #38486627 未加载
评论 #38486611 未加载
评论 #38486835 未加载
评论 #38486657 未加载
评论 #38486566 未加载
评论 #38489081 未加载
评论 #38486622 未加载
评论 #38486855 未加载