Gapful numbers
Some numbers are gapful, some aren't. 100 is gapful because it has at least three digits and 100 is divisible by 10 ((str 1 0)
, the concatenation of the first and last digit). That's the definition of gapful: it has at least three digits and is divisible by the number formed by concatenating the first and last digits.
Create a function that takes a number and finds the closest gapful number. The function should return its argument if the argument itself is gapful. And if there are two gapful numbers equidistant to the argument, return the lower one.
Thanks to this site for the challenge idea!
Yeah, I now see that I keep letting my
gapful?
function. That is debris from when I had misunderstood the problem and thought I wanted to close the divisor in... Here's my latest:I wonder a thing. When I try my
closest-gapful
using something like1024M
, the function never returns. I realise that my implementation isn't really prepared for that kind of input, but I don't understand why it would get stuck in infinity. Someone?