Palindromic gapful numbers: Difference between revisions

m
(→‎{{header|AppleScript}}: Added translation of Phix "Ludicrously fast …" version.)
m (→‎{{header|Wren}}: Minor tidy)
 
(23 intermediate revisions by 8 users not shown)
Line 57:
=={{header|AppleScript}}==
 
<langsyntaxhighlight lang="applescript">on doTask()
set part1 to {"First 20 palindromic gapful numbers > 100 ending with each digit from 1 to 9:"}
set part2 to {"86th to 100th such:"}
Line 141:
end intText
 
return doTask()</langsyntaxhighlight>
 
{{output}}
Line 178:
 
===Translation of Phix "Ludicrously fast …"===
See [https://www.rosettacode.org/wiki/Palindromic_gapful_numbers#Ludicrously_fast_to_10.2C000.2C000.2C000.2C000.2C000.2C000th the original's] comments for an explanation of the logic. While this AppleScripttranslation version iswas developed directly from the originalPhix, comparing the two may be difficult as I've pulled things around a bit for AppleScript efficiency and have relabelled some of the variables for consistency and to tryhelp tome understand the workingsprocess myself!. ForOn the setmy taskmachine, it'sthis notversion actuallytakes as0.12 fast as the script above, which doesn't have the overhead of being ableseconds to handlecarry ridiculously large numbers and which getsout the threeset setstasks of results for each digit inonly a singletad sweep ratherslower than starting at the beginninghard-wired forscript each setabove. It'sThe alsobatch notof nearlyextreme astests fast asin the Phix originaldemo apparentlytakes is,around taking about twelve1.6 seconds to complete the same tests. But that's still not bad. Like the original, it's constrained not by the resolution of the results it can return, but by how many of them it can count using native number classes.
 
<syntaxhighlight lang ="applescript">use-- AppleScriptReturn version "2.4" --a Macscript OSobject 10.10containing (Yosemite)the ormain laterhandlers.
-- It could be loaded as a library instead if there were any point in having such a library.
 
-- Return a script object containing the main handlers.
-- One could instead load it as a library if there were any point in keeping it as such.
on getWorks()
script theWorks
useproperty frameworkouterX11 "Foundation": missing value
property countLimit : missing value
property searchLimit : missing value
property to_skip : missing value
property palcount : missing value
property skipd : {{}, {}, {}, {}, {}, {}, {}, {}, {}}
property outputskipdOuter : {}missing -- Output list.value
property pals : missing value
-- Work out the remainder whenfrom the decimaldivision numberof formedthe frompositive onedecimal orinteger two instances of thevalue digitwhich 'digit'is
-- one or two instances of digit 'digit' separated by 'gap' zeros and followed by 'shift' zeros is divided by 'dd', a two-digit multiple of 11. :)
-- (which may not be realisable as an AppleScript number) by 'outerX11', a multiple of 11.
on rmdr(digit, gap, shift, dd)
on rmdr(digit, gap, shift)
-- The Phix original caches remainders for fast access later. But those after the first three in each innermost
-- Remainders from the division of left-shifted decimals by multiples of 11 reliably repeat
-- cache list are simply repeating sequences of the same two, three, or six numbers. So in fact a usably low
-- dividendevery cansix beplaces quicklyshifted derived> for2, /any/so combinationuse ofa digitdividend shiftswith fromthe equivalent digit shifts < 10 without9.
set coefficient to 10 ^ ((shift - 3) mod 6 + 3)
-- the need for a cache at all. The execution time in AppleScript is about the same. /Possibly/ a tad less.
if (digitgap is> 0-1) then returnset digitcoefficient to coefficient + 10 ^ ((gap + shift - 2) mod 6 + 3)
set v to digit * (10 ^ ((shift - 3) mod 6 + 3))
if (gap > -1) then set v to v + digit * (10 ^ ((gap + shift - 2) mod 6 + 3))
return (vdigit * coefficient mod ddouterX11) as integer
end rmdr
-- Recursively constructinfer palindromicfrom gapfulremainder numbersarithmetic andany storepalindromic asgapful text those which fall within the requirednumbers range.with
-- ((count lhs) * 2 + gap) digits whose outer digit is the first value in lhs.
-- Append text versions of any falling in the current keep range to the 'pals' list.
on palindromicGapfuls(lhs, gap, remainder)
-- lhs: eg {9, 4, 5} of a potential 9459549945…549 result. (Text eg. "945" in the original.)
-- gap: length of inner to be filled in
-- remainder: remainder of outer, eg 9400049 mod 11, but derived from rmdr() results.
set shift to (count lhs) -- left shift of inner (shouldsame alwaysas equalits length(lhsright shift),. I think)
-- This translation's 'skipd' is a four-deep AppleScript list structure indexed with the elements
set outer to beginning of lhs -- outermost 1..9
-- Inof the original Phix, dictionary's keys: (skipd') is-> aoutermost dictionarydigit with-> shift four-element> keysgap -> remainder (+ 1).
-- Here,The tooutermost easedigit theelement congestiondoesn't inchange AppleScript/ASObjC, it'sduring a listsearch ofbased 99on it, so the muchscript smallerproperty
-- 'skipdOuter' has been preset to skipd's outer-th sublist in the set-up for the current search.
-- dictionaries with three-element keys. The axed element, a remainder in the range
-- 0Populate -it 98,just isenough usedhere insteadto withensure 1that addedthe toslot itabout to indexbe thechecked for a 'skip' value listexists.
repeat (shift - (count my skipdOuter)) times
-- I must admit I'm still not entirely clear how the dictionaries' contents affect
-- the process. The set taskend completesof moremy quicklyskipdOuter withoutto them, but they{}
end repeat
-- do speed things up once the numbers start getting ludicrously high.
setrepeat |key|(gap to- {gap,(count item shift, outer}of my skipdOuter)) times
set skip to (item (remainderset +end 1)of item shift of my skipd)'sskipdOuter to objectForKey:(|key|){}
ifend (skip is missing value) thenrepeat
repeat (remainder + 1 -- Key not in dictionary.(count Engineeritem agap highof additionitem resultshift inof themy nextskipdOuter)) test.times
set skipend of item gap of item shift of my skipdOuter to searchLimitmissing value
elseend repeat
set skip to item (skipremainder as+ real1) divof 1item gap of item shift of my skipdOuter
if ((skip is missing value) or (palcount + skip > to_skip)) then
end if
if (palcount + skip > to_skip) then -- (Also when equal in the original.)
set skip to 0
set lhs_shl to lhs & missing value & reverse of lhs -- Palindrome template list.
set mid to shift + 1 -- Index of its middle position.
set nextGap to gap - 2
set outerX11 to outer * 11
repeat with d from 0 to 9
set nextRem to (remainder + rmdr(d, nextGap, shift, outerX11)) mod outerX11
if (gap > 2) then
set skip to skip + palindromicGapfuls(lhs & d, nextGap, nextRem)
else if (nextRem is 0) then
-- A palindrome of lhs's contents around gap ds would be … gapful.
set palcount to palcount + 1
if (palcount > to_skip) then
if-- (gapThis isone 2)would thenbe in the current keep range, so realise it as text and store it.
if (gap is 2) then set item mid of lhs_shld to {d, d} -- Not d * 11. (as d maycould be 0.)
elseset --end ifof my pals to (gaplhs is& 1d & reverse of lhs) thenas text
set item mid of lhs_shl to d
-- else if (gap is 0) then
-- set item mid of lhs_shl to ""
-- else
-- set lhs_shl to d
end if
set end of my output to lhs_shl as text
else
set skip to skip + 1
end if
end if
if (palcount = searchLimitcountLimit) then exit repeat
end repeat
if (palcount < to_skip) then (set item (remainder + 1) of item gap of item shift of my skipd)'sskipdOuter setObject:(skip)to forKey:(|key|)skip
else
set palcount to palcount + skip
Line 267 ⟶ 255:
end palindromicGapfuls
-- ReturnSet up a listsearch of numeric texts representingfor the last 'keep' of the first 'countLimit' PGNs > 100 whose outer digit is 'outer',
-- call the recursive process for each palindrome width, and eventually return the stored numeric texts.
-- 'searchLimit' palindromic gapful numbers > 100 whose outer digit is 'digit'.
on collect(digitouter, searchLimitcountLimit, keep)
-- Set thisInitialise script object's properties for the current batchsearch.
set my searchLimitouterX11 to searchLimitouter * 11
set to_skipmy countLimit to searchLimit - keepcountLimit
set to_skip to countLimit - keep
set palcount to 0
set outputskipdOuter to {}item outer of my skipd
--set Locals.pals to {}
set-- lhsAlso tolocals {digit}and TIDs.
set gaplhs to 1{outer}
set shiftgap to 01 -- Number of digits between outer pair.
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "" -- For list-to-text coercions.
repeat until (palcount = searchLimitcountLimit)
set remainder to rmdr(digitouter, gap, shift, digit * 110)
palindromicGapfuls(lhs, gap, remainder)
set gap to gap + 1
Line 288 ⟶ 277:
set AppleScript's text item delimiters to astid
return outputpals
end collect
on initialise()
repeat 99 times
set end of my skipd to current application's class "NSMutableDictionary"'s new()
end repeat
end initialise
end script
return theWorks
end getWorks
 
(* Test code *)
 
-- Return an integer as text with the appropriate English ordinal suffix
on ordinalise(n)
-- Adapted from Victor Yee (adapted from NG (adapted from Jason Bourque) & Paul Skinner)
set units to n mod 10
if ((units > 3) or ((n - units) mod 100 is 10) or (units < 1) or (units mod 1 > 0)) then return (n as text) & "th"
return (n as text) & item units of {"st", "nd", "rd"}
end ordinalise
 
