It's important to use Sequence here so that the map/filter/count function can happen per item instead of applying to the whole list for each operation.
Here’s my math/logic for n=3 that expands to a general case simply in my mind (if it doesn’t I can work on a more formal proof)
Given:
a<=b<=c
a==b OR b==c
Therefore:
distinct(a,b,c) must be equal to (a,c) OR (a)
aba is never a legal pattern
Explanation of the second therefore: By looking at a 4 digit number that is abca we see that since this implies c<=a<=b that this isn’t a legal string. We can also insert any number of digits (that follow the rules) between b and c and the contradiction with given #1 still occurs.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Kotlin Solution
It's important to use
Sequence
here so that the map/filter/count function can happen per item instead of applying to the whole list for each operation.Something about seeing so many greens <3
Waiting for someone to post a functional/not-very-imperative JS solution!
Where in
part1()
are you checking that 2 adjacent digits are the same?Here’s my math/logic for n=3 that expands to a general case simply in my mind (if it doesn’t I can work on a more formal proof)
Given:
a<=b<=c
a==b
ORb==c
Therefore:
distinct(a,b,c)
must be equal to(a,c)
OR(a)
aba
is never a legal patternExplanation of the second therefore: By looking at a 4 digit number that is
abca
we see that since this impliesc<=a<=b
that this isn’t a legal string. We can also insert any number of digits (that follow the rules) betweenb
andc
and the contradiction with given #1 still occurs.