Recently, my reputation was 25,121
. I noticed that each digit grouping (i.e. the numbers separated by commas) was a perfect square.
Your challenge is, given a non-negative integer N and a unary boolean Black Box Function f : Z* → B , yield a truthy value if each value of f applied to the digit groupings of N is truthy, and falsey otherwise.
One can find the digit groupings by splitting the number into groups of 3, starting from the right side. The leftmost group may have 1, 2, or 3 digits. Some examples:
12398123 -> 12,398,123 (3 digit groupings)
10 -> 10 (1 digit grouping)
23045 -> 23,045 (2 digit groupings)
100000001 -> 100,000,001 (3 digit groupings)
1337 -> 1,337 (2 digit groupings)
0 -> 0 (1 digit grouping)
Additional rules
- This function can map to either booleans (e.g.
true
andfalse
),1
s and0
s, or any truthy/falsey value. Please specify which format(s) are supported by your answer. - You may take an integer as input, or an integer string (i.e. a string composed of digits).
- You may write a program or a function.
- When passing the digital groups to the function f, you should trim all unnecessary leading zeroes. E.g., f, when applied to N = 123,000 should be executed as f(123) and f(0).
Test cases
Function notation is n -> f(n)
, e.g., n -> n == 0
. All operators assume integer arithmetic. (E.g., sqrt(3) == 1
)
function f
integer N
boolean result
n -> n == n
1230192
true
n -> n != n
42
false
n -> n > 400
420000
false
n -> n > 0
0
false
n -> n -> 0
1
true
n -> sqrt(n) ** 2 == n
25121
true
n -> sqrt(n) ** 2 == n
4101
false
n -> mod(n, 2) == 0
2902414
true
n -> n % 10 > max(digits(n / 10))
10239120
false
n -> n % 10 > max(digits(n / 10))
123456789
true
n -> n > 0
applied to0
) to the test cases because most answers fail on it. \$\endgroup\$[0]
. \$\endgroup\$