on doTask()
Line 308 ⟶ 301:
{1.0E+13, 1, 9, 9}, {1.0E+14, 1, 9, 9}, ¬
{1.0E+15, 1, 2, 4}}
-- set tests to {{20, 20, 1, 9}, {100, 15, 1, 9}, {1000, 10, 1, 9}} -- ToThe do the setRC task only.
set output to {}
set theWorks to getWorks()
tell theWorks to initialise()
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
repeat with i from 1 to (count tests)
set {searchLimitcountLimit, keep, firstEndDigitfirstOuter, lastEndDigitlastOuter} to item i of tests
setif |from|(countLimit to searchLimit -= keep) + 1then
set h to "First " & countLimit
if (searchLimit = keep) then
set r to "First " & searchLimit
else if (keep > 1) then
set rh to "Last " & keep & (" of first " & searchLimitcountLimit)
else
set h to ordinalise(countLimit)
end if
if ((keep = 1) and (firstOuter = lastOuter)) then
set h to h & " palindromic gapful number > 100 ending with " & firstOuter & ":"
else if (firstOuter = lastOuter) then
set h to h & " palindromic gapful numbers > 100 ending with " & firstOuter & ":"
else
set rh to h & " palindromic gapful numbers > 100 ending with digits from " & firstOuter & (searchLimit" asto text)" & lastOuter & "th:")
end if
setif s(i to> "1) >then 100set endingend withof output to ""
ifset (keepend >of 1) then set soutput to "s" & sh
setrepeat twith toouter (lastEndDigitfrom asfirstOuter text) &to ":"lastOuter
set end of output to theWorks's (collect(outer, countLimit, keep)) as text
if (firstEndDigit is not lastEndDigit) then set t to "digits " & firstEndDigit & " to " & t
set end of output to ""
set end of output to r & " palindromic gapful number" & s & t
repeat with digit from firstEndDigit to lastEndDigit
set end of output to theWorks's (collect(digit, searchLimit, keep)) as text
end repeat
end repeat
set AppleScript's text item delimiters to linefeed
set output to (rest of output) as text
set AppleScript's text item delimiters to astid
Line 342 ⟶ 336:
end doTask
 
doTask()</langsyntaxhighlight>
 
{{output}}
<pre style="font-size:80%">First 20 palindromic gapful numbers > 100 ending with digits from 1 to 9:
121 1001 1111 1221 1331 1441 1551 1661 1771 1881 1991 10901 11011 12221 13431 14641 15851 17171 18381 19591
242 2002 2112 2222 2332 2442 2552 2662 2772 2882 2992 20702 21912 22022 23232 24442 25652 26862 28182 29392
Line 356 ⟶ 350:
9009 9999 94149 99099 900009 909909 918819 927729 936639 945549 954459 963369 972279 981189 990099 999999 9459549 9508059 9557559 9606069
 
Last 15 of first 100 palindromic gapful numbers > 100 ending with digits from 1 to 9:
165561 166661 167761 168861 169961 170071 171171 172271 173371 174471 175571 176671 177771 178871 179971
265562 266662 267762 268862 269962 270072 271172 272272 273372 274472 275572 276672 277772 278872 279972
Line 367 ⟶ 361:
95311359 95400459 95499459 95588559 95677659 95766759 95855859 95944959 96033069 96122169 96211269 96300369 96399369 96488469 96577569
 
Last 10 of first 1000 palindromic gapful numbers > 100 ending with digits from 1 to 9:
17799771 17800871 17811871 17822871 17833871 17844871 17855871 17866871 17877871 17888871
27799772 27800872 27811872 27822872 27833872 27844872 27855872 27866872 27877872 27888872
Line 378 ⟶ 372:
9675005769 9675995769 9676886769 9677777769 9678668769 9679559769 9680440869 9681331869 9682222869 9683113869
 
Last 5 of first 10000 palindromic gapful numbers > 100 ending with digits from 1 to 9:
1787557871 1787667871 1787777871 1787887871 1787997871
2787557872 2787667872 2787777872 2787887872 2787997872
Line 389 ⟶ 383:
968697796869 968706607869 968715517869 968724427869 968733337869
 
100000th palindromic gapful numbernumbers > 100 ending with digits from 1 to 9:
178788887871
278788887872
Line 400 ⟶ 394:
96878077087869
 
1000000th palindromic gapful numbernumbers > 100 ending with digits from 1 to 9:
17878799787871
27878799787872
Line 411 ⟶ 405:
9687870990787869
 
10000000th palindromic gapful numbernumbers > 100 ending with digits from 1 to 9:
1787878888787871
2787878888787872
Line 443 ⟶ 437:
96878787878786133168787878787869
 
1.0E+15th palindromic gapful numbernumbers > 100 ending with digits from 2 to 4:
27878787878787888878787878787872
3087878787878783113878787878787803
Line 450 ⟶ 444:
=={{header|C}}==
{{trans|C++}}
<langsyntaxhighlight lang="c">#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
Line 542 ⟶ 536:
 
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 582 ⟶ 576:
=={{header|C++}}==
The idea of generating palindromes first then testing for gapfulness was borrowed from other solutions.
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <cstdint>
 
Line 671 ⟶ 665:
 
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 711 ⟶ 705:
=={{header|Crystal}}==
===Brute force and slow===
<langsyntaxhighlight lang="ruby">def palindromesgapful(digit, pow)
r1 = (10_u64**pow + 1) * digit
r2 = 10_u64**pow * (digit + 1)
Line 738 ⟶ 732:
count = 1000
puts "\nLast 10 of first 1000 palindromic gapful numbers ending in:"
(1..9).each { |digit| print "#{digit} : #{digitscount(digit, count).last(10)}\n" }</langsyntaxhighlight>
 
===Orders of Magnitude Faster: Direct Generation of Numbers===
Line 747 ⟶ 741:
 
Optimized version using number<->string conversion: 21.5 secs
<langsyntaxhighlight lang="ruby">def palindromicgapfuls(digit, count)
gapfuls = [] of UInt64 # array of palindromic gapfuls
dd = 11_u64 * digit # digit gapful divisor: 11, 22,...88, 99
Line 802 ⟶ 796:
1.upto(9) { |digit| puts "#{digit} : #{palindromicgapfuls(digit, count).last(keep)}" }
 
puts (Time.monotonic - start).total_seconds</langsyntaxhighlight>
 
Compact version: 22.0 secs
<langsyntaxhighlight lang="ruby">def palindromicgapfuls(digit, count)
gapfuls = [] of UInt64 # array of palindromic gapfuls
dd = 11_u64 * digit # digit gapful divisor: 11, 22,...88, 99
Line 853 ⟶ 847:
1.upto(9) { |digit| puts "#{digit} : #{palindromicgapfuls(digit, count).last(keep)}" }
 
puts (Time.monotonic - start).total_seconds</langsyntaxhighlight>
 
Object Oriented implementation: same speed - 21.8 seconds
<Br>Here using a Struct (allocated on stack) is faster than using a Class (allocated on heap)
<langsyntaxhighlight lang="ruby">struct PalindromicGapfuls
include Enumerable(UInt64)
 
Line 918 ⟶ 912:
1.upto(9) { |digit| puts "#{digit} : #{PalindromicGapfuls.new(digit).first(count).last(keep)}" }
 
puts (Time.monotonic - start).total_seconds</langsyntaxhighlight>
 
Original version optimized for minimal memory use: 24.6 secs
<langsyntaxhighlight lang="ruby">def palindromicgapfuls(digit, count, keep)
palcnt = 0 # count of gapful palindromes
to_skip = count - keep # count of unwanted values to skip
Line 977 ⟶ 971:
1.upto(9) { |digit| puts "#{digit} : #{palindromicgapfuls(digit, count, keep)}" }
 
puts (Time.monotonic - start).total_seconds</langsyntaxhighlight>
 
Compact version optimized for minimal memory use: 24.5 secs
<langsyntaxhighlight lang="ruby">def palindromicgapfuls(digit, count, keep)
palcnt = 0 # count of gapful palindromes
to_skip = count - keep # count of unwanted values to skip
Line 1,030 ⟶ 1,024:
1.upto(9) { |digit| puts "#{digit} : #{palindromicgapfuls(digit, count, keep)}" }
 
puts (Time.monotonic - start).total_seconds</langsyntaxhighlight>
 
OOP version optimized for minimal memory use - 25.4 secs
<BR>It creates an output method that skips the unwanted values and only keeps/stores the desired ones.
<langsyntaxhighlight lang="ruby">struct PalindromicGapfuls
include Enumerable(UInt64)
 
Line 1,105 ⟶ 1,099:
1.upto(9) { |digit| puts "#{digit} : #{PalindromicGapfuls.new(digit).keep_from(count, keep)}" }
 
puts (Time.monotonic - start).total_seconds</langsyntaxhighlight>
 
Compact minimized memory version that numerically create palindromes: 9.2 secs
<langsyntaxhighlight lang="ruby">def palindromicgapfuls(digit, count, keep)
palcnt = 0 # count of gapful palindromes
to_skip = count - keep # count of unwanted values to skip
Line 1,166 ⟶ 1,160:
1.upto(9) { |digit| puts "#{digit} : #{palindromicgapfuls(digit, count, keep)}" }
 
puts (Time.monotonic - start).total_seconds</langsyntaxhighlight>
 
OOP version optimized for minimal memory use, palindromes created numerically - 9.59 secs
<langsyntaxhighlight lang="ruby">struct PalindromicGapfuls
include Enumerable(UInt64)
Line 1,242 ⟶ 1,236:
1.upto(9) { |digit| puts "#{digit} : #{PalindromicGapfuls.new(digit).keep_from(count, keep)}" }
puts (Time.monotonic - start).total_seconds</langsyntaxhighlight>
 
{{out}}
Line 1,319 ⟶ 1,313:
Run as: $ crystal run --release fsharp2crystal.cr
Best Time: 29.455717914 secs
<langsyntaxhighlight lang="ruby">class PalNo
@digit : UInt64
@dd : UInt64
Line 1,361 ⟶ 1,355:
 
puts (Time.monotonic - start).total_seconds
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,424 ⟶ 1,418:
[968787783387787869]
####
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
This is among the faster versions of the problem. It solves the standard and optional tasks in 0.7 seconds.
 
<syntaxhighlight lang="Delphi">
 
{-------------Library Routines ----------------------------------------------------------------}
procedure GetDigits(N: integer; var IA: TIntegerDynArray);
{Get an array of the integers in a number}
{Numbers returned from least to most significant}
var T,I,DC: integer;
begin
DC:=Trunc(Log10(N))+1;
SetLength(IA,DC);
for I:=0 to DC-1 do
begin
T:=N mod 10;
N:=N div 10;
IA[I]:=T;
end;
end;
 
function GetNKPalindrome(N,K: int64): int64;
{Get Nth Palindrome with K-number of digits}
{N = Left half, Right = Reversed(left) a }
var Temp,H1,H2,I: int64;
begin
{Get left digit count - depends on K being odd/even}
if (K and 1)<>0 then Temp:=K div 2 else Temp:=K div 2 - 1;
{Get power of 10 digits}
H1:=trunc(Power(10, Temp));
{Add in N}
H1:=H1 + N - 1;
H2:=H1;
{ If K is odd, truncate the last digit}
if (k and 1)<>0 then H2:=H2 div 10;
{Reverse H2 and add to H1}
while H2>0 do
begin
H1:=H1 * 10 + (H2 mod 10);
H2:=H2 div 10;
end;
Result:=H1;
end;
 
 
 
function GetPalDigits(N: int64; var Offset: int64): integer;
{Get number of digits and offset for Nth Palindrome}
{Used to feed GetNKPalindrome to find Nth Palindrome}
var R1,R2,Step: int64;
begin
R1:=0;
{Step through number of digits}
for Result:=1 to 36 do
begin
{Calculate new Range step: 9,9,90,90,90,900,900...}
if (Result and 1)<>0 then Step:=9 * Trunc(Power(10,Result div 2));
{Calculate R2}
R2:=(R1 + Step)-1;
{See if N falls between R1 and R2}
if (N>=R1) and (N<=R2) then
begin
{Calculate offset and exit}
Offset:=(N - R1)+1;
exit;
end;
R1:=R2+1;
end;
end;
 
 
function GetNthPalindrome(N: integer): int64;
{Get the Nth Palindrome number}
var D,Off: int64;
begin
D:=GetPalDigits(N,Off);
Result:=GetNKPalindrome(Off,D);
end;
 
 
 
procedure GetPalindromeList(Count: integer; var Pals: TInt64DynArray);
{Get a list of the first "Count"-number of palinedromes (Fast)}
var D,I,Inx,Max: integer;
begin
{Set array length}
SetLength(Pals,Count);
Inx:=0;
{Handle palindromes up to 18 digits}
for D:=1 to 18 do
begin
{Get maximum count for palindrom of D digits}
if (D and 1)=1 then Max:=Trunc(Power(10,(D + 1) div 2))
else Max:=Trunc(Power(10,D div 2));
{Step through all the numbers half the size of the number of digits}
for I:=1 to Max-Max div 10 do
begin
{Store palindrome}
Pals[Inx]:=GetNKPalindrome(I,D);
Inc(Inx);
{Exit when array is full}
if Inx>=Count then break;
end;
end;
end;
 
 
{------------------------------------------------------------------------------------------------}
 
 
function IsGapful(N: int64): boolean;
{Return true if number is "GapFul"}
{GapFul = combined first/last}
{ digits divide evenly into N}
var Digits: TIntegerDynArray;
var I: int64;
begin
Result:=False;
{Must be 3 digit number}
if N<100 then exit;
{Put digits in array}
GetDigits(N,Digits);
{Form number from first and last digit}
I:=Digits[0] + 10 * Digits[High(Digits)];
{Does it divide evenly into N}
Result:=(N mod I)=0;
end;
 
 
function HasEndDigit(N: int64; Digit: integer): boolean;
{Return true if last digit match specified "Digit"}
var LD: integer;
begin
LD:=N mod 10;
Result:=LD=Digit;
end;
 
 
function GetGapfulPalinEndSet(Max, EndDigit: integer): string;
{Get first Max number of Gapful Palindromes with specified EndDigit}
var I,Cnt,P: integer;
begin
Result:='Ending in: '+IntToStr(EndDigit)+CRLF;
Cnt:=0;
{Get palindromes and test them}
for I:=0 to high(Integer) do
begin
{Get next palinedrome}
P:=GetNthPalindrome(I);
{Is Gapful and has specified EndDigit}
if IsGapFul(P) and HasEndDigit(P,EndDigit) then
begin
Inc(Cnt);
{Display it}
Result:=Result+Format('%8d',[P]);
if (Cnt mod 5)=0 then Result:=Result+CRLF;
{Break when finished}
if Cnt>=Max then break;
end;
end;
end;
 
 
 
function LastGapfulPalinEndSet(Count,Last,EndDigit: integer): string;
{Get Gapful Palindromes with specified EndDigit}
{Get "Last" number of items out of a total "Count" }
var I,Inx: integer;
var P: int64;
var IA: TInt64DynArray;
begin
SetLength(IA,Count);
Result:='Ending in: '+IntToStr(EndDigit)+CRLF;
{Get count number of items}
Inx:=0;
for I:=0 to Count-1 do
begin
{Keep getting palindromes until}
{they Gapful and have specified last digit}
repeat
begin
P:=GetNthPalindrome(Inx);
Inc(Inx);
end
until IsGapFul(P) and HasEndDigit(P,EndDigit);
{Save item}
IA[I]:=P;
end;
{Get last items}
for I:=Count-Last to Count-1 do
begin
Result:=Result+Format('%12d',[IA[I]]);
if (I mod 5)=4 then Result:=Result+CRLF;
end;
end;
 
 
 
procedure ShowPalindromicGapfuls(Memo: TMemo);
var S: string;
begin
Memo.Lines.Add('First 20 palindromic gapful numbers');
 
Memo.Lines.Add(GetGapFulPalinEndSet(20,1));
Memo.Lines.Add(GetGapFulPalinEndSet(20,2));
Memo.Lines.Add(GetGapFulPalinEndSet(20,3));
Memo.Lines.Add(GetGapFulPalinEndSet(20,4));
Memo.Lines.Add(GetGapFulPalinEndSet(20,5));
Memo.Lines.Add(GetGapFulPalinEndSet(20,6));
Memo.Lines.Add(GetGapFulPalinEndSet(20,7));
Memo.Lines.Add(GetGapFulPalinEndSet(20,8));
Memo.Lines.Add(GetGapFulPalinEndSet(20,9));
 
Memo.Lines.Add('86th to 100th');
Memo.Lines.Add(LastGapFulPalinEndSet(100,15,1));
Memo.Lines.Add(LastGapFulPalinEndSet(100,15,2));
Memo.Lines.Add(LastGapFulPalinEndSet(100,15,3));
Memo.Lines.Add(LastGapFulPalinEndSet(100,15,4));
Memo.Lines.Add(LastGapFulPalinEndSet(100,15,5));
Memo.Lines.Add(LastGapFulPalinEndSet(100,15,6));
Memo.Lines.Add(LastGapFulPalinEndSet(100,15,7));
Memo.Lines.Add(LastGapFulPalinEndSet(100,15,8));
Memo.Lines.Add(LastGapFulPalinEndSet(100,15,9));
 
Memo.Lines.Add('991st to 1000th:');
Memo.Lines.Add(LastGapFulPalinEndSet(1000,10,1));
Memo.Lines.Add(LastGapFulPalinEndSet(1000,10,2));
Memo.Lines.Add(LastGapFulPalinEndSet(1000,10,3));
Memo.Lines.Add(LastGapFulPalinEndSet(1000,10,4));
Memo.Lines.Add(LastGapFulPalinEndSet(1000,10,5));
Memo.Lines.Add(LastGapFulPalinEndSet(1000,10,6));
Memo.Lines.Add(LastGapFulPalinEndSet(1000,10,7));
Memo.Lines.Add(LastGapFulPalinEndSet(1000,10,8));
Memo.Lines.Add(LastGapFulPalinEndSet(1000,10,9));
end;
 
 
 
</syntaxhighlight>
{{out}}
<pre>
First 20 palindromic gapful numbers
Ending in: 1
121 1001 1111 1221 1331
1441 1551 1661 1771 1881
1991 10901 11011 12221 13431
14641 15851 17171 18381 19591
 
Ending in: 2
242 2002 2112 2222 2332
2442 2552 2662 2772 2882
2992 20702 21912 22022 23232
24442 25652 26862 28182 29392
 
Ending in: 3
363 3003 3333 3663 3993
31713 33033 36663 300003 303303
306603 309903 312213 315513 318813
321123 324423 327723 330033 333333
 
Ending in: 4
484 4004 4224 4444 4664
4884 40304 42724 44044 46464
48884 400004 401104 402204 403304
404404 405504 406604 407704 408804
 
Ending in: 5
5005 5115 5225 5335 5445
5555 5665 5775 5885 5995
50105 51315 52525 53735 54945
55055 56265 57475 58685 59895
 
Ending in: 6
6006 6336 6666 6996 61116
64746 66066 69696 600006 603306
606606 609906 612216 615516 618816
621126 624426 627726 630036 633336
 
Ending in: 7
7007 7777 77077 700007 707707
710017 717717 720027 727727 730037
737737 740047 747747 750057 757757
760067 767767 770077 777777 780087
 
Ending in: 8
8008 8448 8888 80608 86768
88088 800008 802208 804408 806608
808808 821128 823328 825528 827728
829928 840048 842248 844448 846648
 
Ending in: 9
9009 9999 94149 99099 900009
909909 918819 927729 936639 945549
954459 963369 972279 981189 990099
999999 9459549 9508059 9557559 9606069
 
86th to 100th
Ending in: 1
165561 166661 167761 168861 169961
170071 171171 172271 173371 174471
175571 176671 177771 178871 179971
 
Ending in: 2
265562 266662 267762 268862 269962
270072 271172 272272 273372 274472
275572 276672 277772 278872 279972
 
Ending in: 3
30366303 30399303 30422403 30455403 30488403
30511503 30544503 30577503 30600603 30633603
30666603 30699603 30722703 30755703 30788703
 
Ending in: 4
4473744 4485844 4497944 4607064 4619164
4620264 4632364 4644464 4656564 4668664
4681864 4693964 4803084 4815184 4827284
 
Ending in: 5
565565 566665 567765 568865 569965
570075 571175 572275 573375 574475
575575 576675 577775 578875 579975
 
Ending in: 6
60399306 60422406 60455406 60488406 60511506
60544506 60577506 60600606 60633606 60666606
60699606 60722706 60755706 60788706 60811806
 
Ending in: 7
72299227 72322327 72399327 72422427 72499427
72522527 72599527 72622627 72699627 72722727
72799727 72822827 72899827 72922927 72999927
 
Ending in: 8
80611608 80622608 80633608 80644608 80655608
80666608 80677608 80688608 80699608 80800808
80811808 80822808 80833808 80844808 80855808
 
Ending in: 9
95311359 95400459 95499459 95588559 95677659
95766759 95855859 95944959 96033069 96122169
96211269 96300369 96399369 96488469 96577569
 
991st to 1000th:
Ending in: 1
17799771 17800871 17811871 17822871 17833871
17844871 17855871 17866871 17877871 17888871
 
Ending in: 2
27799772 27800872 27811872 27822872 27833872
27844872 27855872 27866872 27877872 27888872
 
Ending in: 3
3084004803 3084334803 3084664803 3084994803 3085225803
3085555803 3085885803 3086116803 3086446803 3086776803
 
Ending in: 4
482282284 482414284 482535284 482656284 482777284
482898284 482909284 483020384 483141384 483262384
 
Ending in: 5
57800875 57811875 57822875 57833875 57844875
57855875 57866875 57877875 57888875 57899875
 
Ending in: 6
6084004806 6084334806 6084664806 6084994806 6085225806
6085555806 6085885806 6086116806 6086446806 6086776806
 
Ending in: 7
7452992547 7453223547 7453993547 7454224547 7454994547
7455225547 7455995547 7456226547 7456996547 7457227547
 
Ending in: 8
8085995808 8086006808 8086116808 8086226808 8086336808
8086446808 8086556808 8086666808 8086776808 8086886808
 
Ending in: 9
9675005769 9675995769 9676886769 9677777769 9678668769
9679559769 9680440869 9681331869 9682222869 9683113869
 
Elapsed Time: 763.788 ms.
 
</pre>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// Palindromic Gapful Numbers . Nigel Galloway: December 3rd., 2020
let rec fN g l=seq{match l with 3->yield! seq{for n in 0L..9L->g*100L+g+n*10L}
Line 1,438 ⟶ 1,817:
[1L..9L]|>Seq.iter(fun n->rcGf n|>Seq.skip 85|>Seq.take 15|>Seq.iter(printf "%d ");printfn "");printfn "#####"
[1L..9L]|>Seq.iter(fun n->rcGf n|>Seq.skip 990|>Seq.take 10|>Seq.iter(printf "%d ");printfn "");printfn "#####"
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,473 ⟶ 1,852:
</pre>
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: formatting fry io kernel lists lists.lazy locals math
math.functions math.ranges math.text.utils prettyprint sequences ;
IN: rosetta-code.palindromic-gapful-numbers
Line 1,525 ⟶ 1,904:
15 100 ! part 2
10 1000 ! part 3 (Optional)
[ show-palindromic-gapfuls ] 2tri@</langsyntaxhighlight>
{{out}}
<pre style="height:45ex">
Line 1,564 ⟶ 1,943:
=={{header|FreeBASIC}}==
Time-consuming brute-force solution with only a few speedups...
<langsyntaxhighlight lang="freebasic">function is_gapful( n as uinteger ) as boolean
if n<100 then return false
dim as string ns = str(n)
Line 1,622 ⟶ 2,001:
print_range(yays(), 1, 20)
print_range(yays(), 86, 100)
print_range(yays(), 991, 1000)</langsyntaxhighlight>
{{out}}
<pre>
Line 1,673 ⟶ 2,052:
=={{header|Fōrmulæ}}==
 
In [{{FormulaeEntry|page=https://wiki.formulae.org/?script=examples/Palindromic_gapful_numbers this] page you can see the solution of this task.}}
 
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.
 
The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.
 
=={{header|Go}}==
Line 1,683 ⟶ 2,058:
 
To keep the Pascal entry company, I've extended the search to the first 10 million such numbers for each of the nine sets.
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 1,786 ⟶ 2,161:
fmt.Println()
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,870 ⟶ 2,245:
=={{header|Haskell}}==
===Brute Force===
<langsyntaxhighlight lang="haskell">import Control.Monad (guard)
 
palindromic :: Int -> Bool
Line 1,905 ⟶ 2,280:
putStrLn "\nLast 10 of first 1000 palindromic gapful numbers ending in:"
showSets (show . drop 990 . take 1000 . result)
putStrLn "\ndone."</langsyntaxhighlight>
 
===Optimized===
Here the approach is to generate a series of palindromes.
<langsyntaxhighlight lang="haskell">import Data.List (sort, unfoldr)
import Control.Monad (guard)
 
Line 1,943 ⟶ 2,318:
, ("Last 15 of first 100", drop 85 . take 100)
, ("Last 10 of first 1000", drop 990 . take 1000)
]</langsyntaxhighlight>
{{out}}
<pre>
Line 2,001 ⟶ 2,376:
</pre>
Part 2:
<syntaxhighlight lang="text">
palindromify=: [: , ((,~ |.@}.) ; (,~ |.))&>
gapful=: (0 = (|~ ({.,{:)&.(10&#.inv)))&>
Line 2,007 ⟶ 2,382:
task2_palindromes=: [: 10&#.&> [: palindromify task2_cartesian_products
task2_gapfuls=: [: /:~ [: ; [: (#~ gapful)@task2_palindromes&.> >:@i.
</syntaxhighlight>
</lang>
 
<pre>
Line 2,073 ⟶ 2,448:
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">
import java.util.ArrayList;
import java.util.HashMap;
Line 2,183 ⟶ 2,558:
 
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,222 ⟶ 2,597:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">import Base.iterate, Base.IteratorSize, Base.IteratorEltype
 
struct Palindrome x1::UInt8; x2::UInt8; outer::UInt8; end
Line 2,266 ⟶ 2,641:
 
testpal()
</langsyntaxhighlight>{{out}}
<pre style="height:100ex;overflow:scroll">
Last digit | Last 20 of 20 palindromic gapful numbers from 100
Line 2,359 ⟶ 2,734:
1770.411549 seconds (13.02 G allocations: 443.799 GiB, 40.12% gc time)
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">ClearAll[GapfulQ, GetFirstPalindromicGapfulNumbers]
GapfulQ[n_Integer] := Divisible[n, FromDigits[IntegerDigits[n][[{1, -1}]]]]
GetFirstPalindromicGapfulNumbers[startend_, n_Integer] :=
Module[{out = {}, i, new, digs, id},
digs = 1;
While[Length[out] < n,
Do[
id = IntegerDigits[i, 10, Ceiling[digs/2]];
If[OddQ[digs],
new = Join[{startend}, id, Rest@Reverse[id], {startend}]
,
new = Join[{startend}, id, Reverse[id], {startend}]
];
new //= FromDigits;
If[GapfulQ[new],
AppendTo[out, new]
];
i++;
,
{i, 0, 10^Ceiling[digs/2] - 1}
];
digs += 1;
];
Take[out, n]
]
Print["First 20 palindromic gapful numbers >100 ending with each digit from 1 to 9:"]
Print[GetFirstPalindromicGapfulNumbers[#, 20]] & /@ Range[9];
Print["86th to 100th:"]
Print[GetFirstPalindromicGapfulNumbers[#, 100][[86 ;; 100]]] & /@ Range[9];
Print["991st to 1000th:"]
Print[GetFirstPalindromicGapfulNumbers[#, 1000][[991 ;; 1000]]] & /@ Range[9];</syntaxhighlight>
{{out}}
<pre>First 20 palindromic gapful numbers >100 ending with each digit from 1 to 9:
{121,1001,1111,1221,1331,1441,1551,1661,1771,1881,1991,10901,11011,12221,13431,14641,15851,17171,18381,19591}
{242,2002,2112,2222,2332,2442,2552,2662,2772,2882,2992,20702,21912,22022,23232,24442,25652,26862,28182,29392}
{363,3003,3333,3663,3993,31713,33033,36663,300003,303303,306603,309903,312213,315513,318813,321123,324423,327723,330033,333333}
{484,4004,4224,4444,4664,4884,40304,42724,44044,46464,48884,400004,401104,402204,403304,404404,405504,406604,407704,408804}
{5005,5115,5225,5335,5445,5555,5665,5775,5885,5995,50105,51315,52525,53735,54945,55055,56265,57475,58685,59895}
{6006,6336,6666,6996,61116,64746,66066,69696,600006,603306,606606,609906,612216,615516,618816,621126,624426,627726,630036,633336}
{7007,7777,77077,700007,707707,710017,717717,720027,727727,730037,737737,740047,747747,750057,757757,760067,767767,770077,777777,780087}
{8008,8448,8888,80608,86768,88088,800008,802208,804408,806608,808808,821128,823328,825528,827728,829928,840048,842248,844448,846648}
{9009,9999,94149,99099,900009,909909,918819,927729,936639,945549,954459,963369,972279,981189,990099,999999,9459549,9508059,9557559,9606069}
86th to 100th:
{165561,166661,167761,168861,169961,170071,171171,172271,173371,174471,175571,176671,177771,178871,179971}
{265562,266662,267762,268862,269962,270072,271172,272272,273372,274472,275572,276672,277772,278872,279972}
{30366303,30399303,30422403,30455403,30488403,30511503,30544503,30577503,30600603,30633603,30666603,30699603,30722703,30755703,30788703}
{4473744,4485844,4497944,4607064,4619164,4620264,4632364,4644464,4656564,4668664,4681864,4693964,4803084,4815184,4827284}
{565565,566665,567765,568865,569965,570075,571175,572275,573375,574475,575575,576675,577775,578875,579975}
{60399306,60422406,60455406,60488406,60511506,60544506,60577506,60600606,60633606,60666606,60699606,60722706,60755706,60788706,60811806}
{72299227,72322327,72399327,72422427,72499427,72522527,72599527,72622627,72699627,72722727,72799727,72822827,72899827,72922927,72999927}
{80611608,80622608,80633608,80644608,80655608,80666608,80677608,80688608,80699608,80800808,80811808,80822808,80833808,80844808,80855808}
{95311359,95400459,95499459,95588559,95677659,95766759,95855859,95944959,96033069,96122169,96211269,96300369,96399369,96488469,96577569}
991st to 1000th:
{17799771,17800871,17811871,17822871,17833871,17844871,17855871,17866871,17877871,17888871}
{27799772,27800872,27811872,27822872,27833872,27844872,27855872,27866872,27877872,27888872}
{3084004803,3084334803,3084664803,3084994803,3085225803,3085555803,3085885803,3086116803,3086446803,3086776803}
{482282284,482414284,482535284,482656284,482777284,482898284,482909284,483020384,483141384,483262384}
{57800875,57811875,57822875,57833875,57844875,57855875,57866875,57877875,57888875,57899875}
{6084004806,6084334806,6084664806,6084994806,6085225806,6085555806,6085885806,6086116806,6086446806,6086776806}
{7452992547,7453223547,7453993547,7454224547,7454994547,7455225547,7455995547,7456226547,7456996547,7457227547}
{8085995808,8086006808,8086116808,8086226808,8086336808,8086446808,8086556808,8086666808,8086776808,8086886808}
{9675005769,9675995769,9676886769,9677777769,9678668769,9679559769,9680440869,9681331869,9682222869,9683113869}</pre>
 
=={{header|Nim}}==
Line 2,364 ⟶ 2,803:
Forms palindromes using number<->string conversions.
 
<langsyntaxhighlight lang="ruby">import strutils # for number input
import times # for timing code execution
import unicode # for reversed
Line 2,418 ⟶ 2,857:
for digit in 1..9: echo(digit, " : ", palindromicgapfuls(digit, count, keep) )
 
echo (epochTime() - start)</langsyntaxhighlight>
 
System: I7-6700HQ, 3.5GHz, Linux Kernel 5.9.10, GCC 10.2.0, Nim 1.4.0
Line 2,427 ⟶ 2,866:
Faster version performing number<->string conversions for palindromes.
 
<langsyntaxhighlight lang="ruby">import strutils # for number input
import times # for timing code execution
import unicode # for reversed
Line 2,479 ⟶ 2,918:
for digit in 1..9: echo(digit, " : ", palindromicgapfuls(digit, count, keep) )
 
echo (epochTime() - start)</langsyntaxhighlight>
 
System: I7-6700HQ, 3.5GHz, Linux Kernel 5.9.10, GCC 10.2.0, Nim 1.4.0
Line 2,488 ⟶ 2,927:
Fastest: make palindromes directly numerically.
 
<langsyntaxhighlight lang="ruby">import times
 
proc make_palindrome(front_half: uint64, power: int): uint64 =
Line 2,543 ⟶ 2,982:
for digit in 1..9: echo(digit, " : ", palindromicgapfuls(digit, count, keep) )
 
echo (epochTime() - start)</langsyntaxhighlight>
 
System: I7-6700HQ, 3.5GHz, Linux Kernel 5.9.14, GCC 10.2.0, Nim 1.4.2
Line 2,626 ⟶ 3,065:
9 : 968787783387787869</pre>
 
<langsyntaxhighlight lang="pascal">program PalinGap;
{$IFDEF FPC}
{$MODE DELPHI}{$OPTIMIZATION ON,ALL}{$CODEALIGN proc=16}{$ALIGN 16}
Line 2,798 ⟶ 3,237:
OutPalinGap(10000000,10000000,dgt);
writeln;
end.</langsyntaxhighlight>{{out}}<pre style="height:35ex;overflow:scroll;font-size:87%">
palindromic gapful numbers from 1 to 20
1 : 121 1001 1111 1221 1331 1441 1551 1661 1771 1881 1991 10901 11011 12221 13431 14641 15851 17171 18381 19591
Line 2,870 ⟶ 3,309:
=={{header|Perl}}==
Minor (and inefficient) tweak on the [[Gapful numbers]] task.
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 2,892 ⟶ 3,331:
}
say ''
}</langsyntaxhighlight>
{{out}}
<pre style="height:20ex">Palindromic gapful numbers starting at 1:
Line 2,919 ⟶ 3,358:
{{trans|Go}}
Translation of Go, but trimmed back to bare minimum: you should not expect this to fare particularly well at the 10_000_000-level against the likes of Go/Pascal, though it should fare reasonably well against lesser beings... The version below beats 'em all, though, for now.
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>function reverse_n(atom s)
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
atom e = 0
<span style="color: #008080;">function</span> <span style="color: #000000;">reverse_n</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
while s>0 do
<span style="color: #004080;">atom</span> <span style="color: #000000;">e</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
e = e*10 + remainder(s,10)
<span style="color: #008080;">while</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">></span><span style="color: #000000;">0</span> <span style="color: #008080;">do</span>
s = floor(s/10)
<span style="color: #000000;">e</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">e</span><span style="color: #0000FF;">*</span><span style="color: #000000;">10</span> <span style="color: #0000FF;">+</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
end while
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">/</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
return e
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
end function
<span style="color: #008080;">return</span> <span style="color: #000000;">e</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">mx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1000</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">data</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">20</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"%7d "</span><span style="color: #0000FF;">},</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">86</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">100</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"%8d "</span><span style="color: #0000FF;">},</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">991</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1000</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"%10d "</span><span style="color: #0000FF;">}}</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #7060A8;">ordinal</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
constant mx = 1000,
data = {{1, 20, "%7d "}, {86, 100, "%8d "}, {991, 1000, "%10d "}}
 
include builtins\ordinal.e
 
procedure main()
sequence results = repeat(repeat({},9),mx)
for d=1 to 9 do -- (the start/end digit)
integer count = 0, pow = 1, fl = d*11
for nd=3 to 15 do -- (number of digits, usually quits early)
-- (obvs. 64-bit phix is fine with 19 digits, but 32-bit ain't)
bool odd = (remainder(nd,2)==1)
for s=d*pow to (d+1)*pow-1 do -- (eg 300 to 399)
integer e = reverse_n(s)
for m=0 to iff(odd?9:0) do -- (1 or 10 iterations)
atom p = e + iff(odd ? s*pow*100+m*pow*10
: s*pow*10)
if remainder(p,fl)==0 then -- gapful!
count += 1
results[count][d] = p
-- (see? goto /is/ sometimes useful :-))
if count==mx then #ilASM{jmp :outer} end if
end if
end for
end for
if odd then pow *= 10 end if
end for
if count<mx then ?9/0 end if -- oh dear...
#ilASM{::outer}
end for
<span style="color: #008080;">function</span> <span style="color: #000000;">digit</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">results</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">)</span>
for i=1 to length(data) do
<span style="color: #004080;">integer</span> <span style="color: #000000;">count</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">pow</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">fl</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">*</span><span style="color: #000000;">11</span>
{integer s, integer e, string fmt} = data[i]
<span style="color: #008080;">for</span> <span style="color: #000000;">nd</span><span style="color: #0000FF;">=</span><span style="color: #000000;">3</span> <span style="color: #008080;">to</span> <span style="color: #000000;">15</span> <span style="color: #008080;">do</span> <span style="color: #000080;font-style:italic;">-- (number of digits, usually quits early)
printf(1,"%,d%s to %,d%s palindromic gapful numbers (> 100) ending with:\n", {s,ord(s),e,ord(e)})
-- (obvs. 64-bit phix is fine with 19 digits, but 32-bit ain't)</span>
for d=1 to 9 do
<span style="color: #004080;">bool</span> <span style="color: #000000;">odd</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">(</span><span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">nd</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)==</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
printf(1,"%d: ",d)
<span style="color: #008080;">for</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">=</span><span style="color: #000000;">d</span><span style="color: #0000FF;">*</span><span style="color: #000000;">pow</span> <span style="color: #008080;">to</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">pow</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span> <span style="color: #000080;font-style:italic;">-- (eg 300 to 399)</span>
for j=s to e do
<span style="color: #004080;">integer</span> <span style="color: #000000;">e</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">reverse_n</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
printf(1,fmt,results[j][d])
<span style="color: #008080;">for</span> <span style="color: #000000;">m</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">to</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">odd</span><span style="color: #0000FF;">?</span><span style="color: #000000;">9</span><span style="color: #0000FF;">:</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span> <span style="color: #000080;font-style:italic;">-- (1 or 10 iterations)</span>
end for
<span style="color: #004080;">atom</span> <span style="color: #000000;">p</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">e</span> <span style="color: #0000FF;">+</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">odd</span> <span style="color: #0000FF;">?</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">*</span><span style="color: #000000;">pow</span><span style="color: #0000FF;">*</span><span style="color: #000000;">100</span><span style="color: #0000FF;">+</span><span style="color: #000000;">m</span><span style="color: #0000FF;">*</span><span style="color: #000000;">pow</span><span style="color: #0000FF;">*</span><span style="color: #000000;">10</span>
printf(1,"\n")
<span style="color: #0000FF;">:</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">*</span><span style="color: #000000;">pow</span><span style="color: #0000FF;">*</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
end for
<span style="color: #008080;">if</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fl</span><span style="color: #0000FF;">)==</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">-- gapful!</span>
printf(1,"\n")
<span style="color: #000000;">count</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
end for
<span style="color: #000000;">results</span><span style="color: #0000FF;">[</span><span style="color: #000000;">count</span><span style="color: #0000FF;">][</span><span style="color: #000000;">d</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">p</span>
end procedure
<span style="color: #008080;">if</span> <span style="color: #000000;">count</span><span style="color: #0000FF;">==</span><span style="color: #000000;">mx</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #000000;">results</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
main()</lang>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">odd</span> <span style="color: #008080;">then</span> <span style="color: #000000;">pow</span> <span style="color: #0000FF;">*=</span> <span style="color: #000000;">10</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">count</span><span style="color: #0000FF;"><</span><span style="color: #000000;">mx</span> <span style="color: #008080;">then</span> <span style="color: #0000FF;">?</span><span style="color: #000000;">9</span><span style="color: #0000FF;">/</span><span style="color: #000000;">0</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> <span style="color: #000080;font-style:italic;">-- oh dear...</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">results</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">results</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">({},</span><span style="color: #000000;">9</span><span style="color: #0000FF;">),</span><span style="color: #000000;">mx</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">9</span> <span style="color: #008080;">do</span> <span style="color: #000080;font-style:italic;">-- (the start/end digit)</span>
<span style="color: #000000;">results</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">digit</span><span style="color: #0000FF;">(</span><span style="color: #000000;">results</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">data</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #0000FF;">{</span><span style="color: #004080;">integer</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">e</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">string</span> <span style="color: #000000;">fmt</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">data</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%,d%s to %,d%s palindromic gapful numbers (&gt; 100) ending with:\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">ord</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">),</span><span style="color: #000000;">e</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">ord</span><span style="color: #0000FF;">(</span><span style="color: #000000;">e</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">9</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d: "</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">s</span> <span style="color: #008080;">to</span> <span style="color: #000000;">e</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">,</span><span style="color: #000000;">results</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">][</span><span style="color: #000000;">d</span><span style="color: #0000FF;">])</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</syntaxhighlight>-->
{{out}}
<pre style="font-size: 11px">
Line 3,010 ⟶ 3,455:
 
=== Ludicrously fast to 10,000,000,000,000,000,000th ===
{{libheader|Phix/online}}
Astonishingly this is all done with standard precision numbers, &lt; 2<sup><small>53</small></sup>. You realise this is like ten thousand times the ''square'' of the previous limits, and still far faster.<br>
You can run this online [http://phix.x10.mx/p2js/pgn.htm here].
I will credit [[Self_numbers#AppleScript]] and the comment by Nigel Galloway on the talk page for ideas that inspired me.
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>-- demo/rosetta/Palindromic_gapful_numbers.exw
<span style="color: #000080;font-style:italic;">--
--
-- demo\rosetta\Palindromic_gapful_numbers.exw
-- A palindrome such as 9459549 can be constructed/broken down into
-- ===========================================
-- 9000009
--
-- 400040
-- Astonishingly this is all done with standard precision numbers, &lt;2^53.
-- 50500
-- I will credit [[Self_numbers#AppleScript]] and comment by Nigel Galloway
-- 9000
-- on the talk page for ideas that inspired me.
--
--
-- Further, 9459549 rem 99 is the same as
-- A palindrome such as 9459549 can be constructed/broken down into
-- (the sum of rem 99 on all of those pieces) rem 99
-- 9000009
--
-- 400040
-- Finding eg 400040 rem 99 can also be simplified, it is of course the
-- same as (400000 rem 99 + 40 rem 99) rem 99, and further 40 rem 99 50500
-- 9000
-- is the same as (4 rem 99[already known])*10 rem 99 [smaller nos].
--
-- AlsoFurther, when9459549 fillingrem a99 "hole", such asis the finalsame 9, weas find
-- (the sum of rem 99 on all of those pieces) rem v 99
--
-- 9450549 rem 99 = 9
-- Finding eg 400040 rem 99 can also be simplified, 9451549it remis 99of =course 19,the
-- same as (400000 rem 99 + 945254940 rem 99) =rem 2999, and further 40 rem 99
-- is the same as (4 rem 99[already 9453549known])*10 rem 99 =[smaller 39,nos].
--
-- 9454549 rem 99 = 49,
-- Also, when filling a "hole", such as the final 9, we find
-- 9455549 rem 99 = 59,
-- 9456549 rem 99 =v 69,
-- 94575499450549 rem 99 = 79,9
-- 94585499451549 rem 99 = 8919, and
-- 94595499452549 rem 99 = 029,
-- 9453549 rem 99 ^= 39,
-- 9454549 rem 99 = 49,
-- in this case only the '9' fits.
-- 9455549 rem 99 = 59,
--
-- But actually we can predict what will fit from the9456549 partialrem sum99 of= 69,
-- prior pieces rem 99, ie 9000009..50500, and the same9457549 canrem be99 said= 79,
-- 9458549 rem 99 = 89, and
-- when filling the 505-sized hole - what will "fit" depends not on
-- what the "outer" actually are, but what their sum9459549 rem 99 is= 0, and
-- likewise for larger and larger holes. ^
-- in this case only the '9' fits.
-- If we later find ourselves looking at the same size hole, with
--
-- the same outer rem and the same rem 99 outmost requirement, we
-- But actually we can predict what will fit from the partial sum of
-- would know instantly how many things are going to fit.
-- prior pieces rem 99, ie 9000009..50500, and the same can be said
-- True, keeping full lists as the holes got bigger would probably
-- when filling the 505-sized hole - what will "fit" depends not on
-- consume memory almost as fast as an SR-71, but a single count,
-- what the "outer" actually are, but what their sum rem 99 is, and
-- albeit one keyed on 4 conditions, we can cope. It turns out that
-- likewise for larger and larger holes.
-- even by the 10^19th scan, we only hit 24,791 variations anyway.
-- AsIf we stumblelater acrossfind largerourselves andlooking largerat holes,the whatsame wesize learnhole, canwith
-- bethe usedsame toouter skip morerem and morethe similar,same suchrem that99 findingoutmost therequirement, we
-- would know instantly how many things are going to fit.
-- ten millionth item is almost as fast as the first millionth, as
-- True, keeping full lists as the holes got bigger would probably
-- opposed to the times 10 that you'd normally expect.
-- consume memory almost as fast as an SR-71, but a single count,
--
-- albeit one keyed on 4 conditions, we can cope. It turns out that
-- Note that if I stumble across a hole that will fit more than I'm
-- even by the 10^15th scan, we only hit 17,579 variations anyway.
-- prepared to fully skip, I start going through things one-by-one,
-- As we stumble across larger and larger holes, what we learn can
-- but that's ok because many smaller but still quite big holes
-- be used to skip more and more similar, such that finding the
-- will probably be skipped.
-- ten millionth item is almost as fast as the first millionth, as
--
-- opposed to the times 10 that you'd normally expect.
 
--
sequence cache = columnize(repeat(columnize({tagset(9)}),9))
-- Note that if I stumble across a hole that will fit more than I'm
-- ie {{{1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}},
-- prepared to fully skip, I start going through things one-by-one,
-- {{2}, {2}, {2}, {2}, {2}, {2}, {2}, {2}, {2}},
-- but that's ok because many smaller but still quite big holes
-- {{3}, {3}, {3}, {3}, {3}, {3}, {3}, {3}, {3}},
-- will probably be skipped.
-- {{4}, {4}, {4}, {4}, {4}, {4}, {4}, {4}, {4}},
--</span>
-- {{5}, {5}, {5}, {5}, {5}, {5}, {5}, {5}, {5}},
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
-- {{6}, {6}, {6}, {6}, {6}, {6}, {6}, {6}, {6}},
-- {{7}, {7}, {7}, {7}, {7}, {7}, {7}, {7}, {7}},
<span style="color: #004080;">sequence</span> <span style="color: #000000;">cache</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">({</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">9</span><span style="color: #0000FF;">)}),</span><span style="color: #000000;">9</span><span style="color: #0000FF;">))</span>
-- {{8}, {8}, {8}, {8}, {8}, {8}, {8}, {8}, {8}},
<span style="color: #000080;font-style:italic;">-- ie <nowiki>{{</nowiki>{91}, {91}, {91}, {91}, {91}, {91}, {91}, {91}, {9}1<nowiki>}}</nowiki>,
-- <nowiki>{{</nowiki>2}, {2}, {2}, {2}, {2}, {2}, {2}, {2}, {2<nowiki>}}</nowiki>,
-- aka 1 rem 11 .. 1 rem 99 are all 1,
-- <nowiki>{{</nowiki>3}, {3}, {3}, {3}, {3}, {3}, {3}, {3}, {3<nowiki>}}</nowiki>,
-- .. 9 rem 11 .. 9 rem 99 are all 9.
-- <nowiki>{{</nowiki>4}, {4}, {4}, {4}, {4}, {4}, {4}, {4}, {4<nowiki>}}</nowiki>,
-- each gets extended with 10 rem 11 .. 10 rem 99,
-- <nowiki>{{</nowiki>5}, {5}, {5}, {5}, {5}, {5}, {5}, {5}, {5<nowiki>}}</nowiki>,
-- 100 rem 11 .. 100 rem 99,
-- <nowiki>{{</nowiki>6}, {6}, {6}, {6}, {6}, {6}, {6}, {6}, {6<nowiki>}}</nowiki>,
-- ... .. 900 rem 99, etc.
-- <nowiki>{{</nowiki>7}, {7}, {7}, {7}, {7}, {7}, {7}, {7}, {7<nowiki>}}</nowiki>,
-- (not really worth trying to take advantage of any cycles
-- <nowiki>{{</nowiki>8}, {8}, {8}, {8}, {8}, {8}, {8}, {8}, {8<nowiki>}}</nowiki>,
-- that might appear in such a relatively small table, as
-- <nowiki>{{</nowiki>9}, {9}, {9}, {9}, {9}, {9}, {9}, {9}, {9<nowiki>}}</nowiki>}
-- it will be at most (on 64-bit) 9 * 9 * 42.)
-- aka 1 rem 11 .. 1 rem 99 are all 1,
--
-- .. 9 rem 11 .. 9 rem 99 are all 9.
function rmdr(integer digit, gap, pow, n)
-- each gets extended with 10 rem 11 .. 10 rem 99,
--
-- 100 rem 11 .. 100 rem 99,
-- digit is the outer 0..9 (obvs 0 always yields 0),
-- ... .. 900 rem 99, etc.
-- gap is zeroes between (-1,0,1,2,.. for eg 1,11,101,1001),
-- (not really worth trying to take advantage of any cycles
-- pow is trailing zeros (0,1,2,.. for eg 101,1010,10100),
-- that might appear in such a relatively small table, as
-- n is 1..9 for 11..99
-- it will be at most (on 64-bit) 9 * 9 * 42.)
-- eg rmdr(4,3,2,1) yields remainder(4000400,11), but
--</span>
-- that === remainder(remainder(4000000,11)+
<span style="color: #008080;">function</span> <span style="color: #000000;">rmdrn</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">digit</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">gap</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">pow</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
-- remainder( 400,11),11), and
<span style="color: #000080;font-style:italic;">--
-- if k = remainder(4*10^(m-1),11) [already known] then
-- digit is the outer 0..9 (obvs 0 always yields 0),
-- remainder(4*10^m,11) === remainder(k*10,11), so
-- gap is zeroes between (-1,0,1,2,.. for eg 1,11,101,1001),
-- we only need to keep a small table for each [digit][n].
-- pow is trailing zeros (0,1,2,.. for eg 101,1010,10100),
-- Thus we avoid maths on 10^42-size numbers/needing gmp.
-- n is 1..9 for 11..99
--
-- eg rmdrn(4,3,2,1) yields remainder(4000400,11), but
if digit=0 then return 0 end if
-- that === remainder(remainder(4000000,11)+
integer nn = n*11
-- remainder( 400,11),11), and
while length(cache[digit][n])<gap+pow+2 do
-- if k cache[digit][n] &= remainder(cache[digit][n][$]4*10^(m-1),nn11) [already known] then
-- remainder(4*10^m,11) === remainder(k*10,11), so
end while
-- we only need to keep a small table for each [digit][n].
integer g = iff(gap=-1?0:cache[digit][n][gap+pow+2])
-- Thus we avoid maths on 10^42-ish numbers/needing gmp.
return remainder(g+cache[digit][n][pow+1],nn)
--</span>
end function
<span style="color: #008080;">if</span> <span style="color: #000000;">digit</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #000000;">0</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
 
<span style="color: #004080;">integer</span> <span style="color: #000000;">nn</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">*</span><span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">g</span>
integer skipd = new_dict()
<span style="color: #004080;">sequence</span> <span style="color: #000000;">cdn</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">cache</span><span style="color: #0000FF;">[</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">][</span><span style="color: #000000;">n</span><span style="color: #0000FF;">]</span>
 
<span style="color: #008080;">while</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdn</span><span style="color: #0000FF;">)<</span><span style="color: #000000;">gap</span><span style="color: #0000FF;">+</span><span style="color: #000000;">pow</span><span style="color: #0000FF;">+</span><span style="color: #000000;">2</span> <span style="color: #008080;">do</span>
function palindromicgapfuls(sequence pals, string lhs, atom palcount, to_skip, count, integer l, r, p, dd)
<span style="color: #000000;">cache</span><span style="color: #0000FF;">[</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">][</span><span style="color: #000000;">n</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span> <span style="color: #000080;font-style:italic;">-- (kill refcount)</span>
--
<span style="color: #000000;">cdn</span> <span style="color: #0000FF;">&=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdn</span><span style="color: #0000FF;">[$]*</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #000000;">nn</span><span style="color: #0000FF;">)</span>
-- pals: results (passing it up grants it automatic pass-by-reference status, which may help speedwise)
<span style="color: #000000;">cache</span><span style="color: #0000FF;">[</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">][</span><span style="color: #000000;">n</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">cdn</span>
-- lhs: eg "945" of a potential 9459549 result
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
-- palcount, to_skip, count: self explanatory (aka got/ignore/target)
<span style="color: #000000;">g</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">gap</span><span style="color: #0000FF;">=-</span><span style="color: #000000;">1</span> <span style="color: #0000FF;">?</span> <span style="color: #000000;">0</span> <span style="color: #0000FF;">:</span> <span style="color: #000000;">cdn</span><span style="color: #0000FF;">[</span><span style="color: #000000;">gap</span><span style="color: #0000FF;">+</span><span style="color: #000000;">pow</span><span style="color: #0000FF;">+</span><span style="color: #000000;">2</span><span style="color: #0000FF;">])</span>
-- l: length of inner to be filled in
<span style="color: #008080;">return</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">g</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">cdn</span><span style="color: #0000FF;">[</span><span style="color: #000000;">pow</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">],</span><span style="color: #000000;">nn</span><span style="color: #0000FF;">)</span>
-- r: remainder of outer, eg remainder(9400049,11), built from rmdr()
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
-- p: left shift (should in fact always equal length(lhs), I think)
-- dd: outermost 1..9 (despite the name, it's a single digit)
<span style="color: #004080;">integer</span> <span style="color: #000000;">skipd</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">new_dict</span><span style="color: #0000FF;">()</span>
--
sequence key = {l,r,p,dd}
<span style="color: #008080;">function</span> <span style="color: #000000;">palindromicgapfuls</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">pals</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">string</span> <span style="color: #000000;">lhs</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">palcount</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">to_skip</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">count</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">p</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">dd</span><span style="color: #0000FF;">)</span>
integer node = getd_index(key,skipd)
<span style="color: #000080;font-style:italic;">--
atom skip = iff(node==null?count:getd_by_index(node,skipd))
-- pals: results (passing it up grants it automatic pass-by-reference status, which may help speedwise)
if node!=null and (palcount+skip)<to_skip then
-- lhs: eg "945" of a potential 9459549 result
palcount += skip
-- palcount, to_skip, count: self explanatory (aka got/ignore/target)
else
-- l: length of inner to be filled in
skip = 0
-- r: remainder of outer, eg remainder(9400049,11), built from rmdrn()
for d=0 to 9 do
-- p: left shift (should in fact always equal length(lhs), I think)
integer r2 = remainder(r+rmdr(d,l-2,p,dd),dd*11)
-- dd: outermost 1..9 (despite the name, it's a single digit)
if l<=2 then
--</span>
if r2=0 then
<span style="color: #004080;">sequence</span> <span style="color: #000000;">key</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">l</span><span style="color: #0000FF;">,</span><span style="color: #000000;">r</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dd</span><span style="color: #0000FF;">}</span>
palcount += 1
<span style="color: #004080;">integer</span> <span style="color: #000000;">node</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">getd_index</span><span style="color: #0000FF;">(</span><span style="color: #000000;">key</span><span style="color: #0000FF;">,</span><span style="color: #000000;">skipd</span><span style="color: #0000FF;">)</span>
if palcount<=to_skip then
<span style="color: #004080;">atom</span> <span style="color: #000000;">skip</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">node</span><span style="color: #0000FF;">==</span><span style="color: #004600;">null</span><span style="color: #0000FF;">?</span><span style="color: #000000;">count</span><span style="color: #0000FF;">:</span><span style="color: #7060A8;">getd_by_index</span><span style="color: #0000FF;">(</span><span style="color: #000000;">node</span><span style="color: #0000FF;">,</span><span style="color: #000000;">skipd</span><span style="color: #0000FF;">)),</span> <span style="color: #000000;">skipn</span>
skip += 1
<span style="color: #008080;">if</span> <span style="color: #000000;">node</span><span style="color: #0000FF;">!=</span><span style="color: #004600;">null</span> <span style="color: #008080;">and</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">palcount</span><span style="color: #0000FF;">+</span><span style="color: #000000;">skip</span><span style="color: #0000FF;">)<</span><span style="color: #000000;">to_skip</span> <span style="color: #008080;">then</span>
else
<span style="color: #000000;">palcount</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">skip</span>
pals = append(pals,lhs&repeat(d+'0',l)&reverse(lhs))
<span style="color: #008080;">else</span>
end if
<span style="color: #000000;">skip</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
end if
<span style="color: #008080;">for</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">to</span> <span style="color: #000000;">9</span> <span style="color: #008080;">do</span>
else
<span style="color: #004080;">integer</span> <span style="color: #000000;">r2</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">+</span><span style="color: #000000;">rmdrn</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">,</span><span style="color: #000000;">l</span><span style="color: #0000FF;">-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dd</span><span style="color: #0000FF;">),</span><span style="color: #000000;">dd</span><span style="color: #0000FF;">*</span><span style="color: #000000;">11</span><span style="color: #0000FF;">)</span>
{pals,palcount,atom skipn} = palindromicgapfuls(pals, lhs&(d+'0'), palcount, to_skip, count, l-2, r2, p+1, dd)
<span style="color: #008080;">if</span> <span style="color: #000000;">l</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">2</span> <span style="color: #008080;">then</span>
skip += skipn
<span style="color: #008080;">if</span> <span style="color: #000000;">r2</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
end if
<span style="color: #000000;">palcount</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
if palcount==count then exit end if
<span style="color: #008080;">if</span> <span style="color: #000000;">palcount</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">to_skip</span> <span style="color: #008080;">then</span>
end for
<span style="color: #000000;">skip</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
if palcount<to_skip then setd(key,skip,skipd) end if
<span style="color: #008080;">else</span>
end if
<span style="color: #000000;">pals</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">deep_copy</span><span style="color: #0000FF;">(</span><span style="color: #000000;">pals</span><span style="color: #0000FF;">),</span><span style="color: #000000;">lhs</span><span style="color: #0000FF;">&</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">+</span><span style="color: #008000;">'0'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">l</span><span style="color: #0000FF;">)&</span><span style="color: #7060A8;">reverse</span><span style="color: #0000FF;">(</span><span style="color: #000000;">lhs</span><span style="color: #0000FF;">))</span>
return {pals,palcount,skip}
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end function
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
 
<span style="color: #008080;">else</span>
function collect(integer digit, atom count, keep)
<span style="color: #0000FF;">{</span><span style="color: #000000;">pals</span><span style="color: #0000FF;">,</span><span style="color: #000000;">palcount</span><span style="color: #0000FF;">,</span><span style="color: #000000;">skipn</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">palindromicgapfuls</span><span style="color: #0000FF;">(</span><span style="color: #000000;">pals</span><span style="color: #0000FF;">,</span><span style="color: #000000;">lhs</span><span style="color: #0000FF;">&(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">+</span><span style="color: #008000;">'0'</span><span style="color: #0000FF;">),</span><span style="color: #000000;">palcount</span><span style="color: #0000FF;">,</span><span style="color: #000000;">to_skip</span><span style="color: #0000FF;">,</span><span style="color: #000000;">count</span><span style="color: #0000FF;">,</span><span style="color: #000000;">l</span><span style="color: #0000FF;">-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">r2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dd</span><span style="color: #0000FF;">)</span>
atom to_skip = count - keep,
<span style="color: #000000;">skip</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">skipn</span>
palcount = 0, l = 3
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
sequence pals = {}
<span style="color: #008080;">if</span> <span style="color: #000000;">palcount</span><span style="color: #0000FF;">==</span><span style="color: #000000;">count</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
string lhs = ""&(digit+'0') -- ie "1" or "2" .. or "9"
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
while palcount < count do
<span style="color: #008080;">if</span> <span style="color: #000000;">palcount</span><span style="color: #0000FF;"><</span><span style="color: #000000;">to_skip</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">setd</span><span style="color: #0000FF;">(</span><span style="color: #000000;">key</span><span style="color: #0000FF;">,</span><span style="color: #000000;">skip</span><span style="color: #0000FF;">,</span><span style="color: #000000;">skipd</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
integer r = rmdr(digit,l-2,0,digit)
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
{pals,palcount} = palindromicgapfuls(pals,lhs,palcount,to_skip,count,l-2,r,1,digit)
<span style="color: #008080;">return</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">pals</span><span style="color: #0000FF;">,</span><span style="color: #000000;">palcount</span><span style="color: #0000FF;">,</span><span style="color: #000000;">skip</span><span style="color: #0000FF;">}</span>
l += 1
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
end while
return pals
<span style="color: #008080;">function</span> <span style="color: #000000;">collect</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">digit</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">count</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">keep</span><span style="color: #0000FF;">)</span>
end function
<span style="color: #004080;">atom</span> <span style="color: #000000;">to_skip</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">count</span> <span style="color: #0000FF;">-</span> <span style="color: #000000;">keep</span><span style="color: #0000FF;">,</span>
 
<span style="color: #000000;">palcount</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">3</span>
constant tests = {{20,20,1},{100,15,1},{1000,10,1},{10_000,5,1},
<span style="color: #004080;">sequence</span> <span style="color: #000000;">pals</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
{100_000,1,1},{1_000_000,1,1},{10_000_000,1,1},
<span style="color: #004080;">string</span> <span style="color: #000000;">lhs</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""</span><span style="color: #0000FF;">&(</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">+</span><span style="color: #008000;">'0'</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- ie "1" or "2" .. or "9"</span>
{100_000_000,1,9},{1000_000_000,1,9},{10_000_000_000,1,9},
<span style="color: #008080;">while</span> <span style="color: #000000;">palcount</span> <span style="color: #0000FF;"><</span> <span style="color: #000000;">count</span> <span style="color: #008080;">do</span>
{100_000_000_000,1,9},{1000_000_000_000,1,9},
<span style="color: #004080;">integer</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">rmdrn</span><span style="color: #0000FF;">(</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">,</span><span style="color: #000000;">l</span><span style="color: #0000FF;">-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">)</span>
{10_000_000_000_000,1,9},{100_000_000_000_000,1,9},
<span style="color: #0000FF;">{</span><span style="color: #000000;">pals</span><span style="color: #0000FF;">,</span><span style="color: #000000;">palcount</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">palindromicgapfuls</span><span style="color: #0000FF;">(</span><span style="color: #000000;">pals</span><span style="color: #0000FF;">,</span><span style="color: #000000;">lhs</span><span style="color: #0000FF;">,</span><span style="color: #000000;">palcount</span><span style="color: #0000FF;">,</span><span style="color: #000000;">to_skip</span><span style="color: #0000FF;">,</span><span style="color: #000000;">count</span><span style="color: #0000FF;">,</span><span style="color: #000000;">l</span><span style="color: #0000FF;">-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">r</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">)</span>
{1000_000_000_000_000,1,9},
<span style="color: #000000;">l</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
{10_000_000_000_000_000_000,1,9}} -- 64 bit only
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
-- (any further and you'd need mpfr just to hold counts)
<span style="color: #008080;">return</span> <span style="color: #000000;">pals</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
atom t0 = time(), count, keep, start
for i=1 to length(tests)-(machine_bits()!=64) do
<span style="color: #008080;">constant</span> <span style="color: #000000;">tests</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #000000;">20</span><span style="color: #0000FF;">,</span><span style="color: #000000;">20</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">100</span><span style="color: #0000FF;">,</span><span style="color: #000000;">15</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">10_000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">},</span>
{count, keep, start} = tests[i]
<span style="color: #0000FF;">{</span><span style="color: #000000;">100_000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">1_000_000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">10_000_000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">},</span>
atom from = count-keep+1
<span style="color: #0000FF;">{</span><span style="color: #000000;">100_000_000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">1000_000_000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">10_000_000_000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">},</span>
string r = iff(count==keep?sprintf("First %d",{count}):
<span style="color: #0000FF;">{</span><span style="color: #000000;">100_000_000_000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">1000_000_000_000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">},</span>
iff(keep>1?sprintf("Last %d of first %,d",{keep,count})
<span style="color: #0000FF;">{</span><span style="color: #000000;">10_000_000_000_000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">100_000_000_000_000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">},</span>
:sprintf("%,dth",{count}))),
<span style="color: #0000FF;">{</span><span style="color: #000000;">1_000_000_000_000_000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">},</span>
s = iff(keep=1?"":"s")
<span style="color: #000080;font-style:italic;">-- {1_000_000_000_000_000,1,2,4}, -- (matches AppleScript)</span>
printf(1,"%s palindromic gapful number%s ending with:\n", {r,s})
<span style="color: #0000FF;">{</span><span style="color: #000000;">10_000_000_000_000_000_000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">}}</span> <span style="color: #000080;font-style:italic;">-- 64 bit only
sequence tags = tagset(9,start),
-- (any further and you'd need mpfr just to hold counts)</span>
res = apply(true,collect,{tags,count,keep})
string fmt = sprintf("%%%ds",max(apply(join(res,{}),length)))
<span style="color: #004080;">atom</span> <span style="color: #000000;">t0</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">(),</span> <span style="color: #000000;">count</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">keep</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">start</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">finish</span>
for j=1 to length(res) do
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">)-(</span><span style="color: #7060A8;">machine_bits</span><span style="color: #0000FF;">()!=</span><span style="color: #000000;">64</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
printf(1,"%d: %s\n",{tags[j],join(apply(true,sprintf,{{fmt},res[j]})," ")})
<span style="color: #0000FF;">{</span><span style="color: #000000;">count</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">keep</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">start</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">finish</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">tests</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
end for
<span style="color: #004080;">string</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">count</span><span style="color: #0000FF;">==</span><span style="color: #000000;">keep</span><span style="color: #0000FF;">?</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"First %d"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">count</span><span style="color: #0000FF;">}):</span>
puts(1,"\n")
<span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">keep</span><span style="color: #0000FF;">></span><span style="color: #000000;">1</span><span style="color: #0000FF;">?</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Last %d of first %,d"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">keep</span><span style="color: #0000FF;">,</span><span style="color: #000000;">count</span><span style="color: #0000FF;">})</span>
end for
<span style="color: #0000FF;">:</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%,dth"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">count</span><span style="color: #0000FF;">}))),</span>
printf(1,"Completed in %s\n",elapsed(time()-t0))</lang>
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">keep</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">?</span><span style="color: #008000;">""</span><span style="color: #0000FF;">:</span><span style="color: #008000;">"s"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s palindromic gapful number%s ending with:\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">r</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span><span style="color: #0000FF;">})</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">tags</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">finish</span><span style="color: #0000FF;">,</span><span style="color: #000000;">start</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #000000;">collect</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">tags</span><span style="color: #0000FF;">,</span><span style="color: #000000;">count</span><span style="color: #0000FF;">,</span><span style="color: #000000;">keep</span><span style="color: #0000FF;">})</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">fmt</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%%%ds"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">max</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,{}),</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">)))</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">tags</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">],</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">},</span><span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]}),</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Completed in %s\n"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">))</span>
<!--</syntaxhighlight>-->
{{out}}
<pre style="font-size: 11px10px">
First 20 palindromic gapful numbers ending with:
1: 121 1001 1111 1221 1331 1441 1551 1661 1771 1881 1991 10901 11011 12221 13431 14641 15851 17171 18381 19591
Line 3,301 ⟶ 3,758:
spare time you have, leave this running and it'll look better, uncomment the reset of
count, to something that'll actually finish, and you'll start to believe. :-)
<langsyntaxhighlight Phixlang="phix">--count = 100000
while count do
count -= 1
?collect(9,count,1)
end while</langsyntaxhighlight>
 
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<langsyntaxhighlight lang="prolog">init_palindrome(Digit, p(10, Next, 0)):-
Next is Digit * 10 - 1.
 
Line 3,415 ⟶ 3,872:
print_numbers(1, 20, Numbers),
print_numbers(86, 100, Numbers),
print_numbers(991, 1000, Numbers).</langsyntaxhighlight>
 
{{out}}
Line 3,465 ⟶ 3,922:
Note: Although this uses the idea of generating palindromes from the Geeks4geeks reference mentioned in the Factor entry, none of their code was used.
 
<langsyntaxhighlight lang="python">from itertools import count
from pprint import pformat
import re
Line 3,497 ⟶ 3,954:
b = {k:v[-last:] for k, v in bin.items()}
txt = pformat(b, width=220)
print('', re.sub(r"[{},\[\]]", '', txt))</langsyntaxhighlight>
 
{{out}}
Line 3,535 ⟶ 3,992:
 
===Functional===
<langsyntaxhighlight lang="python">'''Palindromic gapful numbers'''
 
from itertools import chain, count, islice, tee
Line 3,736 ⟶ 4,193:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>First 20 samples of gapful palindromes (> 100) by last digit:
Line 3,775 ⟶ 4,232:
{{works with|Rakudo|2019.07.1}}
 
<syntaxhighlight lang="raku" perl6line>constant @digits = '0','1','2','3','4','5','6','7','8','9';
 
# Infinite lazy iterator to generate palindromic "gap" numbers
Line 3,787 ⟶ 4,244:
my @gappal = (1..9).map: -> \digit {
my \divisor = digit + 10 * digit;
@npal.hyper.map: -> \this { next unless (my \test = digit ~ this ~ digit) %% divisor; test }
}
 
Line 3,801 ⟶ 4,258:
put "$_: " ~ @gappal[$_-1][|$range].fmt("%{$fmt}s") for 1..9;
say round( now - $now, .001 ), " seconds";
}</langsyntaxhighlight>
{{out}}
<pre style="font-size:80%;">(Required) First 20 gapful palindromes:
Line 3,864 ⟶ 4,321:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX program computes and displays palindromic gapful numbers, it also can show those */
/*─────────────────────── palindromic gapful numbers listed by their last decimal digit.*/
numeric digits 20 /*ensure enough decimal digits gapfuls.*/
Line 3,894 ⟶ 4,351:
do k=1 for 9; say k':' strip( subword($.k, 1 + n - z) )
end /*k*/; say
return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the internal default inputs:}}
 
Line 3,935 ⟶ 4,392:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
 
Line 3,975 ⟶ 4,432:
 
see "done..." + nl
</syntaxhighlight>
</lang>
Output:
<pre>
Line 3,993 ⟶ 4,450:
{{trans|Crystal}}
===Brute force and slow===
<langsyntaxhighlight lang="ruby">def palindromesgapful(digit, pow)
r1 = digit * (10**pow + 1)
r2 = 10**pow * (digit + 1)
Line 4,020 ⟶ 4,477:
count = 1000
puts "\nLast 10 of first 1000 palindromic gapful numbers ending in:"
(1..9).each { |digit| print "#{digit} : #{digitscount(digit, count).last(10)}\n" }</langsyntaxhighlight>
 
===Orders of Magnitude Faster: Direct Generation of Numbers===
Line 4,028 ⟶ 4,485:
Run as: $ ruby palindromicgapfuls.rb
Optimized version, the ultimate fastest: Ruby 2.7.1 - 112.5 secs
<langsyntaxhighlight lang="ruby">def palindromicgapfuls(digit, count)
gapfuls = [] # array of palindromic gapfuls
nn = digit * 11 # digit gapful divisor: 11, 22,...88, 99
Line 4,084 ⟶ 4,541:
1.upto(9) { |digit| puts "#{digit} : #{palindromicgapfuls(digit, count).last(keep)}" }
 
puts (Time.now - start)</langsyntaxhighlight>
 
Compact version: Ruby-2.7.1 - 113.0 secs
<langsyntaxhighlight lang="ruby">def palindromicgapfuls(digit, count)
gapfuls = [] # array of palindromic gapfuls
nn = digit * 11 # digit gapful divisor: 11, 22,...88, 99
Line 4,136 ⟶ 4,593:
1.upto(9) { |digit| puts "#{digit} : #{palindromicgapfuls(digit, count).last(keep)}" }
 
puts (Time.now - start)</langsyntaxhighlight>
 
Object Oriented implementation: Ruby 2.7.1 - 113.0 secs
<langsyntaxhighlight lang="ruby">class PalindromicGapfuls
include Enumerable
 
Line 4,201 ⟶ 4,658:
1.upto(9) { |digit| puts "#{digit} : #{PalindromicGapfuls.new(digit).first(count).last(keep)}" }
 
puts (Time.now - start)</langsyntaxhighlight>
 
Versions optimized for minimal memory use: Ruby 2.7.1 - 110.0 secs
<langsyntaxhighlight lang="ruby">def palindromicgapfuls(digit, count, keep)
palcnt = 0 # count of gapful palindromes
to_skip = count - keep # count of unwanted values to skip
Line 4,262 ⟶ 4,719:
1.upto(9) { |digit| puts "#{digit} : #{palindromicgapfuls(digit, count, keep)}" }
 
puts (Time.now - start)</langsyntaxhighlight>
 
Compact version optimized for minimal memory use: Ruby 2.7.1 - 111.5 secs
<langsyntaxhighlight lang="ruby">def palindromicgapfuls(digit, count, keep)
palcnt = 0 # count of gapful palindromes
to_skip = count - keep # count of unwanted values to skip
Line 4,316 ⟶ 4,773:
1.upto(9) { |digit| puts "#{digit} : #{palindromicgapfuls(digit, count, keep)}" }
 
puts (Time.now - start)</langsyntaxhighlight>
 
OOP version optimized for minimal memory use: Ruby 2.7.1 - 116.0 secs
<BR>It creates an output method that skips the unwanted values and only keeps/stores the desired ones.
<langsyntaxhighlight lang="ruby">class PalindromicGapfuls
include Enumerable
 
Line 4,392 ⟶ 4,849:
1.upto(9) { |digit| puts "#{digit} : #{PalindromicGapfuls.new(digit).keep_from(count, keep)}" }
 
puts (Time.now - start)</langsyntaxhighlight>
{{out}}
<pre>First 20 palindromic gapful numbers 100 ending with:
Line 4,463 ⟶ 4,920:
{{trans|F#}}
0.186s on Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
<langsyntaxhighlight lang="ruby">
class PalNo
def initialize(set)
Line 4,481 ⟶ 4,938:
for n in 1..9 do palNo=PalNo.new(n); g=1; palNo.each{|n| print "#{n} " if g>85; g+=1; break unless g<101}; puts "" end; puts "####"
for n in 1..9 do palNo=PalNo.new(n); g=1; palNo.each{|n| print "#{n} " if g>990; g+=1; break unless g<1001}; puts "" end; puts "####"
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 4,521 ⟶ 4,978:
Run as: $ ruby fsharp2ruby.rb
Best Time: 437.566515299 secs
<langsyntaxhighlight lang="ruby">class PalNo
def initialize(digit)
@digit, @l, @dd = digit, 3, 11*digit
Line 4,549 ⟶ 5,006:
(1..9).each { |digit| PalNo.new(digit).show(10_000_000, 1) }; puts "####"
 
puts (Time.now - start)</langsyntaxhighlight>
{{out}}
<pre>
Line 4,620 ⟶ 5,077:
This version uses number->string then string->number conversions to create palindromes.
 
<langsyntaxhighlight lang="rust">fn palindromicgapfuls(digit: u64, count: u64, keep: usize) -> Vec<u64> {
let mut palcnt = 0u64; // count of gapful palindromes
let to_skip = count - keep as u64; // count of unwanted values to skip
Line 4,674 ⟶ 5,131:
println!("{:?}", t.elapsed())
}</langsyntaxhighlight>
System: I7-6700HQ, 3.5 GHz, Linux Kernel 5.9.10, Rust 1.48
Compil: $ rustc -C opt-level=3 -C target-cpu=native -C codegen-units=1 -C lto palindromicgapfuls.rs
Line 4,684 ⟶ 5,141:
About 2.5x faster.
 
<langsyntaxhighlight lang="rust">fn palindromicgapfuls(digit: u64, count: u64, keep: usize) -> Vec<u64> {
let mut palcnt = 0u64; // count of gapful palindromes
let to_skip = count - keep as u64; // count of unwanted values to skip
Line 4,744 ⟶ 5,201:
println!("{:?}", t.elapsed())
}</langsyntaxhighlight>
System: I7-6700HQ, 3.5 GHz, Linux Kernel 5.9.10, Rust 1.48
Compil: $ rustc -C opt-level=3 -C target-cpu=native -C codegen-units=1 -C lto palindromicgapfuls.rs
Line 4,818 ⟶ 5,275:
=={{header|Sidef}}==
Inspired from the C++ and Raku entries.
<langsyntaxhighlight lang="ruby">class PalindromeGenerator (digit, base=10) {
 
has power = base
Line 4,852 ⟶ 5,309:
say ("#{d}: ", arr.map{ "%*s" % (w, _) }.join(' '))
}
})</langsyntaxhighlight>
{{out}}
<pre style="font-size:83%">
Line 4,904 ⟶ 5,361:
{{libheader|Wren-fmt}}
Search limited to the first 100,000 palindromic gapful numbers as, beyond that, the numbers become too large (>= 2 ^ 53) to be accurately represented by Wren's Num type.
<langsyntaxhighlight ecmascriptlang="wren">import "./fmt" for Conv, Fmt
 
var reverse = Fn.new { |s|
Line 4,963 ⟶ 5,420:
}
System.print()
}</langsyntaxhighlight>
 
{{out}}
Line 5,021 ⟶ 5,478:
8: 80869644696808 80869655696808 80869666696808 80869677696808 80869688696808
9: 96877711777869 96877800877869 96877899877869 96877988977869 96878077087869
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang "XPL0">func Palindromic(N); \Return 'true' if N is palindromic
int N, I, J, S(10);
[I:= 0;
while N > 0 do
[N:= N/10;
S(I):= rem(0);
I:= I+1;
];
J:= 0; I:= I-1;
while J < I do
[if S(J) # S(I) then return false;
J:= J+1; I:= I-1;
];
return true;
];
 
int Lo, Hi, Task, Mul, N, Cnt, Prod;
[Lo:= 0; Hi:= 20;
for Task:= 1 to 2 do
[Mul:= 11;
repeat N:= 1; Cnt:= 0;
loop [Prod:= N * Mul;
if Prod >= 100 then
if rem(Prod/10) = Mul/10 then
if Palindromic(Prod) then
[Cnt:= Cnt+1;
if Cnt >= Lo then
[IntOut(0, Prod); ChOut(0, ^ )];
if Cnt >= Hi then quit;
];
N:= N+1;
];
CrLf(0);
Mul:= Mul + 11;
until Mul > 99;
CrLf(0);
Lo:= 86; Hi:= 100;
];
]</syntaxhighlight>
{{out}}
<pre>
121 1001 1111 1221 1331 1441 1551 1661 1771 1881 1991 10901 11011 12221 13431 14641 15851 17171 18381 19591
242 2002 2112 2222 2332 2442 2552 2662 2772 2882 2992 20702 21912 22022 23232 24442 25652 26862 28182 29392
363 3003 3333 3663 3993 31713 33033 36663 300003 303303 306603 309903 312213 315513 318813 321123 324423 327723 330033 333333
484 4004 4224 4444 4664 4884 40304 42724 44044 46464 48884 400004 401104 402204 403304 404404 405504 406604 407704 408804
5005 5115 5225 5335 5445 5555 5665 5775 5885 5995 50105 51315 52525 53735 54945 55055 56265 57475 58685 59895
6006 6336 6666 6996 61116 64746 66066 69696 600006 603306 606606 609906 612216 615516 618816 621126 624426 627726 630036 633336
7007 7777 77077 700007 707707 710017 717717 720027 727727 730037 737737 740047 747747 750057 757757 760067 767767 770077 777777 780087
8008 8448 8888 80608 86768 88088 800008 802208 804408 806608 808808 821128 823328 825528 827728 829928 840048 842248 844448 846648
9009 9999 94149 99099 900009 909909 918819 927729 936639 945549 954459 963369 972279 981189 990099 999999 9459549 9508059 9557559 9606069
 
165561 166661 167761 168861 169961 170071 171171 172271 173371 174471 175571 176671 177771 178871 179971
265562 266662 267762 268862 269962 270072 271172 272272 273372 274472 275572 276672 277772 278872 279972
30366303 30399303 30422403 30455403 30488403 30511503 30544503 30577503 30600603 30633603 30666603 30699603 30722703 30755703 30788703
4473744 4485844 4497944 4607064 4619164 4620264 4632364 4644464 4656564 4668664 4681864 4693964 4803084 4815184 4827284
565565 566665 567765 568865 569965 570075 571175 572275 573375 574475 575575 576675 577775 578875 579975
60399306 60422406 60455406 60488406 60511506 60544506 60577506 60600606 60633606 60666606 60699606 60722706 60755706 60788706 60811806
72299227 72322327 72399327 72422427 72499427 72522527 72599527 72622627 72699627 72722727 72799727 72822827 72899827 72922927 72999927
80611608 80622608 80633608 80644608 80655608 80666608 80677608 80688608 80699608 80800808 80811808 80822808 80833808 80844808 80855808
95311359 95400459 95499459 95588559 95677659 95766759 95855859 95944959 96033069 96122169 96211269 96300369 96399369 96488469 96577569
 
</pre>
 
=={{header|zkl}}==
Using ideas from the Factor entry
<langsyntaxhighlight lang="zkl">// 10,True --> 101,111,121,131,141,151,161,171,181,191,202, ..
// 10,False --> 1001,1111,1221,1331,1441,1551,1661,1771,1881,..
fcn createPalindromeW(start,oddLength){ //--> iterator
Line 5,042 ⟶ 5,563:
if(p%10==endsWith and (p%div)==0) p else Void.Skip
})
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">println("First 20 palindromic gapful numbers:");
[1..9].apply(palindromicGapfulW).apply("walk",20) : pgpp(_);
 
Line 5,054 ⟶ 5,575:
m,fmt := (0).max(table.apply((0).max)).numDigits, "%%%dd ".fmt(m).fmt;
foreach d,row in ([1..].zip(table)){ println(d,": ",row.pump(String,fmt)) }
}</langsyntaxhighlight>
{{out}}
<pre style="font-size:83%">
Line 5,090 ⟶ 5,611:
9: 9675005769 9675995769 9676886769 9677777769 9678668769 9679559769 9680440869 9681331869 9682222869 9683113869
</pre>
<langsyntaxhighlight lang="zkl">/* We can also thread the whole mess, which for this case, is a 3.75 speed up
* (3 min to 48sec) with 8 cores (Intel 4/4).
*/
Line 5,099 ⟶ 5,620:
.apply("noop") // wait for threads to finish
: pgpp(_);
}</langsyntaxhighlight>
{{out}}
<pre style="font-size:83%">
9,482

edits