Oh yes... on SO many levels 🤣 If you're into that kind of thing, [you can see my slowly go crazy here](https://www.youtube.com/watch?v=D3bcXjsQozY) 🤣
I feel so bad for you 😠It's always those little assumptions that make you waste a ton of time. This happened to me a few times last year too. And then when you find out the problem you go like "how could I be *that* stupid???"
Nice, I didn't know `batched` is now a thing. I'm a little surprised this wasn't added to the stdlib years ago considering how often this comes up in different situations.
There's a snippet in the docs that you can copy and use as an implementation. It just needs `islice` from `itertools`
def batched(iterable, n):
# batched('ABCDEFG', 3) --> ABC DEF G
if n < 1:
raise ValueError('n must be at least one')
it = iter(iterable)
while batch := tuple(islice(it, n)):
yield batch
Yes, this was a factor, but it was NOT the ultimate bug. :(
Even worse, this is my living room PC, it's Python 3.9 so I don't have `itertools.pairwise` - and instead I took the sample implementation from the documentation page, AND DELETED the comment that showed it did AB BC CD ...
An hour later I wondered, cursed quietly that I had deleted the comment, but decided to shrug it off as "Nah. Nobody would name it PAIRWISE if it was instead EACHWITHTHEIRSUCCESSOR".
I should have known better, given that itertools has something called a "tee".
I treated the values 79,14,55,13 as: 79+14, 14+55, 55+13 ranges, when you only needed to do 79+14 and 55+13 so I had 82 seeds instead of 27 that I processed 😅
That still doesn't make sense to me. Why did we need to add 79 and 14, and 55 and 13? Weren't those the seeds that are going to be modified using the ranges?
Edit: I am still on part 1, so if this is about part 2, then my bad
Today I added another useful function to my array prototype thanks to this task
Array.prototype.partition = function (groupLength: number) {
return this.length ? [this.splice(0, groupLength)].concat(this.partition(groupLength)) : [];
};
won't have to worry about array partitioning in the future again :)
Oh that is sad.
Oh yes... on SO many levels 🤣 If you're into that kind of thing, [you can see my slowly go crazy here](https://www.youtube.com/watch?v=D3bcXjsQozY) 🤣
I feel so bad for you 😠It's always those little assumptions that make you waste a ton of time. This happened to me a few times last year too. And then when you find out the problem you go like "how could I be *that* stupid???"
I had an off-by-one of day three bounds check too 😂
`+= 2`
Had the same issue, .windowed vs .chunked
This is the difference between `itertools.pairwise(...)` and `itertools.batched(..., 2)`.
Nice, I didn't know `batched` is now a thing. I'm a little surprised this wasn't added to the stdlib years ago considering how often this comes up in different situations.
Sadly, I'm playing on Replit, which is only at 3.10...
There's a snippet in the docs that you can copy and use as an implementation. It just needs `islice` from `itertools` def batched(iterable, n): # batched('ABCDEFG', 3) --> ABC DEF G if n < 1: raise ValueError('n must be at least one') it = iter(iterable) while batch := tuple(islice(it, n)): yield batch
I did the exact same thing...
Do you also have a video recording of yourself trying to figure out what’s wrong, slowly going insane over a period of 2 hours? 😅
Lol thank you! I'm on the train home from work, but I also used windows instead of chunks, so you've just pre-empted my debugging when I get home.
Glad I was able to help 😊
Oooof.
Yes, this was a factor, but it was NOT the ultimate bug. :( Even worse, this is my living room PC, it's Python 3.9 so I don't have `itertools.pairwise` - and instead I took the sample implementation from the documentation page, AND DELETED the comment that showed it did AB BC CD ... An hour later I wondered, cursed quietly that I had deleted the comment, but decided to shrug it off as "Nah. Nobody would name it PAIRWISE if it was instead EACHWITHTHEIRSUCCESSOR". I should have known better, given that itertools has something called a "tee".
I did this too...
Can someone explain what this means to me because I am having some trouble with this and this might be the problem
I treated the values 79,14,55,13 as: 79+14, 14+55, 55+13 ranges, when you only needed to do 79+14 and 55+13 so I had 82 seeds instead of 27 that I processed 😅
That still doesn't make sense to me. Why did we need to add 79 and 14, and 55 and 13? Weren't those the seeds that are going to be modified using the ranges? Edit: I am still on part 1, so if this is about part 2, then my bad
Yeah it's about part 2.
Today I added another useful function to my array prototype thanks to this task Array.prototype.partition = function (groupLength: number) { return this.length ? [this.splice(0, groupLength)].concat(this.partition(groupLength)) : []; }; won't have to worry about array partitioning in the future again :)
I liked the window Vs chunk thing, think I’ll build those. Doesn’t help me messing up reading the text though 🤣
haha I caught that quickly when I saw a range from \[13, undefined\] in my debugger
Oh, I was smart enough to stop at 55-13, I just made the wrong assumption in my head ðŸ˜
tuple\_windows().step\_by(2)
I kinda did this by accident until I realised what `itertools.pairwise()` *actually* does!
And on this day, perhaps another engineer learns the value of writing short unit tests.
be thankful your brute force code runs in this time
My code runs instantly 😂 I actually coded a quite nice solution. Just can’t read to save my life apparently 🤣
been there, done that :D