22
3
A pleasing number (according to this definition) is a number that can be passed through the following process (let's use 41802000
as an example):
- Separate the trailing identical numbers (
41802000 => [41802, 000]
) - Sort the first half of the digits and take the maximum (
[41802, 000] => [8, 000]
) - Take the length of the final element. Call the resultant elements A and B (
[8, 000] => A=8, B=3
) - Is NB = A for any integer
N
? (True
in this example; 23 = 8)
If the input results in True
from the following process, it is considered pleasing.
Your task is to take an integer x
, and output whether x
is a pleasing number. You can output any two distinct values for truthy and falsey, but please state what you're using in your answer. x
is guaranteed to have at least two distinct digits (e.g. 111
is an invalid input). As with most challenges, you may take x
as a string, or a list of digits.
This is a code-golf so shortest code in bytes wins.
Test cases
Input Output
41802000 1
100 1
123456788 0
451111111 0
234543454545444 0
12 1
41902000 0
92599 1
can the number be passed as a string? (especially given the '234543454545444' test case) – Uriel – 2017-12-17T21:08:33.133
@Uriel You may take input as a string – caird coinheringaahing – 2017-12-17T21:10:09.577
3As a suggestion for clarification: I would use the term "digit" rather than "number", as you are specifically referring to the decimal characters, abstracted from their number values. – Jonathan Frech – 2017-12-17T22:43:16.250
list of digits
- would this be a list of the ASCII numeral characters, or a list of integers from 0-9 – Οurous – 2017-12-17T23:05:42.2931@Οurous Up to you – caird coinheringaahing – 2017-12-17T23:08:12.340
Would 1 be considered a pleasing number? (01) 0 is 0^1. – fəˈnɛtɪk – 2017-12-18T00:40:17.880
@fəˈnɛtɪk - does not matter since "
x
is guaranteed to have at least two distinct digits" (although I see your "01" reasoning) – Jonathan Allan – 2017-12-18T00:44:30.697@DLosc Added, Thanks! – caird coinheringaahing – 2018-04-04T07:09:45.817