Jump to content

Palindromic gapful numbers: Difference between revisions

Line 450:
<lang ruby>def palindromicgapfuls(digit, count)
gapfuls = [] of UInt64 # array of palindromic gapfuls
nndd = digit * 11 # digit gapful divisor: 11, 22,...88, 99
(2..).select do |power|
base = 10_u64**(power >> 1) # value of middle digit position: 10..
Line 457:
next_lo = base * (digit + 1) # starting half for next digit: 20.. to 100..
this_lo.step(to: next_lo - 1, by: 10) do |front_half| # d_00; d_10; d_20; ...
left_half = front_half.to_s; right_half = left_half.reverse
if power.odd?
palindrome = (left_half + right_halfleft_half.reverse).to_u64
10.times do
gapfuls << palindrome if palindrome.divisible_by?(nndd)
return gapfuls if gapfuls.size == count
palindrome += base11
end
else
palindrome = (left_half.rchop + right_halfleft_half.reverse).to_u64
10.times do
gapfuls << palindrome if palindrome.divisible_by?(nndd)
return gapfuls if gapfuls.size == count
palindrome += base
Line 508:
<lang ruby>def palindromicgapfuls(digit, count)
gapfuls = [] of UInt64 # array of palindromic gapfuls
nndd = digit * 11 # digit gapful divisor: 11, 22,...88, 99
(2..).select do |power|
base = 10_u64**(power >> 1) # value of middle digit position: 10..
Line 520:
palindrome = (left_half + right_half).to_u64
10.times do
gapfuls << palindrome if palindrome.divisible_by?(nndd)
return gapfuls if gapfuls.size == count
palindrome += basep
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.