4 ms·
Regardless of how it found it, or what it was basing it on, puzzle two is missing the key "aha" with such a sliding window type of problem. Which is that two o
by lostcolony 5y ago
Regardless of how it found it, or what it was basing it on, puzzle two is missing the key "aha" with such a sliding window type of problem.
Which is that two of the values are the same in both windows you're comparing; you don't actually need to sum anything, just compare the unique values from each (i-3 and i, respectively).
If Copilot is trained on a corpus of average devs...I do worry about what this says about the state of our field.
- wk_end 5y agoMeh. The problem is so small and simple and straightforward, you don't need any clever "aha" moment. If anything, being clever just makes the code slightly less obvious, because the reader needs to get that "aha" moment too. ...and my solution did actually do things the way you described, so I'm not just being defensive about it :P
- alexfoo 5y agoThese types of puzzles can help educate people as to how things might need to be coded to work in more "real world" situations. At my previous job we used them as the basis for discussion and education amongst the team (hoping to do something similar at current company). For example, taking 2021_day1, the naive solution that reads in all of the values and then iterates through calculating and comparing sums is all well and good, it satisfies the end goal of producing a solution. What if you had 1,000,000,000 values in the input? * A program that reads in and stores all of the values before iterating through them now consumes a non-insignificant amount of memory. What if you had to check the differences between the sums of 100,000 consecutive terms? * A program that calculates and compares the sums (rather than just comparing the two non-common terms) will be doing a lot more unnecessary computation. What if you had to take a seemingly endless input stream and report the running totals at 1,000,000 iteration intervals? * A program that reads all of the input before iterating through it is now unsuitable. ..etc.. Programming is not just about getting the answer, it's knowing where you can do the bare minimum to do that, and knowing under what conditions your bare minimum solution will become impractical and what you would have to do to avoid this. There's nothing stopping people using AoC as a toy to collect all of the stars (surprisingly few people have all 304 stars, it was under 700 last time Eric answered that question in July 2021). But it can also be used for a lot more than that.
- piaste 5y agoI agree with the general principle of naive vs. specialized solution. Using AoC day 1 is probably not a good example of it however, because a lot of modern languages offer streaming iterators, so the naive, declarative solution will still not need to load all the values into memory at once.
- deleted 5y ago[deleted]
- lostcolony 5y agoI'm not sure what streaming iterators have to do with it; the thing I noted was simply that you only need two values at a time. How you get to them from the input is kinda immaterial; the observation is that you can create a more generalized solution (that will be efficient no matter the size of the input, and no matter the size of the window). In fact, if the windows are only offset by one, you don't even need to do any math. It becomes a trivial two pointer problem. Even with a streaming iterator, you're summing up values (either a lot of unnecessary summations across the entire window, or you're adding/subtracting individual values off, which is one step away from realizing the thing being subtracted, and the thing being added, are the only relevant inputs per iteration). More broadly, it's a neat observation that you can determine the direction of a rolling sum without actually maintaining a sum. And certainly, you can do it without recalculating the sum(s) at every step.
- mrtranscendence 5y agoIt may be a neat observation, but you're not pushed in any way to recognize it so I struggle to see how it could be the point of the exercise. It's so dead simple to just code it up naively in thirty seconds that unless you notice the trick right off the bat (or already know it), no one's going to think twice that there might be a more efficient or clever solution.
- lostcolony 5y ago>> so I struggle to see how it could be the point of the exercise I think you make a mistake in assuming "the" point, as in, singular. From Advent of Code's own website - 'People use them as a speed contest, interview prep, company training, university coursework, practice problems, or to challenge each other.' We also have seen people use them as an excuse to start doing something in a new language, and, per this post, to play with Github Copilot and understand what it's doing. So...it's really what you want to make of it. -My- point was simply that if there's an ML model trained with all sorts of approaches devs use to solve sliding window style problems, and it manages to solve the problem but still misses such a generally useful optimization, it does call into question what it was trained on.
- seba_dos1 5y agoWhen you try to write this kind of thing quickly, it's hard to beat something like `sum(lines[i:i+3]) > sum(lines[i-1:i+2])`. You get points for time of submission, not for the code.
- MauranKilom 5y agoIf you just imagine the sums written out, you can see the trick faster than you could type anything involving: lines[i+1] + lines[i+2] + lines[i+3] > lines[i] + lines[i+1] + lines[i+2] It's a single mental step to eliminate `lines[i+1]` and `lines[i+2]` on both sides, arriving at `lines[i+3] > lines[i]`.
- seba_dos1 5y ago...but why would I write anything like that (or even imagine it) when I could just write the thing I wrote above? :) It directly encodes what the puzzle is asking for, so you don't even have to stop and think about it. Of course it can be logically simplified, but if you want to be relevant in the leaderboard you need to act in a matter of single seconds. The whole puzzle can be solved in just two lines of Python, but I certainly wouldn't come up with that in 1min it took the person that solved it first, since I had to take a step back and notice quite a few things (even if they're ultimately rather simple observations) to come down to such concise solution.
- lostcolony 5y ago>> ...but why would I write anything like that (or even imagine it) Because in the example explaining the steps, it shows you that? I.e., 'The measurements in the first window are marked A (199, 200, 208); their sum is 199 + 200 + 208 = 607. The second window is marked B (200, 208, 210); its sum is 618'; even how the text is aligned on the page, the 200 and 208 are almost directly above/below each other. Sure, yes, if your goal is just to solve it as quickly as possible for the internet points, by all means do the naive thing. But if you already "had to take a step back and notice a few things to come down to such (a) concise solution", it seems like maybe solving it as quickly as possible wasn't your goal.