Palindromic gapful numbers: Difference between revisions

Content deleted Content added
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 + left_half.reverseright_half).to_u64
10.times do
gapfuls << palindrome if palindrome.divisible_by?(dd)
Line 466:
end
else
palindrome = (left_half.rchop + left_half.reverseright_half).to_u64
10.times do
gapfuls << palindrome if palindrome.divisible_by?(dd)
Line 561:
include Enumerable(UInt64)
 
@nndd : Int32
 
def initialize(@digit : Int32)
@nndd = @digit * 11 # digit gapful divisor: 11, 22,...88, 99
end
 
Line 578:
palindrome = (left_half + right_half).to_u64
10.times do
yield palindrome if palindrome.divisible_by?(@nndd)
palindrome += base11
end
Line 584:
palindrome = (left_half.rchop + right_half).to_u64
10.times do
yield palindrome if palindrome.divisible_by?(@nndd)
palindrome += base
end
Line 626:
to_skip = count - keep # count of unwanted values to skip
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 637:
palindrome = (left_half + right_half).to_u64
10.times do
(gapfuls << palindrome if (palcnt += 1) > to_skip) if palindrome.divisible_by?(nndd)
palindrome += base11
end
Line 643:
palindrome = (left_half.rchop + right_half).to_u64
10.times do
(gapfuls << palindrome if (palcnt += 1) > to_skip) if palindrome.divisible_by?(nndd)
palindrome += base
end
Line 685:
to_skip = count - keep # count of unwanted values to skip
gapfuls = [] of UInt64 # array of palindromic gapfuls
nndd, base = (digit * 11).to_u64, 1_u64 # digit gapful divisor: 11, 22,...88, 99
(2..).select do |power|
base *= 10 if power.even? # value of middle digit position: 10..
Line 697:
palindrome = (left_half + right_half).to_u64
10.times do
(gapfuls << palindrome if (palcnt += 1) > to_skip) if palindrome.divisible_by?(nndd)
palindrome += basep
end
Line 738:
include Enumerable(UInt64)
 
@nndd : Int32
 
def initialize(@digit : Int32)
@nndd = @digit * 11 # digit gapful divisor: 11, 22,...88, 99
end
 
Line 755:
palindrome = (left_half + right_half).to_u64
10.times do
yield palindrome if palindrome.divisible_by?(@nndd)
palindrome += base11
end
Line 761:
palindrome = (left_half.rchop + right_half).to_u64
10.times do
yield palindrome if palindrome.divisible_by?(@nndd)
palindrome += base
end
Line 813:
to_skip = count - keep # count of unwanted values to skip
gapfuls = [] of UInt64 # array of palindromic gapfuls
nndd, base = digit * 11, 1_u64 # digit gapful divisor: 11, 22,...88, 99
(2..).select do |power|
base *= 10 if power.even? # value of middle digit position: 10..
Line 823:
palindrome = make_palindrome(front_half, power)
10.times do
(gapfuls << palindrome if (palcnt += 1) > to_skip) if palindrome.divisible_by?(nndd)
palindrome += basep
end
Line 874:
include Enumerable(UInt64)
@nndd : Int32
def initialize(@digit : Int32)
@nndd = @digit * 11 # digit gapful divisor: 11, 22,...88, 99
end
Line 890:
palindrome = make_palindrome(front_half, power)
10.times do
yield palindrome if palindrome.divisible_by?(@nndd)
palindrome += basep
end