Timeline for "Can a given array be made strictly increasing by removing one number?"
Current License: CC BY-SA 3.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 27, 2017 at 21:42 | comment | added | AJFaraday | @ReedMacConnell I've taken another try, see my newer answer. | |
Mar 27, 2017 at 21:09 | comment | added | AJFaraday | @ReedMacConnell I think I may have misunderstood the requirements. I was looking at occasions when the array decreased, but not the wider context. I'll have a look to see if I can find a satisfying solution. | |
Mar 27, 2017 at 17:13 | comment | added | Lenocam | @AjFaraday I appreciate your input, I've taken a lot from what you've put here. However, the implementations you've suggested don't work for [1,2,1,2], [1, 2, 3, 4, 5, 3, 5, 6], or [40, 50, 60, 10, 20, 30]. | |
Mar 25, 2017 at 17:36 | comment | added | Flambino | Well, I disagree. I'd much rather do that than mess around with explicit indices and block side-effects like incrementing a closed-over counter variable. It literally just says "for every two consecutive elements, count the ones that aren't increasing and compare to the given tolerance" | |
Mar 25, 2017 at 17:33 | comment | added | AJFaraday | Just saying that the one liner isn't particularly easy to understand. | |
Mar 25, 2017 at 17:32 | comment | added | Flambino | Not sure I understand. What might never be read again? | |
Mar 25, 2017 at 17:31 | comment | added | AJFaraday | @flambino perhaps, tho it might never be read again ;) | |
Mar 25, 2017 at 17:30 | comment | added | Flambino |
Doh, don't know why I made such a complicated answer. Your own code can actually be reduced to array.each_cons(2).count { |a, b| a >= b } <= tolerance (if we don't need to return early)
|
|
Mar 25, 2017 at 14:51 | history | answered | AJFaraday | CC BY-SA 3.0 |