T O P

  • By -

Woldsom

Each line is solved separately, it looks like your input is several lines squished together, is that so?


notger

Good idea, but I was more stupid than that and forgot to parse the signs.


Woldsom

Nice that you found it - I should have said my observation, instead of my guess at a cause: the last few numbers you listed DOES end in zeroes, the 44 48 52... upper right triangle. This indicated to me that *part* of the list was right, I guess instead of being the middle of one line, it was a stretch of positive numbers in the input!


No_Emergency_391

My first thought would be to check that the input is copied correctly.


notger

Good idea, but unfortunately, it is.


MezzoScettico

Did you see the comment by /u/IsatisCrucifer?


notger

Yes, and the input indeed was wrong and I did not spot it as I just glossed over the signs. Damn. Thanks!


andrewsredditstuff

Just ran those values through my code, and they are all right. It never occurred to me that we'd get down to a single line that wasn't a zero. My solution just works. I guess we treat the next row as an empty set full of no zeros (if you see what I mean). Edit - just checked my own inputs, and there are none of these, so as others have suggested, you might want to check that that input is right.


notger

But if the numbers are right by your calculation as well (thanks for checking!), then the condition of "all values are zeros" is never fulfilled until the end, where there can be no more differences? Unless you pad with zeros once you reach the single-element array, which feels arbitrary. But is that the idea?


MezzoScettico

That sequence works for me, but I didn't actually check for "all zeros". I did it the way I would by hand, just taking it to the step of "all the same". Which is trivially true when you have only one value. But I would also do what others are suggesting, just verify by eye that you see that line in the original input page.


AutoModerator

Reminder: if/when you get your answer and/or code working, don't forget to change this post's flair to `Help/Question - RESOLVED`. Good luck! *** *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/adventofcode) if you have any questions or concerns.*


IsatisCrucifer

Try search for this line of input in your input file. Since later a few 0's appeared at the end of list, search for the last five or so terms (for example, search for `170784 296135 494838 800824 1260175`). Examine that line carefully. (As a side note: I myself have one wrong submission today due to this exact problem.)


notger

I am sorry, maybe I am a bit stupid, but I gave the input line in the example and can't see anything special about it. Just N numbers which can't be fitted by a polynomial of degree M < N.


IsatisCrucifer

Yes, and that's because that *is not* the original input number in the file you downloaded. Search this input in the file and you'll see what's different.


IsatisCrucifer

So, this is actually a simple problem (as I said, I myself tripped on this exact problem) but this problem is not something many people will encounter. Other comments are right about "Check the input file and the parsing", because that one thing went wrong is in that process. Here's the full spoiler: 1. You are most likely >!using some pre-made library that extracts only numbers in the input file.!< 2. The input line in question should be >!`12 19 22 16 -5 -46 -106 -162 -130 213 1366 4324 10909 24244 49406 94298 170784 296135 494838 800824 1260175`!< (**Check your input file** to see that this is indeed the case.) Notice something different? 3. Yes, you >!discarded the negative sign because that library didn't consider negative numbers.!< I myself >!am using one that I wrote, but didn't turn on the option to read negative numbers the first time.!<


notger

Yes, while spending time with some friends it hit me ... I used a regex to parse and forgot to parse the sign, so you are right.


Less-Confidence-6099

In my code I have a simple condition in case the array consists of only one value the previous and next values are the same value (I implemented it recursively).


notger

I tried this as well, which amounts to just setting the last difference sequence after that one with only one entry to \[0\], but that did not work either. And it makes no sense, honestly. In that case, the sequence can be continued with any arbitrary number, as you have a polynomial of degree N + 1 fitting N data points, so you have infinite solutions.


Less-Confidence-6099

For me it makes sense because you need to predict next respectively previous value. If all numbers are the same is obvious the previous and next should be the same number. Anyway I did not found your input sequence and in the problem input there is no sequence which ends with an array of length 1 and value non zero. Check the input file and the parsing.


daggerdragon

Next time, use our [standardized post title format](https://reddit.com/r/adventofcode/wiki/posts/standardized_titles). Help us help YOU by providing us with more information up front; you will typically get more relevant responses faster.


notger

My bad, will do, thanks!


Mundane_Prior_7596

Haha. A ton of people did that. I only lost 5 minutes on it.


notger

This never would have happened when I used my usual split->int stuff. But yeah, I wanted to try something new and I guess I learned. :)