For the purposes of this challenge, let's define a cyclic number as an integer that passes the basic part of Midy's Theorem, but not necessarily the extended theorem. This means:
the digits in the second half of the
repeating decimal period are[integer is] the 9s complement of the corresponding digits in its first half
In other words,
142857
is a cyclic number because 142 + 857 = 999
and 13358664
is a cylic number because 1335 + 8664 = 9999
.
The Challenge
Given an even-digit integer n > 10, determine whether n is a cyclic number by our definition. If it is, return something truthy. If it's not, return the closest cyclic number to n.
Example:
> 18
True
> 133249
132867
This is code golf, so shortest code wins.
132867
is closer to133249
than133866
is. Are you only considering numbers higher than the original? \$\endgroup\$142857
nor13358664
is a cyclic number because they both "pass" the extended theorem as well as the basic one. \$\endgroup\$