In a six digit (or larger) number, locate the greatest sequence of five consecutive digits found within the number given.
In the following 10 digit number:
67890 is the greatest sequence of 5 consecutive digits.
This challenge comes from jhoffner on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email email@example.com with your suggestions!
Top comments (8)
🔗 the below code in a runnable playground
unwrapping is safe, because even with
0we will have at least one element
(actually we will consider
bad: leads to dividing bigger numbers
good: can be longer than u64
Here is a Python solution,
To be honest, the solutions I provide here would NEVER pass code review. But I get it working at a REPL, and it's just too tempting to post as-is 😊
Here is a nearly identical solution (sans the transducer), written in a readable way:
Ah, it's just a simple application of a sliding window algorithm.