qW8|Z|$\40g`4eR`<`(Tx8`#CT#DIV!#IO1#LXA#PPQ#PWa#RLq#RTL#TRAP#SM#WSID#QNULL^#QQUOTE#SE#MP#ML#PATH#WX!#USING1#AVUA#TNAME\
Y""""+D$t04"D:"" (pPXPp\#4^D\t8D48D$4C|~PX\0g| Dp(|#
6#k%'z#u#_abcdefghijklmnopqrstuvwxyz.l#0123456789$"ABCDEFGHIJKLMNOPQRSTUVWXYZY#{ }"7#h#[/?#\@#<d"=e">`"("'"-+?
"t#~!!s#%*#
#""("")"*"""|;,q#r#R#K#I#=#"_#9#!U#N#k#j#a"b""#& %%%%<%%%$%4%,%%@^ #":w#"!!]#)]#^#c#
"+,:[\ =
¨.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ !"#$%&'()*{}_?>;<-^abcdefghijklmnopqrstvwxyzժ]u|@ҡ~
ȝ`/Ĳ4| NetUsingHandleUReR'
$, A'+=\""p"(P
|L4 $BB 'RonaldT0(&N|R' sum of integers 1 to Y\h:|sumofmultiplesto0,.|Q1o'Ronaldt'Ronald0<#8Ol'Ronald$') nth fibonacci number = (g*n-h*n)sqrt(5)`u'8 = (g*3+(g*3)*2+(g*3)*n - (h*3+(h*3)*2+(h*3)*n))sqrt(5)8+|Q2'Ronald0'# Let g=golden ratio = (1+sqrt(5))2\' Let h = 1-g = -1gH/'5 we want fib(3)+fib(6)+fib(9)+...+fib(3i)+...+fib(3n)T'< = ((g*3(1-g*3n))(1-g*3) - h*3(1-h*3n)(1-h*3))sqrt(5)\c'Ronald'd = (g*3(1+g*3)-g*(3n+3)(1+g*3) - h*3(1+h*3) + h*(3n+3)(1+h*3))(sqrt(5)(1+g*3)(1+h*3))X>H'# replacing the geometric series ....'( Putting the fibonacci identities in ... 0|D"R%?(R]#]# = (g*3(1+h*3)-g*(3n+3)(1+h*3) - h*3(1+g*3) + h*(3n+3)(1+g*3))sqrt(5)U'Ronald
NC|n|sumofevenfibonacci'? returns the sum of the first Y fibonacci numbers that are evenh('0 this is the same as every 3rd fibonacci number,d'4 since odd+odd=even, odd+even=odd, even+odd=odd, ...c'0 so it simply sums fib(3), fib(6), ..., fib(3Y)yD'? To make the function faster, the following derivation holds...<4S(6 R!((fib 3)-(fib 3n+4)-(fib 3n+1))((1-h*3)(1-g*3))%' Using the fibonacci formula,|'Ronald'^ = (g*3 + 1 - g*(3n+3) - g*(3n) - h*3 - 1 + h*(3n+3) + h*(3n))(sqrt(5)(1+g*3)(1+h*3))#'T = (g*3 - h*3 - g*(3n+3) + h*(3n+3) - g*(3n) + h*(3n))(sqrt(5)(1-h*3)(1-g*3))(\ R!(((g*3)-((g*(3+3n))+(g*(3n))+(h*3)))+((h*(3+3n))+(h*(3n))))((5*0.5)(1-h*3)(1-g*3))](p R!((((g*3)(1+g*3))-((g*(3+3n))(1+g*3)))+((h*(3+3n))(1+h*3))-(h*3)(1+h*3))((5*0.5)(1+g*3)(1+h*3))$%(\ R!((((g*3)(1+h*3))-((g*(3+3n))(1+h*3)))+((h*(3+3n))(1+g*3))-(h*3)(1+g*3))(5*0.5)gN|N' as h<1, as n->infinity, h*n->0X='I therefore, take h*n negligible and solve for (g*n)sqrt(5) < 2000000 = ND'Ronald%'5 = (fib(3) - fib(3n+3) - fib(3n))((1-h*3)(1-g*3))@'9 = (fib(3) - fib(3n+3) - fib(3n))(1-g*3-h*3+(g*3)h*3)s(H '= now take h*n into account, h is negative and less than 0, sod '+ h*n is positive, and magnitude less than 1!!'+ h*n is negative, and magnitude less than 1P!Qh!'> = (fib(3) - fib(3n+3) - fib(3n))(1-g*3-h*3-1) since gh=-1 !'I = (fib(3n+3) + fib(3n) - fib(3))(((1+sqrt(5))2)*3+((1-sqrt(5))2)*3)<$"'] = (fib(3n+3) + fib(3n) - fib(3))((1+3sqrt(5)+35+sqrt(125)+1-3sqrt(5)+35-sqrt(125))8)"'* = (fib(3n+3) + fib(3n) - fib(3))(328)`u #'% = (fib(3n+3) + fib(3n) - fib(3))4Ht#' = (fib(3n+3) + fib(3n) - 2)43#$ =K$(o now find the sum of the first
#n3 even fibonacci numbers, since the first n fib numbers are within the boundsW'4$(6 R!((fib 3)-((fib 3+3n)+(fib 3n)))((1-h*3)(1-g*3))<:<%'Ronald%X&"0Xo$n'|Q5'Ronaldp1{L&BH(&&'(k '"/ is to take the lowest common divisor of the array, the array is s#20, which is the sequence from 1 to 20p&'Ronaldd&'>q,gp:qggp:@#W^
B`$|&'':
J (@H'Ronald('@([|A-("
'RonaldX(('Ronald)X((0Cx@|Q16'Ronald)<)'Ronald)T)l)'Ronald))'Ronald-))'Ronald))'% The returned array is then disclosed#,*'X (since the / operator modifies the function to only be able to return a single element)<|*'O so the array is actually enclosed within an array with no dimensions/axis/rankPs*' +/ to sum all digitst+'Ronaldd-*+0)Hh|Q20'? Similar to question 16, but multiply sequence 1 to 100 instead,'= Returns an array giving the number of factors of each numberp,' in the range (X,Y],' X defaults to 0i-'Ronald+L- X-"'Ronald0+-(-"'Ronald-- +|T' initialise range/t:;'Ronald;;'R upper bound of primes needed to test the largest integer for primality testing: Y
<'Ronald>;<' represents to max of:;(<'\ square of prime (since smaller multiples of the prime are already struck by smaller primes)c<'G the smallest multiple of the prime within the "range", aka more than Xzt='c normalized as the sieve array index, and normalized as 2prime smaller than actual starting number='Ronald<p>'Ronald?<>'Ronald>>'RonaldH?>?'Ronald?0?'Ronald@;`?'Ronaldx??'Ronald@??'Ronald??'Ronald@? @'Ronald8@P@'Ronald@h@@'Ronald@@'RonaldA8@@'Ronald@A$($@A'RonaldA(AhA'RonaldAA'RonaldBAA'2 strike all those in the arithmetic sequence belowk(A'RonaldATB'RonaldBlBB'RonaldBB'Ronald,CB'RonaldPNx?C'RonaldCBDC'Ronald\CtC048,|Q10HnC|prime|primelist'RonaldK\C D'Ronald8DPD ; ]# Note the following implementation is much faster than . ]# the implementation in the "dfns" library : ]# This is primarily due to the interpretative overhead x} ]# The algorithm complexity itself is almost O(n)/linear time (actually, to get linear time, Euler's sieve should be used)? ]# But the interpretative complexity here is O(sqrt(n)) time B ]# The "dfns" implementations interpretative complexity is O(n)'RonaldLLhDK@$K8|bsearch'RonaldK4L'RonaldL8DdL'RonaldlMML'RonaldRPL'RonaldLL'Ronald|L$M'RonaldMMTM'RonaldM100} bsearch 25000/"(1 1000000000098) " 1 12 30 24 60 60 1000"#TS-T| U'Q The time required has been tested, both the implementation in dfns, and this oneU'6 It has been statistically tested using "R" (freeware)hV'N The result is that there is extremely significant evidence that this functionT#V' is more efficient. And...
@W'Q we estimate that on average this function takes between 557 and 916ms less time.W'> timing.df> X' time methodf4X'1 5878 iterativeRpX'2 6096 iterativeHY\X'3 5751 iterativeXX'4 6550 recursiveYY$Y'5 6537 recursiveHY`Y'6 6532 recursivetY'7 5915 iterativeYY'8 5826 iterativetZYZ'9 5773 iterative8ZPZ'10 6574 recursiveZXZ'11 6854 recursiveZZ'12 6742 recursive[Z['13 7003 recursive([@['14 6284 iterative[d[|['15 5889 iterative[['16 5790 iterativeX([['17 5783 iterative\0\'18 6644 recursive\T\l\'19 6659 recursive\\',> timing.fit<-lm(time~method,data=timing.df)tԭ\'> anova(timing.fit)d/8]'Analysis of Variance TableH1Dt]'Response: time1]'. Df Sum Sq Mean Sq F value Pr(>F)Ha]'2method 1 1478290 1478290 86.14 6.634e-06 ***"4H^'Residuals 9 154454 17162dJ^'---xP^(>Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1_'> summary1way(timing.fit)|_'ANOVA Table:Oz_'D Df Sum Squares Mean Square F-statistic p-value,\0`'BBetween Groups 1 1478289.60303 1478289.60303 86.13959 1e-05`'-Within Groups 9 154454.03333 17161.559260^a'!Total 10 1632743.63636<`a'Numeric Summary:|a'; Sample size Mean Median Std Dev Midspread\a';All Data 11 6207.818 6096 404.0722 691.5\cxHb';iterative 6 5873.167 5852 125.3881 119.5bb';recursive 5 6609.400 6550 137.6982 37.0bc'4Table of Effects: (GrandMean and deviations from GM),tc' typ.val iterative recursiveXc'6207.8182 -334.6515 401.5818d+Ld'> ciReg(timing.fit)\]`d'0 95 % C.I.lower 95 % C.I.upperQd'0(Intercept) 5752.1833 5994.1500X4=d'0methodrecursive 556.7861 915.68064eLe'RonaldReSp(:s' Technical Notes:XXe' Variances appear the same,f'X Data not normally distributed, but central limit theorem means average is normal enough*pf'Ronald`,Cf
l gL<0
'Ronaldghg'u> timing.df<-data.frame(time=c(5878,6096,5751,6550,6537,6532,5915,5826,5773,6574,6854,6742,7003,6284,5889,5790,5783,6644,6659),method=factor(c("iterative","iterative","iterative","recursive","recursive","recursive","iterative","iterative","iterative","recursive","recursive","recursive","recursive","iterative","iterative","iterative","iterative","recursive","recursive")))g'Ronald|jg8i' R input/output:Rhi :Field Private sievedto!10000000'RonaldPidj'Ronaldq#0gp:qdrgr:$=sgp:rtW3B`$nnnoa*J,o@CH0wDM|Q3%X=|aB
|o'Ronaldqpo'Ronaldno'RonaldPpop'Ronald p8p'Ronaldo php'
:EndWhile,{p'Ronaldpp'Ronaldop'Ronaldun,q'RonaldDq\q'Ronaldqtqq'Ronaldqq'Ronalddrqq'Ronaldrr'Ronald|w4rLr'I this is accurate until (((1+5*0.5)2)*Y)5*0.5 has an error of almost 1.(|r'O since this function can detect whether the result should be rounded up or downr'9 and the first part converges to being an integer anyways hs'; it is expected that when this function becomes inaccurate,41s'A the integer size would be too small to hold the fibonacci number|0t' below is the fibonacci formula:.t' most significant part-t') now decide which way to round the resultX/v$u'Ronaldrxu(, R!((((1+5*0.5)2)*Y)-((1-5*0.5)2)*Y)5*0.5|u'K however, note that ((1-5*0.5)2)*Y is always less than 1, converges to 0,K(v') and is -ve for Y even, and +ve for Y odd8@}v'L so ignore that, then round up or down depending on whether Y is even or not8v'Ronalddrdw0Ip|runall'Ronalduw8(&+|Q4'Ronald|wx' current unfactorised portionDx', largest factor found (1 is always a factor)]x'A algorithm is O(max(2nd largest factor,sqrt(largest factor)) timeHܹx'M But slow due to interpretative complexity - worst case interpreting the loopPLy(# n!N ]# current unfactorised portion<y(: maxfactor!1 ]# largest factor found (1 is always a factor)$H4z(H :If 0=2|n ]# remove 2, so that it is no longer a concern (it is not odd)p,z( n!maxfactor!2`
{(1 :While n`"1 ]# while there are factors to be foundi{(B sqrtn!
#n*0.5 ]# largest factor not 1 or n, that could be foundp{_d|(c maxfactor!3#maxfactor ]# in case maxfactor is 1 or 2, maxfactor starts from last known position<}(0 :While maxfactord"sqrtn ]# while less than...x~(l :If 0=maxfactor|n ]# if is factor (we know it is prime, as we test from smallest odd numbers upwards'~(/ :Leave ]# process this prime factorto' :EndIfA(> maxfactor+!2 ]# not a factor, go to next odd candidateH' :EndWhile1`(X :If maxfactor>sqrtn ]# if we tried to start after largest possible factor not 1 or ntsr$(> maxfactor!n ]# n must be the next largest prime factoreԀ(. n!maxfactor ]# remove factor found from n;( R!maxfactorX$'Ronald,xd'> Below is my original method. Overall complexity is O(sqrt(n))"( R!Q3;N;n;maxfactor;sqrtn,' another solutionp.XXX' 1,000,000 times (sqrt(n))_'Ronald,x0| " P|x\|y': Extremely brute force solution, quite slow (many seconds)p(3 R!#/",/,/{(u#=10"=#((6)/10)"u#)/u#}{u#".u#}99+s#900
ԅ'? It first finds products of all combinations of 3 digit numbersX,d(L call this u#, encodes it base 10, reverses it, and compares it to original u#̆( replicate the matrix of booleans with original u# to get matrix of possible answers (palindromes, product of 2 3-digit numbers)W'* then ravel twice to turn it into an array5' disclose, and find maximumy'RonaldL'Ronaldĉd|'Ronald'D previous solution can do same problem for n=4 faster that one below ܉'RonaldDqH'Ronald`x'Ronald'Ronald؊'Ronald'Ronald 84Hz|digitarraydd'RonaldP'Ronald̋ :EndClassL;pH"&p"l"(0"
'\ Digit array refers to a number with each digit being represented as an element in the array[Ќ'G This allows the array to represent arbitrarily large positive integers@T' Divide to collect all overflowT|č' If overflow is present ...pElW'% Remove overflow from the current col#P'1 Add overflow to the next more significant column** arrays with fewer elements => less processing"Y'Ronald|'Ronald'RonaldĽܽ'RonaldĽ'ms*<'Ronald$h'RonaldȾ' PublichI|fibonacci:Class fibonacci|fib :EndClass'Ronaldп ' sum of first n fib numbersI,y0' Find n:L$t'& returns largest n, such that fib(n)infinity, h*n->0(J]# therefore, take h*n negligible and solve for (g*n)sqrt(5) < 2000000 = N(>]# now take h*n into account, h is negative and less than 0, so( " R!fibindex N;g;n' :Access Public' ' ' ' ( g!(1+5*0.5)2( n!N(5*0.5)( n!g_#n(> :If (2|n)=0 ]# h*n is positive, and magnitude less than 1( n!#n' :Else(; n!
#n ]# h*n is negative, and magnitude less than 1' :EndIf( R!n( "(@]# returns the sum of the first Y fibonacci numbers that are even(1]# this is the same as every 3rd fibonacci number,(5]# since odd+odd=even, odd+even=odd, even+odd=odd, ...(1]# so it simply sums fib(3), fib(6), ..., fib(3Y)(@]# To make the function faster, the following derivation holds...($]# Let g=golden ratio = (1+sqrt(5))2(]# Let h = 1-g = -1g(*]# nth fibonacci number = (g*n-h*n)sqrt(5)(6]# we want fib(3)+fib(6)+fib(9)+...+fib(3i)+...+fib(3n)(9]# = (g*3+(g*3)*2+(g*3)*n - (h*3+(h*3)*2+(h*3)*n))sqrt(5)($]# replacing the geometric series ...(=]# = ((g*3(1-g*3n))(1-g*3) - h*3(1-h*3n)(1-h*3))sqrt(5)(7]# R!((fib 3)-(fib 3n+4)-(fib 3n+1))((1-h*3)(1-g*3))(S]#]#]# = (g*3(1+h*3)-g*(3n+3)(1+h*3) - h*3(1+g*3) + h*(3n+3)(1+g*3))sqrt(5)(]]# R!((((g*3)(1+h*3))-((g*(3+3n))(1+h*3)))+((h*(3+3n))(1+g*3))-(h*3)(1+g*3))(5*0.5)(e]# = (g*3(1+g*3)-g*(3n+3)(1+g*3) - h*3(1+h*3) + h*(3n+3)(1+h*3))(sqrt(5)(1+g*3)(1+h*3))(q]# R!((((g*3)(1+g*3))-((g*(3+3n))(1+g*3)))+((h*(3+3n))(1+h*3))-(h*3)(1+h*3))((5*0.5)(1+g*3)(1+h*3))(_]# = (g*3 + 1 - g*(3n+3) - g*(3n) - h*3 - 1 + h*(3n+3) + h*(3n))(sqrt(5)(1+g*3)(1+h*3))(U]# = (g*3 - h*3 - g*(3n+3) + h*(3n+3) - g*(3n) + h*(3n))(sqrt(5)(1-h*3)(1-g*3))(]]# R!(((g*3)-((g*(3+3n))+(g*(3n))+(h*3)))+((h*(3+3n))+(h*(3n))))((5*0.5)(1-h*3)(1-g*3))()]# Putting the fibonacci identities in ...(6]# = (fib(3) - fib(3n+3) - fib(3n))((1-h*3)(1-g*3))(7]# R!((fib 3)-((fib 3+3n)+(fib 3n)))((1-h*3)(1-g*3))(:]# = (fib(3) - fib(3n+3) - fib(3n))(1-g*3-h*3+(g*3)h*3)(?]# = (fib(3) - fib(3n+3) - fib(3n))(1-g*3-h*3-1) since gh=-1(J]# = (fib(3n+3) + fib(3n) - fib(3))(((1+sqrt(5))2)*3+((1-sqrt(5))2)*3)(^]# = (fib(3n+3) + fib(3n) - fib(3))((1+3sqrt(5)+35+sqrt(125)+1-3sqrt(5)+35-sqrt(125))8)(+]# = (fib(3n+3) + fib(3n) - fib(3))(328)(&]# = (fib(3n+3) + fib(3n) - fib(3))4(!]# = (fib(3n+3) + fib(3n) - 2)4(9 " R!sumofevenfibonacci Y ]# sum of first n fib numbers' :Access Public' ' ' ' ' ' ' ' ' ' ' () R!((fib 3+3Y)+(fib 3Y)-(fib 3))4( "PX|t0gtfibonaccitLUZp0gDfibonacci@`RDdȾrPsstttvvvLw\u`udR0ȈfibdY[!~qluy}gp:qrgq+og
g
g
g
gg
g
gg
g
gg
g
g
ggp:```WWWaWaraWW^
goW
r^
gp:pgogp:pgoSB`$пR+J@DUYdbDȾ<,\ DP!!8TfibindexDNgn[!qt}gp:qrdsdtgy+og^
gg^
g
gg
gg
gg
g
g
gs:`WWWaWgt:r`WWagt:s tg
go`W
taW^
gt:tgogt:t^
gogp:tsB`$4TпR+J(|@DUY2bD\Ⱦx,<`|X0 % ""#\###dp8phsumofevenfibonacci[!q"&'+/348<@DHLPQqgp:qr^
g+og
g
g
g
gg
gg
g
gg
gg
g
gg
g
g
gg
g
gg
g
gg
g
g
gg
g
g
gg
g
g
g
g
g!
g"
ggp:``$W$Wra`$Wra`$Waa%WSB`$пR+J@DUY4`b($p,HDd\$0t8,0D\4t(dDP@D48L8dT| |H(,`,XHxx$$%nq+,17;Ugp:qdrdsggr:Wgs:$=ug
gp:sw`sxra W3B`$пR+JD@xH'K now R contains between 13 and 24 base 10 digits, we want only the first 10tK|'! set back to a more "normal" base|0'M add the two base 10*12 digits together (with first digit multipled by 10*12)|$<'' now R contains those digits in base 10XF'2 turn the first 10 digits into a number for output4'Ronald`'Ronaldx's 2*40 used to reduce multiply operations for greater speed (92*40 fits into the size of a double without rounding)H_"RX\'- Multiply array using the digitarray function3'/ Therefore the returned array is then disclosedLp(D (/s#12),(/12+s#10),/((6s#13)+16)+"s#6 is actually the same as s#1004'7 except groups of 6 elements are pre-multipled togetherd'] (with the first two groups containing 1-12 multipled together, and 13-22 multiplied togetherD'6 This reduces the workload on the da.multiply functionV'_ we know da.multiply is slower, because it operates on large arrays, so we smartly pre-multiplyL,(g if we wanted to do the same thing, but up to some larger N, we can add the term ,100+s#N-100 to the end'2 so we can extract the digits from the string data7 d)8!|Q8data'Ronaldx48|Q8'RonaldLBHd4h\H8P |L(+ u#[... ...] get the digits at those indiceso'7 the return from the dynamic function then is processed,'E / multiply each row (so we get all products of 5 consecutive digits$#( #/ we want maximumgd.qYZegp:qdrggr:$=s^
gp:@@WoLb`#`WLa La8D`WJ#Lacrorwxg
g
g
gg
g
g
g
gg
gg
g
g
d3B`$d+J@4H(3 s#(1-z#)+t#u#: indices of number of different products(S ".+ combines 2 above expressions, so each row contains 5 consecutive digitsh'D the rows contain all combinations of consecutive indices`8(A (1-h#s#z#) indices of number of consecutive digits, starting from 0'0 The above expression does the following things:_P'Q da.digitizestring Q8data: extract data from string, and format as integer digits1'O 5 (on the LHS of a dynamic function - number of consecutive digits to multiply$'Ronald84h|Q18 P`t(|Q18data' this is a bottom-up approachتX'z ie. instead of taking routes from the top of the triangle, it considers routes from the bottom of the triangle to the topWld'D it consists of a dynamic function operating between 2 adjacent rows ' of the trianglet'A the upper row has its values redefined to be its original valuesmt'Q plus the maximum total possible from the bottom of the triangle to that position'O therefore, at the end, the number left is the maximum total from bottom to top\+"K"_@"/R"#W
"R/A"K""XMI?C"cAF\" ))8S(PF!"
)0H!/ %^"5G,A+[4a3"F!MIN'D9"
[G4&[+:20"?BDY5CIEW(">b FbI]&5<'Ronald'6 {... ...}/ dynamic function operating between 2 rows( z#+ add its own value$l(+ s#t#z# one possible previous location|(9 u#[s#t#z#] max total coming from that previous location}(2 1!u# max totals of other previous location(K u#[s#t#z#]#1!u# max totals from bottom to this location (excluding value here);d$(( "" don't want it having a rank='Ronald;9\2H\0L\|dD': uses an programming approach called "dynamic programming"41'RonaldtH~qklgp:qggp:33oLLb# LcW%Luo@sgg^
gg^
g^
gg^
g^
gg^
g^
g^
gg^
g^
g^
g^
g^
g^
g^
B`$xHrm+J@H', Basically, each step, you go down or acrossH'. You step down 20 times, and go right 20 times 'C the direction you step each time can be expressed as DRRDRDDRDD.../\ '3 each such string uniquely maps to a distinct route" 'R therefore, actual problem is number of ways 20 D's and 20 R's can be put in orderȵt4$
' that is ((!40)(!20))!20]Q
8()l|Q15' Dynamic programming approach|'+ it basically goes level by level downwardsPP'D routes to each point = routes to left point + routes to point above0'! +/ scan neatly happes to do this$U'1 do this N times, with a starting seed of (N+1)/1(\'G the last value happens to be it (hence the reverse, take and disclose)@( R!"1!=#(+\c#N)(N+1)/1{(
'Ronald`x
' or 40C20D
'L can also think of 40 letters, 20 of which we choose to be D, the rest are R
'! and that gives us a unique routeDP'Ronald
'E---------------------------------------------------------------------L'5 but uncommented solution above is faster, and better<'Ronald
'I use digitarray functions for even larger N, or big in the "dfns" libraryr'Ronald@'RonaldX<|sums' sum of squares 1*2 to Y*2Q$|summations:Class summations :EndClass 8$nh|Q6H)|sumsquares1to'RonaldtH<`0|sum1to"dR>q#Bgp:qdrgr:$=sgp:``rtWaWarwW3B`$$t}{+J@H'Ronald'Ronald'Ronaldd'Ronald4L'Ronald4|'QRPA'Ronald'RonaldL'Ronald4'Ronald)d'Ronald|'o gets the residues mod those primes, the residues that =0 are factors of n, only keep factors that are relevant}?'Ronald\ dK0%|Q11data'Ronaldt'G quite simple, the comments above show the direction each line looks at
p%(% (s#(1-num)+(t#Q11data)[1])".+(1-h#s#num)LwX(I (1-h#s#num) counts the 4 numbers to multiply (starts from 0, ie. 0 1 2 3),(@ (s#(1-num)+(t#Q11data)[1]) index of the first of each group of 4'E inner addition, to make a matrix, where the rows are the groups of 4=0'3 up/down simply makes those indices the row indices') left/right makes them the column indicesv' then x/ the correct axisLmP(. and find the #/#/ maximum of the whole matrix', for the diagonal ones, similar concept, butxLS(` ((1-h#s#num),1-h#s#num) does the indices of each group of 4 (both axes simultaneously incremented)ql(2 ((s#(t#Q11data)[1]+1-num)".,s#(1-num)+(t#Q11data)[2])T'. refers to starting indices of each group of 4HU$^'4 but outer concatenated, to form the x and y indices`08(+ then ".+ outer add to form all groups of 4( and R##/#// as usual'3 the other diagonal is almost exactly the same, butkh( ((1-h#s#num),=#1-h#s#num)3 ](% notice the =# reverse on one of them.`2Lw8:|Q11' Similar to Q8'" left,up / right,down (diagonally)h '" left,down / right,up (diagonally) T4 ' left/rightl |num'Ronald0)t 'Ronald !'7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450/"a&(KN42M[11c(Q9Q1I7O]G(C5X1
$A4F_<*ED8 8G%$[G3C?Y)\$6((B!
P/ _?^'?([B1^7:BIcaNN`SX"Y?H$ KL,-#=!a"!_N5KC^P> 58\'*`#/7:X6$U9V80#GY,,%,<:36:PQD^/EI\
V4MY7(4Sa#ca9 O!bBX$DW9>H.!C.7 ?]5E*I&'^H. (>L$E$)HX">cERC;UJ$I#NZJ1G0VQ96F6GS36E\!0=+4YC0dX$h4xD̠Tܡ d0t@ȤPإ`,p<ĨLԩ\(l8|HЭX$h4xḎTܲ d0t@ȵPض`0DXp(Hh(@('('Ronald0)('Ronald) !):|t'Ronald* h)'Ronald))'Ronald`*))`H|Qs'ms)tt^*'Ronald)H*': d&8zx*'Ronald+)*'Ronald**'Ronald+*+' but always leave last elementHd4+' remove them8|+'Ronald++bHCC`0CPA>q#2gp:qdrgr:$=sgp:@rtW3B`$+,+,J`,@CH'RonaldC|,'1 jack up the base, because it makes it run faster(,'Ronald,-'Ronald-0-H-'Ronald`-x-02|runallxp|Y'Total time elapsed: -'Ronaldp0`-0.'RonaldH.`.' all possible question functions`U.'$ find which question functions exist.' start total timer<$/' test each function`/' stop total timerp./' print results of each functionbLm/'
time summary 0'Ronald0x.X00"'Ronaldp00'Average times:AH0'Total Average time taken: ]1--,.)&./\w1*PH1p<=Hz{.gpqdrggs:#W^
gs:s^o`LWa@sPo3Gron=W!0LeoGs^
ggr:o`q!` W saa Lo3!@
o3GzoG#qg222Wgg`` sa!Wa 3!@
so`2W!`0La!Wa!`L
Wa!`2WaoG`@b Wcrbd# scaqggW!`0
Wo`@La L
o`*bWcrabd Wca!Ws@`$`1143,J3@,.-'Ronald?H.43'RonaldL3d3HNLNNQ\lQL;QR
g?
g@
gA
gB
gC
gD
g8
gE
gF
gG
gH
gI
g8
gJ
gK
gL
gM
gN
gO
gP
sJ`$34,9,J<8@NHNN'! array of candidate prime factors 8'8 add list of primes up to next power of 10 as candidatesY`8'Ronald>|3,9(K]# it is slower than commented alternative below (10 times longer to run)g^\9(5]# however, this one has better worst case scenario:(-]# as interpretative complexity is O(log n)\=:(K]# in worst case, for similarly sized N this solution is 100 times faster4;'U Edit: this is now faster, because I have created a compromise, it is trial division,;'X but using arrays at a time, each array of primes including the next power of 10 upwardsft<'0 this removes much of the looping inefficiencies"<'P while ensuring that if not required, larger primes are not trial divided into nDL=' no new primes to addB=' no primes to return>'8 split each prior digit into its five constituent digits@>' make our digit arrayN>'RonaldD9>'j 402*25=2*1000, so we create an array of forty 2*25, and multiply them all together for faster processing%?'RonaldAD9?' change base back to normal8?$PA@'R large base for faster processing (1+10E14)-10E14 returns 1, so this is good stilld@@'p exit while loop when newfactors is empty (ie. we have divided all prime factors as many times as we can into n)D@'Ronald?TAr:p(,.4;AP'Time elapsed: 0]A'Ronald@ClAAnp().5ALgpqdrggr:?g/W!0qgr:`V-?ragW!`0ra!Ws@`$ABA-JB@,.p(' N: number to factorisepB$[P|decompose'RonaldA(C' get max of prime decompositionTXC'RonaldLL3C'H after decompose, we [1] because return is made of (primes powers) array=C'RonaldC@D' add new factors foundlpD' put in corresponding powers|D'% remove all factors found from n oncelQD' get factors dividing still\4DE' record mask from endİE'' keep those factors still dividing onlyE'& while got some factors dividing still%F'$ increment powers with mask from endmhF' remove factors dividing from n0F' find factors still dividingL8F'RonaldGXD@G'RonaldXGpG(: factors ! 1+power of prime that divides into each numberzG'Q drop those powers of primes-1 (except rotate to drop, since we need to reuse Ts)N'
double rangeN#|R(O :Field Private primes!0t#0ss 'RonaldQN@P'< here T represents number of times a prime divides its indext4pP'+ eg. for p=2, T=0 1 0 2 0 1 0 4 0 1 0 2 ...P'Y and T+1 represents number of times a prime divides the index-th number the prime dividesH0(Q'RonaldXPQ'0 convert date to number of days since 1 Jan 1900<Q#lV4R' years since 1900\a\R#m8OVR#RR"cR', days considering only years (365 days/year)S(H but it adds 1 for every year divisible by 4 (
#(R+3)4) due to leap yearp{dS($ except on centuries: -(
#(R+99)100)zT"<T' days in each month of the yearU,T'/ adds day to February if this year is leap yearbU' gets cumulative days per monthhC`U' add days in months fully passedUU'd add days in current month passed (-1 because today not passed, but +1 for later as today is Monday)zU': Sundays are congruent 0 mod 7, Mondays 1 mod 7, and so on|V#+DRnV(p unless it is divisible by 400:+(
#(R+299)400) Note: 299 so that 2001 (which means 2000 has passed) would make 1 iW'# assumes includes from, excludes to\X' convert both dates`\X"|-X'= compares the weekday you want to count, to the starting date`Z,X'RonaldmXP(Y'8 if starting date is fortuitously the weekday of concern9XY'. its like there are 6 extra days in the periodhNY'= every extra day past 1 past the weekday is like an extra dayYZ' effective days|<xZ'& each effective week gets counted oncelQZ|N|CalB|dateToDay'[ get primes up to X (at least 3 so we have something to start with, so long as Y>=3 though)<T['B end is the last number in the range we are currently dealing withd|[' gets those initial primesD\': while we have primes in our pl(prime list) to account for0bX)\'7 p is prime, i is corresponding index of prime in sieved\' initialize T for use belowpEL]', refill pl with new primes in the next range@dH]'. end of last range becomes start of this rangehNH]'x we can easily find primes up to square of end of last range (since all primes, and only primes have 1 up to that range)|D<^(T tests for 1 (means it is a prime), and converts it to index form (start+s#end-start)^'0 R now holds results (it is the processed sieve)d_'$ create dates we are concerned with:`8x8x|Q19HdKCII:MKKD`0a4b8Ob Jb\(K cdJJKNhNdcc@dde$fgL;pggthh,iiNO'U notice that code below is not wrapped up in a function like many of my other answers*$,a'v this is because this is too specialized, I only wrap answers in functions if they are useful in more general contexts- a'& how much to start searching at a timeLb'/ numfactors contains number of factors of indexкb' start off with trival array^Db' means haven't found answer,y8c'\ get more # of factors (do that in the current range, +1 because of n(n+1) - notice the n+1)|c'- test takes # factors of each triangle number4d(I numfactors[(lower-1)+2s#1+range2] are odd numbers within the range (+1)pXd(> numfactors[(lower2)+s#range2] are corresponding even numberse'Z replicate both (2/) because each number is multiplied by number both above and below +/-1[Qe(Z then remove 1 off both ends of odd numbers (2!1=#) so that they change at different timesn){g(F and convert those with enough factors into (i+lower): /(lower+s#range)g'? representing triangle number=(i+lower)(i+lower+1)2 of courseTh'% if there are any with enough factorsHIh'd take first one (as required by problem), and calculate full triangle number (with dynamic function)L|Dinq !'-39?@OPVstz"()3>Dgp:qdrdsdtdudvdwdxggw: Wgp:
Wgr:$={gg^
g^
ggt:W^
gs:
W^
gg^
gv:W rW^
gg^
g^
g^
g^
g^
ggCop
W^
gg^
gv!:*`sWar`stWagg^
g^
g^
g^
g^
gu:`!W@vb`s!Wa#t!Wca!W%"W*!W@vb`sWa!W#Wt!Wcg^#
ggu:`uwa@`s#ta^$
g^%
g^&
gg'o
W u^'
gp:o!WJLLWoW$u^(
goggs:t^)
gt:!W^*
gEo3B`$t`i(YZ3J@l@KM:IICH'B convert to days since 1900 Jan 00, s.t. 0=7|k represents a Sundayl' then sum all boolean 1's(G= m'Ronald@Ydm'Ronaldm|mm'Ronaldmm'N have leap day this year if this year is leap year and month is March or later8m(7 leap year (as before) if divisble by 4: (0=4|"date[1])H_ln(/ but not if divisible by 100: -(0=100|"date[1])o(+ unless divisible by 400: +(0=400|"date[1])vo'/ add leap day if it has been passed in the yearp|Months|Years'Ronald,p(c 1900+s#Years is range of years, Months/ makes 12 duplicates of each year for each month of the year!}p(W (MonthsYears)t#s#Months, makes s#12 for each month, then makes 100 copies of it in orderq(Y ((MonthsYears)t#1) always the first of each month - creates appropriate number of copiesr' dates we want are now doneys'RonaldpsHtst' Public'Ronaldt0t'oneTuй`t'twovt'three0ut'four(ut'fivettu'sixtt@u'seven{\{lu'eightu'nine(uu'tenu0*udKԕ|calendar:Class calendar: :EndClassBHP`[dpp$v8`0qrtsDR\smLmDX$[.q]^dekpuv|gp:qdrdsdtggr:$=ugg^
gs:Wgt:Wgg^
g^
g^
gp:`s@W#ta``sta #sa``sta
Wagg^
gg^
g^
gp:@WW
rp3B`$wdw0t73J`x@pdp[H'Ronaldtx'and^x' make units also cumulativedcx]y'0 replace all words with their pure letter countsRDy' cumulative count is betters@y' split everything into superbasety#
0(z'b all subhundred letters: first term for full cycles of 100, second term for the last partial cycleX>p~Pz' counts 1-198Xz' seventeenp
{'forty{D{'fifty$vt{'sixtyu{'" find # letters in all numbers<100h a{"(|- |'RonaldxH|' stands for Number of Hundredsȯx|' stands for Hundred OverflowD|') add the part that says how many hundreds}'s counts "and" which is in 99 numbers in each hundred (ignoring the first), plus the overflow (for partial hundreds)<nX}'* counts letters in unit before the hundred\}'5 counts letters due to usage of actual word "hundred"$H~'2 but we still need to assign "and" if any Y[i>1]>08~'a ptc stands for partial thousands count (letters required to count to some number less than 1000)p~' full thousands count'* if Y[1]=1-99, there is no "and" assigned,0~'0 this is equivalent to and99, or andho if nh=04e<$'S this is also the case for more than Y[1], it applies to the most inferior thousandh<|'f to take this into account, below, the partial inferior thousands count, full inferior thousands countȵ'RonaldЁ`|'Ronald'Ronaldx(* ]# assumes includes from, excludes to( ]# convert both dates(' " R!day countWeekday(from to);bonus' :Access Public' ( from!dateToDay from( to!dateToDay to' (U bonus!7|from-day ]# compares the weekday you want to count, to the starting date' (K :If bonus=0 ]# if starting date is fortuitously the weekday of concern(A bonus!6 ]# its like there are 6 extra days in the period' :Else(Q bonus-!1 ]# every extra day past 1 past the weekday is like an extra day' :EndIf' (& R!to+bonus-from ]# effective days' (4 R!
#R7 ]# each effective week gets counted once' ( "(7 ]# convert date to number of days since 1 Jan 1900(O ]# but it adds 1 for every year divisible by 4 (
#(R+3)4) due to leap year(+ ]# except on centuries: -(
#(R+99)100)(w ]# unless it is divisible by 400:+(
#(R+299)400) Note: 299 so that 2001 (which means 2000 has passed) would make 1(6 ]# adds day to February if this year is leap year(U ]# have leap day this year if this year is leap year and month is March or later(> ]# leap year (as before) if divisble by 4: (0=4|"date[1])(6 ]# but not if divisible by 100: -(0=100|"date[1])(2 ]# unless divisible by 400: +(0=400|"date[1])(A ]# Sundays are congruent 0 mod 7, Mondays 1 mod 7, and so on(+ " R!dateToDay date;dayspermonth;leapday' :Access Public( :If (1`"a"date)'"(2`"a"date)( #SIGNAL 4( :ElseIf 3`"t#date( #SIGNAL 5' :EndIf' (( R!"date[1]-1900 ]# years since 1900' (e R!(R365)+(
#(R+3)4)+(
#(R+299)400)-(
#(R+99)100) ]# days considering only years (365 days/year)(W dayspermonth!31 28 31 30 31 30 31 31 30 31 30 31 ]# days in each month of the year' ' (C leapday!(2<2"date)'"(0=4|1"date)+(0=400|1"date)-(0=100|1"date)' (D dayspermonth!+\0,dayspermonth ]# gets cumulative days per month' (? R+!dayspermonth[2"date] ]# add days in months fully passed(A R+!leapday ]# add leap day if it has been passed in the year(u R+!3"date ]# add days in current month passed (-1 because today not passed, but +1 for later as today is Monday)( "PԕX|0g<calendar؞xUZ0gcalendar@`Bl4tDXXXYDY|-Y\`ZZZ4Rday04countWeekday0fromtolbonus[!0КTdateToDayNrfouv|gp:qr`stadugk+og^
gg^
gs:ysgt:ytggu:
W
sq^
ggouW^
gu:W^
gogu:W^
goggp:tus^
ggp:p
W^
g`$S3J\ę@4lUYBlК0t\pRDRRRVRRLSTtTWTTHUTnDntooUULpdVVdate0dayspermonthleapday[!q"(.89?@Fygp:qrdsdtg+ogo`Wra`Wragg=Wgo W rogg=
Wgogg^
gp:3rbWcW^
ggp:`pWa``p WaWa``pWaWa``pWaWa^
g^
g^
g^
gs:V^
gg^
gg^
gt:`WW3ra`WW
W3ra`WW
W3ra`WW
W3rag^
g^
g^
ggs:BW!s^
ggp:sbW3rc^
gp:t^!
gp: W3r^"
g^#
sB`$4S3J\|@0lКUY7:Tvv D|\܃Ȅp Ԇd|vpT( 8Xԑ<Ldtvv :EndClass8
4|Q14'RonaldLP|A006577:Class A006577 :Field Private Sequence'Ronalddl'Ronald'RonaldD̠'Ronald'Ronaldt,'RonaldD\'RonaldԤ :Field Private Max :Field Private Max2'Ronaldnnnnnnnnnnnnnn'Ronald ' initializeiP P'Ronald8'RonaldD8|seq|get'Ronaldt,'Ronalḍ\'RonaldD'Ronalḍ' 524+1t'RonaldԤ 'Ronald4p'Ronald'Ronald̦Х$@B$'Ronald(H(||sequence'Ronaldا@Nq#)/Ogp:qdrdsgr:$=tg^
gp:DoL#`@La6orvW3B`$X]<4J\@H"9'Ronald̦'Ronald'Ronald 'Ronald8P'Ronaldh'Ronaldh'RonaldȨ'C a quick way of finding the step lengths of lots of starting values/'V but explodeFrom leaves lots of gaps (in the interests of speed, doesn't go above Max)a|'> so simulate stepping through the chains from each of the gapsd' and return final sequencep\Xfd' find all gaps in the sequence|Hd'M 1st row is starting point (the gaps), 2nd row is current value after s steps^' no steps taken yet\]h'C contains all starting at [1;] which after [3;] steps, reaches [2;]d(B [2;]d"Max, but we don't yet know step length after [2;] to reach 1|'8 while step lengths still unfound for some starting gaps>' make a step+' test if any now at known pointszP', subseq is array of known points of interest]'? check if known points of interest also have known lengths to 1'Z those found we have both known point of interest, and known steps after point of interest$fT'N halffound for known point of interest, but yet unknown step length afterwardsخ' AKA unfound, for next iteration#P' put those found into Sequenceت' process half-founds~' while some yet to be processed#7' if can processZd' process any possibleEt' find those still to process(Gܰ( Sequence[hf[1;]]!2$ 'Ronalḏ'Ronald'RonaldLȨ'+ if nothing, can shortcut to next iterationp!'Ronaldh'Ronald' Y is 8 minimum0Ȳ') works better with at least 8 in sequenceX/'. initialise sequence to get rid of 1-2-4 cycle$^T"0t"س'Ronald'Ronald4'RonaldLd'RonaldĴP>ܴ' Public'2 Note: It is unfortunate that worst case is O(N*2)~'f There is no good way of writing this due to interpretation (only array operations are very efficient):P'2 idealling, a topological sort would improve speedD<' get decompositionH/8Z<'; first makes (the power of each prime) copies of each primeLx'$ add a 1 to the start for each prime8`ܶ'# and scan multiplies for each primeDX('9 then take the outer product between array for each prime$t'
and ravel$,{ط'+ we now have an array of all factors of N2TP8)P|Q9'* the range are indices (i,limit) exclusive'( get gcd of each of these numbers with iPظ8|limith|decomposition'A Euclid's formula for a triple (generalized, not just primitive):<' for (a*2)+(b*2)=(c*2)dm'1 a=2kmn, b=k((m*2)-(n*2)), c==k((m*2)+(n*2))4'/ we want a+b+c=N, substituting and simplifying:b' k((2mn)+2(m*2))=N' km(n+m)=N2tR('% so we get prime decomposition of N2,E`'" so get prime decomposition of N2H'! find all factors, then sort themd8' then plug into formula\H'@ then m and (m+n) are the product of non-intersecting subsets ofT'2 the prime decomposition of N2, and n'eighteen8'twenty`'thirty8'eighty0|h'ninety'hundred'billion'A limit thousands count - counts letters in highest possible digit4y(D:"'Ronald' powers of 1000_$@Bʚ;('p full millions count (count to 1000 + count inferiorly to 1000, 999 times + count to 1000 + thousand, 1000 times("9' count to 1 mill('9 count 1 mill to Y[3] mill inferiorly (lower digit parts)L`'% count to Y[3] mill (this digit part)t'" say "Y[3] million" 1+Y[1 2] times' for and in thousandsN`' count to 1 thou'9 count 1 thou to Y[2] thou inferiorly (lower digit parts)'% count to Y[2] thou (this digit part)d*<'! say "Y[2] thousand" 1+Y[1] timesd' for and in onesD?|sum8|Q17(|lettersinnumbers1tobH4X8z>q#0gp:qdrgr:$=sgp:rtW3B`$4J@H'RonaldLH(. Public ]# Y<10*12, anything above is truncatedx'0 concatenate lengths of each of first 20 numbersy_'< next 80 are cross adds of eg (twenty,thirty,...)+(,one,two)dTT'M this is so we can count the groups of hundreds in each superdigit separately'F separated into two lines to show similarity with previous superdigits0(L the first number to be striked is composite, given each primeL\': calc number in arithmetic sequence to get to end of rangeV'Ronald('X get all primes up to dynsieve, then calculate diff, start, and range-startdiff in bulk<X'< since even multiples of prime have already been crossed offddTbH
&dD
8 (TX<($8D
`
dp|M'R here it is a 20 by 20 grid, if (N,M)=(30,20), it'd be a 20 by 30 rectangular grid@W'7 M+N total moves, N of which you choose to be downwards|'Ronald@q $(,0459=>BFJNRVZ[_gp:qdrdsggr:Wgs:W^
gg
g
g
g
gg
gg
g
g
g
g
g
gp:rsr^
gg
g
g
g
g
g
g
g
g
g
gg
g
gg
g
g
g!
g"
g#
g$
gg%
3B`$</ compared to if we knew what bound it was right from the startd'V this is because the worst case range of x tested is 1.5 times more than the best case5T'1 the same with y, hence 2.25-1 (looking at areas)='j and at worst, we are only checking 125% more than we would have had to if the bound chosen was the answer?0@|minN|max4L|bound|bcC|oydd|isddh |candidates'5 Below I try a more general solution than the 2nd oneP0 '; We know that palindromes which are the product of integersH4'1 within some range appears with a minimum density('. eg. as shown with the 900..02900..09 patternH' or the 10..0110..01=L'> However, it is very difficult to prove that the density is att'A least some amount (if that amount is to be asymptotically close)4y'Y If it is not asymptotically close, then the solution would not be asymptotically optimal`'> We want to generalize the problem so that the solution finds:'D the largest palindrome xy, which is the product of two integers x,y0L(d such that mind"x,y<max, where min and max is not just powers of 10 (as the second solution requires)$%<'. To do this, we can find all x,y s.t. xy>bound
0'; for some bound, then try each to see if it is a palindromeĶ'O and find the maximum of all palindromes (lowering the bound if there are none)\+d': contains the lower bound of y's in the previous iterationSV(3 initialized to l# (no y's were considered at start)
@'F lower bound in each iteration (lower bound in 0th iteration is max*2)P<' no palindromes found yet J@(6 #bound(max-1) contains the lowest x we need consider:'( at least min*2 (min product obtainable)4^'4 is the corresponding lower bound of y's to considerTh'4 equalize lengths of oy and y (using max to fill in)Б|'* commented below is unoptimized expression\# (A x(y-1)+s#oy-y contains all products of range we are considering8t'" if odd, ie. if even num of digits| 'b we can consider just those where WLOG, 11|x, since all even-digit palindromes are divisible by 11zl' find all indices where 11|xI' odd digit palindromes<-<(- as x,y symmetrically defined, now assume xd"y\=|(/ y#x, for xd"y, replacing where y goes, with x#ydV(+ also have 0#oy-u# in case oy-y#x yields -ve'+ now test candidates if they are palindromep' for next iteration,\'
2nd solution,4;' Oldest solution'Ronald@'6 is the range of x we consider,where x is at least min48w|rate'! how quickly the bound is lowered0'K lower by rate, but don't cross power of 10, unless it was on a power of 10?v 'D don't let rate keep increasing, if not needed, in case it overflows\ 'n because of this, if indeed the palindromes occur at a certain density, this algorithm will take 2.25kn time< 'h where n is the minimum products tested for palindromicity, k is some constant, and 2.25 due to the rateLp
'> and 2n can be seen as the average period between palindromes<4'8 so the algorithm takes O(1density of palindromes) time|'_ density of course depends on the range we are considering, a characteristic dependent on max*2#' since no suitable candidatestxd'Ronald 'Ronald$
'Ronald
'Ronald <
%@0Bl
'H using 10E12, because at large values of bound, there is round-off error
'RonaldT
'Ronald 8'RonaldPh'RonaldP'Ronald'Ronald'Q indeed, this solution is faster than the 2nd one, because the 2nd one calculates|('\ a certain "minimum density" for that particular region, then checks all products up to thatp'H to ensure a palindrome, which turns out checking much more than needed.
(D((,]# n!3 ]# digits of x and y, for xy=palindrome$fo(]# :If n=0 ]# small casese( ]# R!0.p(
]# :ElseIf n=1^( ]# R!9+(
]# :ElseIf n=2 c,(]# R!9009Lp(]# :Else ]# now for general cased$(/]# ]# 9000....002 9000....009 = 8100..0990..018p(:]# ]# starting with 902909=819918, so we know, WLOG let xd"y<((]# ]# then 81000...<x (in this case 810<x)1=8(,]# ]# and also 90000...<y (in this case 900<y)v(7]# ]# Also, 11|ABCCBA, for digits ABC, or more generally,n0()]# ]# 11|100...001 for even numbers of 0's,$(>]# ]# since 10a"-1 mod 11, so 10*(2k+1)a"-1 mod 11, and 1a"1 mod 11_D(S]# ]# therefore, 6 digit palindrome (or any even digit palindrome) is divisible by 11_ (:]# ]# so one of x or y is divisible by 11 (which is a prime)4b$H(=]#]# Therefore, Case #1: assume 11|y, and check all y>900,x>810T(M]#]# (but ignore xd"y so that we automatically check 11|x for x>900 as well)Ut(&]#]# then, Case #2: 11|x and xd"900,y>900`2(]#]# Case #1:0(K]#]# 900...002 (even # of digits) is always divisible by 11 (modulo analysis):p(*]# y!(9+910*(n-1))+11s#
#(10*(n-1))11\<,0("]# x!(8110*n-2)+s#(1910*n-2)-100(1]# R!#/",/,/{(u#=10"=#((2n)/10)"u#)/u#}x".yi(]# ]# Case #2:($]# ]# 81a"4 mod 11 => 8100..00a"4 mod 11"tT(.]# x!(7+8110*(n-2))+11s#
#(1910*(n-2))11L;T(]# y!(910*n-1)+s#(10*n-1)-1d(3]# R!R##/",/,/{(u#=10"=#((2n)/10)"u#)/u#}x".yP<(]# :EndIfa'Ronald' if there are solutions84' get the largestt'1 returns an empty array if there are no solutions-%mB 'Ronald$/T8 |clim4|climi(d if clim was not implemented, this solution is practical up to max!4E6 , after which WS becomes fullq 'p with clim, max can be up to 50 mill, the practical limits of precision, and clim prevents the WS full exception!'0 we also want to limit the candidates, due to WS4=@"'3 a rate of kmax, allows k more x's, and k more y's
N"'N at 1.5rate each iteration, the extra area is roughly (k(k2))+(k(k2))+k*2(W"'E that is 5k*2 < 1,000,000 (estimated allowable candidate array size)0l#' therefore, k<447maxm#'M actually, only half the area is checked, at most, therefore, 2.5k*2<1000000y$'
k<632max6$'& this is our limit on rate (initially)PF$'G now we have to reduce clim, since area is 5k*2, then 7k*2, 9k*2,...%%ffffff?o%'RonaldP % 'Ronald`&%&'Ronald0&H&I ]# calculates overflow (based on magnitude, and keeps sign constant) ' removes leading zerosd''Ronald60&0('1 we want either all elements +ve or -ve, not bothD<-`('% make all elements in R the same sign(': very complicated, and quite inefficient, integer division0)'RonaldH(p) c ]# luckily, this function was done just for completeness, and is not used in any of the problems ' more efficient (worst case) the larger the base (note contrast with other operations, which become more efficient when the base is larger)p+' each of the 4 below are slightly different division algorithms for different situations (if I just used the 4th, it would be extremely inefficient)
T$,' most efficient methodu,'w efficient if Y has only 1 element, if Y has many elements, can be inefficient if Y[2] is high (almost as high as base)4b -' same as the first, it is for the 2nd and 4th which are different, that I need to replicate the first in this slightly different while loop,-] ]# unfortunately, division is always one of the hardest arithmetic operations to get right '4 boolean return, is it consistent?, or does it flow?0'E overflow all digits that overflow (ie. perform all carry operations)L=x0'; if most significant digit overflows, we need to add digitsbH0a ]# here I coin the term "flow" to describe digit arrays, where all elements have the same sign |x ]# those which are consistent (all elements have the same sign) flow, and those which are not consistent, do not flow i ]# so the verb "to flow" is the process of making a digit array consistent (in sign over all elements)'RonaldH;)6H p78\ h @p8|T< |Pt'2 number of numbers in a line to multiply at a time$7' up/down;7'RonaldtH((8kq
:;A
!'-34:@AGMSgp:qdrgr:W^
gg^
gg^
gp:@@@bWcxb`#` Wra` xab Wca8D` WJ#radcgg^
gp:p@@@bWcxbd`#` Wra` xabWca8D` WJ#racgg^
gp:p@@@xb``#` xab Wc Wra8D!#` Wra` xabWca8D`` WJ#ra!G WJ#racgg^
gp:p@@@xb``#` xab Wc Wra8D!#` Wra` xabWca8D`` WJ#ra!G* WJ#racgg^
gg^
g^
g^
g^
gg^
g^
gg^
g^
gg^
g^
gg^
g^
g^
gg^
g^
gg^
g^
g^
3B`$7X8(8iEJ:@ H' and sum;;'Ronald60;' +/+/ to sum all digits<`;'Ronald@8;' Public lp;'2 calculate limit up to where we can extract primes78<' extract primesZ\<'" can drop extract range from sievea<' and we have increased sievedto<'E if those were not the last primes to extract (nothing left to sieve)(='1 use last primes extract to cross off next lot...=' extract next set of primes=' :EndIf`8>' Public Xh>'RonaldDA;>H)4hD(@@D?D??Đl>(@\>;*\+;|setformat'K no need to check for good formatting (always grows and always +ve anyways)h t?qU[_ogp:qdrgr:$=sg
gruW^
grx W^
g
gp:`3r|@`
W 2`WWaaa^
ggruW^
gp:$Wr|Gp^
gp:@@p^
g
g
g
g
gg
N3B`$>?,AGwEJA@4H'Ronald>,A% :Field Private base!10 ]# the base }j :Field Private format!1 ]# whether formatting will make output arrays good, ie. consistent, and reduced( " setbase Y' :Access Public( base!Y( "( " setformat Y' :Access Public(+ :If (Y=1)("(Y=0) ]# only set if boolean( format!Y' :EndIf( "( " R!X multiply Y;doublearray' :Access Public( Y!arrayize Y( doublearray!0( :If (1=a"X)( :If (1<t#X)( doublearray!1' :EndIf' :EndIf(- :If doublearray ]# If X is a digit array(+ R!add/(=#base*1-h#s#t#X)(X(op)"Y)(' :Else ]# If X is not a digit array( R!Xop Y' :EndIf( "( " R!X add Y' :Access Public( X!arrayize X( Y!arrayize Y( X Y!X equalize Y( R!X+op Y( "( " R!X minus Y' :Access Public( X!arrayize X( Y!arrayize Y( X Y!X equalize Y( R!X-op Y( "( ]# more efficient (worst case) the larger the base (note contrast with other operations, which become more efficient when the base is larger)(P " R!X divide Y;Q ]# very complicated, and quite inefficient, integer division' :Access Public ( X!arrayize X( Y!arrayize Y' :If Y[1]=0( #SIGNAL 11' :EndIf( R!(t#X)t#0( :While ((t#Y)<t#X) ]# each of the 4 below are slightly different division algorithms for different situations (if I just used the 4th, it would be extremely inefficient)( :If ((|1!Y)<|1!X)'"2d"t#Y(I Q!(X[2]+X[1]base)(Y[2]+Y[1]base) ]# most efficient method(% Q!((Q>0)
#Q)+((Q<0)#Q)( R[1+(t#X)-t#Y]+!Q(1 X!X minus(Q multiply Y),((t#X)-t#Y)t#0( :Else ]# efficient if Y has only 1 element, if Y has many elements, can be inefficient if Y[2] is high (almost as high as base)(& Q!(X[2]+X[1]base)(1!Y)(% Q!((Q>0)
#Q)+((Q<0)#Q)( R[(t#X)-t#Y]+!Q(3 X!X minus(Q multiply Y),((t#X)-1+t#Y)t#0' :EndIf' :EndWhile(" :While ((t#X)=t#Y)'"(|1!Y)<|1!X( :If 2d"t#X ]# same as the first, it is for the 2nd and 4th which are different, that I need to replicate the first in this slightly different while loop(1 Q!(X[2]+X[1]base)(Y[2]+Y[1]base)(% Q!((Q>0)
#Q)+((Q<0)#Q)( R[1+(t#X)-t#Y]+!Q(1 X!X minus(Q multiply Y),((t#X)-t#Y)t#0' :Else( Q!X[1]Y[1](% Q!((Q>0)
#Q)+((Q<0)#Q)( R[1+(t#X)-t#Y]+!Q(1 X!X minus(Q multiply Y),((t#X)-t#Y)t#0' :EndIf' :EndWhile( :If (X[1]<0)'"Y[1]>0( R[1]-!1( :ElseIf (X[1]<0)'"Y[1]<0( R[1]+!1' :EndIf(5 R!containOverflow flow reduce overflowInPlace=#R( "( " (X Y)!X equalize Y( :If 0=a"X( X!1t#X' :EndIf( :If 0=a"Y( Y!1t#Y' :EndIf( :If (t#X)>(t#Y)( Y!(((t#X)-t#Y)/0),Y( :ElseIf (t#Y)>(t#X)( X!(((t#Y)-t#X)/0),X' :EndIf( "(]]# Digit array refers to a number with each digit being represented as an element in the array(H]# This allows the array to represent arbitrarily large positive integers( " R!X(F op)Y;A;i' (W Y!arrayize X F Y ]# The actual operation (whether it be multiply, add or whatever)( R!Y( "( ]# find leading zeros(- " R!reduce R;drop ]# removes leading zeros( drop!0(F :While ((drop+1)<t#R)'"R[drop+1]=0 ]# but always leave last element( drop+!1' :EndWhile( R!drop!R ]# remove them( "( " R!arrayize R;drop( :If ((a"R)=0)( R!1t#R' :EndIf' :If format(9 R!containOverflow flow reduce overflowInPlace R' :Else(i R!containOverflow overflowInPlace R ]# no flow or reduce if formatting doesn't have to be "good"' :EndIf( "(5 " R!flow R ]# make all elements in R the same sign(J :If ~consistent R ]# we want either all elements +ve or -ve, not both' :If R[1]>0( R+!base-1( R[t#R]+!1( R[1]-!base' :Else( R-!base-1( R[t#R]-!1( R[1]+!base' :EndIf($ R!reduce overflowInPlace R' :EndIf( "(H consistent!{ ]# boolean return, is it consistent?, or does it flow?( ('"/0e"u#)("('"/0d"u#)' }(; ]# fixes R such that no value is greater than the base(d " R!overflowInPlace R;A;i ]# overflow all digits that overflow (ie. perform all carry operations)(< :For i :In =#1!s#t#R ]# For each index, check for overflow(4 A!of R[i] ]# Divide to collect all overflow(2 :If (+/A)`"0 ]# If overflow is present ...(E R[i]!R[i]-Abase ]# Remove overflow from the current col(P R[i-1]!A+R[i-1] ]# Add overflow to the next more significant column' :EndIf'
:EndFor( "(X " R!containOverflow R;A ]# if most significant digit overflows, we need to add digits(L A!of R[1] ]# If overflow remains in left-most (most significant column)(@ :While A`"0 ]# Keep adding columns until no column overflows(0 R[1]!R[1]-Abase ]# Remove the overflow(? R!A,R ]# Add overflow to extra column inserted on left(2 A!of R[1] ]# Calculate overflow remaining' :EndWhile( "(
of!{( (1-h#2u#e"1)
#|u#base' }(( ]# make a string into a digit array(/ ]# num is characters to consider at a time(4 ]# then in batches of num, add integer to array(" " R!{num}digitizestring string' :Access Public(# R!l# ]# start with empty output( :If 0=#NC'num'( num!1 ]# default=1' :EndIf(P :If 0`"num|t#string ]# if doesn't divide perfectly, start with reduced amount(" R,!N#string[s#num|t#string]' :EndIf' (8 :For i :In ((nums#
#(t#string)num)-num)+num|t#string( R,!N#string[i+s#num]'
:EndFor( "(6 ]# convert a digit array into an ordinary integer( " R!numerize array' :Access Public(u R!+/(=#\1,1!(t#array)/base)array ]# multiply array with the base to the power of the position, then sum together( "@zy&PzX|y0g@zytzyydigitarrayzUZyz0gyT({ydigitarrayy@`z
t{ybase({ L{(
10 ]# the based{yformat| {(P1 ]# whether formatting will make output arrays good, ie. consistent, and reducedB|}ĴL{8~}ysetbaseyY[!>p#'gpqg+ogs:qS@`$|X},AwEJ,}}@}UY|r~}Ĵ\D~{0|~ysetformat[ss!' only set if boolean(>l~^p"+CGMgpqg'+ogLo`qWa`qWa^
gv:qg0oS@`$}~,AwEJ@~ @}UY}~ }ĴtD\lL{ȀyRyX0ȃ(ymultiplyTydoublearray[! 0zyarrayizeT0}yadd@4\ЌyoprKTY^n{gp:qrsdtgP+ogs:vsgt:Wgo`W$qago`W qagt:Wgsogcogot^
gp:z@`*{WJ# qaG`q`|Ga2sago^
gp:q|sgokB`$`,AwEJH@}UY@}ĴtȀ[TT!8`yequalizenr)27<CJgp:qrsg.+ogq:uqgs:usgqs:qvsgp:qwsB`$HЂ,AwEJtD@}UY(%ȃ}ĴtȀ8hyminus[!nr)27<CJgp:qrsg.+ogq:uqgs:usgqs:qvsgp:qwsB`$,AwEJ@}UY|ȃ&,T}X);,t\D-,L{-ȃ-\.̅0\0LydivideDyQ[L!8z`ycontainOverflow0{xyflow0Ȁ~Dyreduce80yoverflowInPlace,r'Nhy/Qk|6@FOgp:qrsdt^
g+og^
gq:xqgs:xsgosb Wc
Wgg=Wgogp:` qa
Wgo`` sa qa^
go``
W$sa
W$qa
W sgt:`qb
Wcqb Wc~a`sb
Wcsb Wc~a^
gt:``t
Wata``t
Watagpb W` qa sc:tgq:q`tsa!`` qa sa
Wgo^
gt:`qb
Wcqb Wc~a` W$sagt:``t
Wata``t
Watagpb` qa sc:tgq:q`tsa!`` qa W sa
Wgogogo`` qa sa`
W$sa
W$qgo
W q^
gt:`qb
Wcqb Wc~a`sb
Wcsb Wc~agt:``t
Wata``t
Watagpb W` qa sc:tgq:q`tsa!`` qa sa
Wgogt:qb Wcsb Wcgt:``t
Wata``t
Watagpb W` qa sc:tgq:q`tsa!`` qa sa
Wg$ogog5o`qb Wc
Wasb Wc
Wgpb Wc: WgEo`qb Wc
Wasb Wc
Wogpb Wc: Wgogp:*pB`$,AwEJ@}UYȄT0YR}D\rDRY_mtzg`pqa:prqg^oWpgp:W pgIogyoWqgq:W qgdogo` pa` qagq:``` pa qa@Wa!qgo` qa` paogp:``` qa pa@Wa!pgoTBa$t,AwEJ@}}UYT]i$Ȁ}Dd<ttyF$yAyins0489EIgp:q`rsatdudvg
g
ggt:yqrt^
gp:tJ`$,AwEJ@dD$}UY̋Ȁlr0(D\d++tydropG~q39>_ekvgp:qpdr^
g^
gr:Wgjo``rWa papbrWcW^
gr:WgCogp:r%p^
sB`$t̍,AwEJl@UYT0t{tD\{̅0\H': no flow or reduce if formatting doesn't have to be "good"Sq6ELRYagrxgp:qpdrgQo``paWagp:W pg;ogfougp:vwxypgwogp:vyp^
gWossB`$Ď`,AwEJ@UYt((\DL{0\0L{̅TyconsistentqIWemwgp:qp^
gosp^
gopbWcWgp:wWgpb pc:WgpbWc:wgogp:wWgpb pc:WgpbWc:wg\ogp:xypgNoSB`$\Đ,AwEJ@UY<2`0D>p+FLgp:*o^
LE#og`@WLa`@WLaLK#ogoaEQ
,A*wEJUY̑\Dd0Б\4D8L{8ȀHyofq=C[h{gp:qpdrds^
g^
gosHo*W%# p^
gr:xpbsc^
go`@ra
W^
gpbsc:pbscr|^
gpbsWc:rpbsWc^
gmogN
osB`$X,AwEJ4@dDUY̒\̅D414\HDL{4|~q3APep~gp:qpdr^
gr:tpbWc^
gorW^
gpbWc:pbWcry^
gp:r!p^
gr:tpbWc^
gFoxsB`$ؔ,AwEJ@DUYx̅B4\L{>p&CIgp:%oIB#og`WJWLWa
LsIH#ogoaEQ
4,A%wEJUY4(LĴdDй\ddynum8TԘydigitizestringBzystring[ !rS\bhq~gp:lqmrsgX+og^
g^
gp:k^
goWn= Wgq:
W^
gvogoWq
s^
gp!:*/sb#q
scgogg^
go~o``q#` saqaqaq
sgp!:*/sb~#qcg
oC`$,AwEJ@(UYLĴ\L{0d0TynumerizeBtyarray[(!Nq )/Lgp:qrg%+og^
gp:@`*BW!W%` ra@var^
SB`$T,AwEJؙ|@UY4+X\ABD@DdDDDDEhEEE|E$FHF|FFFGdGGGHtHHI$I@IpIIII8JdJJJJK@K|KK))t.LMKMN8NXNNNN@PP4QQQPRpSS(TpTTU(U|UV@WWW\X|XXYhYYYZ`ZZZ[0[[Tt`[\4\d\\\\\0]x]]^^Xx_8^___``%8a`aahbbbc&|D c`ccccdddee/L124e8ffg@g|ggghXhhhi,iHii,j (jDjk,llmmdnnn'no(pp(qq,rLrx&hrrrĸ8ttrPstu@uuuTvvvsv\www\xxwxyȚH44h(0-dD?D?$H$\HqMNYlrsgp:qdrggr:$=s^
gruWW^
g^
ggrzW^
ggp:`3r}@Wr~Gab#Wcg^
gruW^
gp:pbWcr}pbWcWW^
g^
ggp:rpb#Wc^
3B`$8,AwEJğ@4HH+4hD?D?X,,Đ0(|-Xd**\++'Ronald>\.qY_osw{gp:qdrgr:$=sgrtW^
g
g
g
g
gg
g
g
ggp:@`$r~@`@#Wa!`@W#Wa!@G``W#WaWa2#Wag
g
g
gg
3B`$\wEJ@4H'm Find index corresponding the to "fin" bound in the primes array (if fin required less than available primes)l
'F remove primes larger than fin, if any (only occurs on last iteration)pgT' extract last set of primes >\Ģ'Ronaldt( new range!Y-sievedto ]8'" now we've sieved right to the end\mD'Ronald$ أ(: ]# first check that we have sieved past the nth prime(> ]# got upper bound on size of nth prime from wikipedia...(B ]# n ln n + n (ln ln n - 1)< p_n < n ln n + n ln ln n for ne"6( " R!nthprime Y;upperbound' :Access Public' (. :If Y<6 ]# so if n<6, just sieve past p_6' :If sievedto<11' sieveto 11' :EndIf(1 :Else ]# otherwise just calculate upperbound(! upperbound!(Y_#Y)+Y_#_#Y'! :If sievedtoY}#.bsearch 1,t#primes)-1' :Else( Y!t#primes' :EndIf' :Else(0 Y!({primes[u#]>Y}#.bsearch 1,t#primes)-1' :EndIf( :If 0=#NC'X'(
X!0' :Else(
X!X(0 X!({primes[u#]>X}#.bsearch 1,t#primes)-1' :EndIf' (# :If Yd"X ]# no primes to return(
R!l#' :Else( R!primes[X+s#Y-X]' :EndIf( "(x ]# Find index corresponding the to "fin" bound in the primes array (if fin required less than available primes)(c ]# get all primes up to dynsieve, then calculate diff, start, and range-startdiff in bulk(I ]# the first number to be striked is composite, given each prime(! ]# represents to max of:(g ]# square of prime (since smaller multiples of the prime are already struck by smaller primes)(R ]# the smallest multiple of the prime within the "range", aka more than X(n ]# normalized as the sieve array index, and normalized as 2prime smaller than actual starting number(E ]# calc number in arithmetic sequence to get to end of range(A ]# strike all those in the arithmetic sequence below(* ]# extract next set of primes(@ ]# use last primes extract to cross off next lot...( ]# same things done in bulk as for above (we calculate arithmetic sequence parameters so that we don't have to interpret calculations for every prime)(A ]# strike all those in the arithmetic sequence below(X " R!sieveto Y;sieve;range;fin;j;start;diff;dynsieve;num;diffs;starts;nums;primerange' :Access Public ' :If sievedto<3( primes!2 3( sievedto!3' :EndIf(5 :If sievedto<Y ]# sieve further only if required( range!Y-sievedto(h fin!
#Y*0.5 ]# upper bound of primes needed to test the largest integer for primality testing: Y(0 sieve!ranget#(6|sievedto+1)=#0 1 0 0 0 1' (9 dynsieve!({primes[u#]>fin}#.bsearch 1,t#primes)-1(( primerange!2!primes[s#dynsieve](Z diffs!2primerange ]# since even multiples of prime have already been crossed off' (R starts!((diffs-diffs|sievedto+primerange)#(primerange*2)-sievedto)-diffs' ($ nums!
#(range-starts)diffs' '7 :For diff start num :InEach diffs starts nums(& sieve[start+diffs#num]!0' :EndFor' (d :While sievedto<fin ]# if those were not the last primes to extract (nothing left to sieve)(b dynsieve!(Y
#sievedto*2)-sievedto ]# calculate limit up to where we can extract primes(U primes,!primerange!sievedto+sieve[s#dynsieve]/s#dynsieve ]# extract primes(F sieve!dynsieve!sieve ]# can drop extract range from sieve(A sievedto+!dynsieve ]# and we have increased sievedto( primerange!(1-h#{primerange[u#]>fin}#.bsearch 1,t#primerange)!primerange ]# remove primes larger than fin, if any (only occurs on last iteration)( diffs!2primerange(V starts!((diffs-diffs|sievedto+primerange)#(primerange*2)-sievedto)-diffs(D nums!
#(Y-sievedto+starts)diffs ]# new range!Y-sievedto' '; :For diff start num :InEach diffs starts nums(* sieve[start+diffs#num]!0' :EndFor' ' :EndWhile(E primes,!sievedto+sieve/s#t#sieve ]# extract last set of primes(8 sievedto!Y ]# now we've sieved right to the end' :EndIf( "(>]# Returns an array giving the number of factors of each number(]# in the range (X,Y](]# X defaults to 0(R]# The way solving this is based on a number N writing as a decomposition of primes(']# N!(p1*a1)(p2*a2)(p3*a3)(p4*a4)...(/]# In which case the number of divisors of N is:(!]# (a1+1)(a2+1)(a2+1)(a2+1)...(/]# So the algorithm looks at each prime in order(.]# Checks how many times it divides each number(7]# and multiplies the current number of "known divisors"(=]# by (a+1) where "a" is the number of times the current prime(]# divides into the number(+]# to get the new number of "known divisors"(]# initialise range(\]# get primes up to X (at least 3 so we have something to start with, so long as Y>=3 though)(X]# The general sieve algorithm allows for a prime dividing into the number more than once(]# General Sieve starts below:(i ]# Make an array size Y-X each with the number of factors that are powers of only this prime(G ]# here T represents number of times a prime divides its index(6 ]# eg. for p=2, T=0 1 0 2 0 1 0 4 0 1 0 2 ...(d ]# and T+1 represents number of times a prime divides the index-th number the prime divides(7 ]# refill pl with new primes in the next range(_ ]# tests for 1 (means it is a prime), and converts it to index form (start+s#end-start)(7 ]# R now holds results (it is the processed sieve)(2 " R!{X}numfactorsieve Y;T;n;p;i;j;pl;start;end' :Access Public( :If 0=#NC'X'(
X!0' :EndIf( :If 0`"a"X( #SIGNAL 11' :ElseIf X<0( #SIGNAL 6' :EndIf' ' (4 R!(Y-X)t#1 ]# init to 1, as 1 divides everything(S end!Y
#3#X ]# end is the last number in the range we are currently dealing with(2 pl!primelist end ]# gets those initial primes' ' (N :While 0<t#pl ]# while we have primes in our pl(prime list) to account for' :For p :In pl(L i!p-X ]# p is prime, i is corresponding index of prime in sieve' (Y n!
#p_#Y ]# find the max power of this prime that divides a number less than Y' (0 T!1t#0 ]# initialize T for use below( :For j :In =#s#n-1(' T!((2t#T)t#(1-p)1)\T+1' :EndFor(K j!(ps#
#Yp)-X ]# calculate index of each multiple of the prime' (; n!
#Xp ]# find number of multiples less than X(f T!n=#T ]# drop those powers of primes-1 (except rotate to drop, since we need to reuse Ts)(1 j!n!j ]# and also drop those indices(^ R[j]!R[j](t#j)t#(T+2) ]# factors ! 1+power of prime that divides into each number' :EndFor' (C start!end ]# end of last range becomes start of this range( end!Y
#(end*2) ]# we can easily find primes up to square of end of last range (since all primes, and only primes have 1 up to that range)' (9 pl!(R[(start-X)+s#end-start]=1)/start+s#end-start' :EndWhile' ( "( ]# N: number to factorise(. ]# largest factor found (1 is always a factor)(?]# Below is my original method. Overall complexity is O(sqrt(n))(L]#]# it is slower than commented alternative below (10 times longer to run)(6]#]# however, this one has better worst case scenario(.]#]# as interpretative complexity is O(log n)(L]#]# in worst case, for similarly sized N this solution is 100 times faster(V]# Edit: this is now faster, because I have created a compromise, it is trial division,(Y]# but using arrays at a time, each array of primes including the next power of 10 upwards(1]# this removes much of the looping inefficiencies(Q]# while ensuring that if not required, larger primes are not trial divided into n(+ ]# find factors still dividing(]# R!Q3;N;n;maxfactor;sqrtn(]# another solution(B]# algorithm is O(max(2nd largest factor,sqrt(largest factor)) time(N]# But slow due to interpretative complexity - worst case interpreting the loop(]# 1,000,000 times (sqrt(n))($]# n!N ]# current unfactorised portion(;]# maxfactor!1 ]# largest factor found (1 is always a factor)(]#(I]# :If 0=2|n ]# remove 2, so that it is no longer a concern (it is not odd)(]# n!maxfactor!2(]# :EndIf(2]# :While n`"1 ]# while there are factors to be found(C]# sqrtn!
#n*0.5 ]# largest factor not 1 or n, that could be found(d]# maxfactor!3#maxfactor ]# in case maxfactor is 1 or 2, maxfactor starts from last known position(]#(1]# :While maxfactord"sqrtn ]# while less than...(m]# :If 0=maxfactor|n ]# if is factor (we know it is prime, as we test from smallest odd numbers upwards(0]# :Leave ]# process this prime factor(]# :EndIf(?]# maxfactor+!2 ]# not a factor, go to next odd candidate(]# :EndWhile(Y]# :If maxfactor>sqrtn ]# if we tried to start after largest possible factor not 1 or n(?]# maxfactor!n ]# n must be the next largest prime factor(]# :EndIf(/]# n!maxfactor ]# remove factor found from n(]# :EndWhile(
]# R!maxfactor(8 " (factors powers)!decompose N;n;newfactors;p10;mask' :Access Public(( n!N ]# current unfactorised portion( powers!factors!l#' ' ( p10!1(5 newfactors!l# ]# array of candidate prime factors( :While n`"1(/ :If p10>
#n*0.5 ]# no new primes to add(; newfactors!1t#n ]# then add last possible prime' :Else(p newfactors,!p10 primelist(10p10)
#
#n*0.5 ]# add list of primes up to next power of 10 as candidates' :EndIf( newfactors!{(0=u#|n)/u#}newfactors ]# gets the residues mod those primes, the residues that =0 are factors of n, only keep factors that are relevant' (5 factors,!newfactors ]# add new factors found(? powers,!(t#newfactors)/1 ]# put in corresponding powers(B n!h#/newfactors,n ]# remove all factors found from n once' (I mask!(0=newfactors|n)/s#t#newfactors ]# get factors dividing still(8 mask!(t#newfactors)-mask ]# record mask from end(\ newfactors!newfactors[(t#newfactors)-mask] ]# keep those factors still dividing only' (@ :While 0`"t#mask ]# while got some factors dividing still(M powers[(t#powers)-mask]+!1 ]# increment powers with mask from end(@ n!h#/newfactors,n ]# remove factors dividing from n' (F mask newfactors!{(u#/mask)(u#/newfactors)}(0=newfactors|n)( :EndWhile ]# exit while loop when newfactors is empty (ie. we have divided all prime factors as many times as we can into n)( p10!10' :EndWhile( "\)P$X|0g\primesT!UZ0gH4primes$X (0t#0sievedto p'1(HxĴk(ll|-mp-\mmm R04\nthprime
Yupperbound[5!0H
LsievetoqV_`flrgp:qrdsg[+ogg^
g^
g^
gorW^
gozWg|Wgogo^
gs:`r rar rgozsg|s^
gogwogp:brc^
sB`$$أzEJ(@(xUYH(x;Dp@\0X/(>xX0ȸprimelist[n!bsearchrw !%KQRVdhnzgp:lqmrsg|+ogo`W vawsgxsgoswgs:`ovbLcsoNy
W! va
Wgogs: vgogogs:`ovbLcsoNy
W! va
Wgog oWn=Wgq:WgPogq:qgq:`9ovbLcq-oNy
W! va
Wgogg
gmosq^
gp:kgogp:vbq#sqcg[oBC`$lأzEJ @(xUY`02(xH
p
,\>p97h<|-\D:<@$<\==X>****D<|<<==
tp
psieveH
rangexfinjstartdiff{(dynsieveHnum(diffs
startsOnums{primerange{[O!' same things done in bulk as for above (we calculate arithmetic sequence parameters so that we don't have to interpret calculations for every prime),\3nq #17DUV\#);Vak "+1gp:qrdsdtdudvdwdxdydzd{d|d}d~g+og"oWg:Vg:Wgog0or^
gt:rgu:rW^
gs:t `W
Wa*Vgg
^
gy:`pobLcudoNW! aWg
^
g~:W%b#ycg{:W~^
gg
^
g|:``{{
~a`~Waa{g
^
g
^!
g
^"
g
^#
gg
^$
g}:`t|a{ggoxwz*o{|}g^%
gsbwx#zc:&Wg
oggou^'
g^(
gy:`rWa^)
g!:*~:sb#yc@#y^*
gs:y%s^+
g:y^,
g~:`WJo~bLcuwoNW! ~a$~^-
g^.
g^/
g{:W~g|:``{{
~a`~Waa{g}:`r|a{^0
ggoxwz*o{|}g^%
gsbwx#zc:&Wg
oggog!:*s@# s^1
g:r^2
g(osB`$p
أzEJ0t@\,
p
H
(xUYP 8n(Hx
(Ĵ,,4-D0-|-1`223X334t445p.\.[,\p\51\4]/x]H0HPQQHIHI$H]$^^__0Ș
numfactorsieve\T
Hnhp
ipl{,end[\\!:r'048<INT_dsx~
%7=W]pv| gp:lqmrsdtdudvdwdxdydzd{g,+og
g
g
gSoWn=Wgq:WgAogroWqgg=Wg}oqWiogg=WgYogg
g
g
g
g
g
g
g
g
g
gg
gp:`sqa W^
g!
g{:s"Wq^#
gy:{^%
gg&
gg'
goW y^(
govoygw:vq^)
ggu:v s^*
ggt:W W^+
g\ox*o*#uWg^,
gt:``-W ta `WvaWaBtWg0
ogx:`v#svaq^.
g
^/
g
^0
g
^1
ggu:qv^2
gt:u*t^3
gx:u%x^4
gpbxc:pbxc` xa `t-Wa^5
g
ogg
^6
gz:{^7
g{:s`{-Wa^8
gg
^9
gy:`pb`zqa#{zcWa@z#{zgogg^:
C`$PxأzEJL@(
(xUY0HpB4hĴBtxx::;;\<<4==\8=(9DDDD,EpEEFPFFF(GL||}p~p0Ԁ6pL
factorspowers\0@$decompose(NHnewfactors\p10mask\[BB!/~r7@FOU[_cgklpquy}
+,FTefv#'+/37;?Cg`pqa:rsdtdudvdwg<+og^
gt:s^
gq:p:kg^
g
g
g
g
gg
gg
g
g
g
gv:Wgu:k^
gotWgovtW^
gu:W t^
gogu!:*v`WvatW^
gogu:o`WL
ta@Lou^
ggp!:*u^
gq!:*` ua@W^
gt:J@u!t^!
ggw:`Wu
ta@# u^"
gw:` uaw^#
gu:ub` uawc^$
ggoW w^%
gqb` qawc:W^&
gt:J@u!t^'
gg^(
gwu:o`L@wa`L@uao`Wu
tagko^)
gv:Wgog*
g+
g,
g-
g.
g/
g0
g1
g2
g3
g4
g5
g6
g7
g1
g8
g9
g:
g;
g<
g=
g>
g?
g@
gA
gB
gC
sBa$pأzEJL@h4UYP.POij4̦ܧ̨Hkȩ,|Ȫ@`ܫLhȬd8TDDEFGIJ0@x̹HlܻЮЯxؼL4h ؾ8пP|8hDTlD\8\`(`P8l84Xp4L@h$@8P(0h6\`0,Pd Xp(4t dt,tThDdpH\,\p06m Hw0P4X|h 4tH4LL0D<l
dL8z!("((""T##$|$$K%lp%%
(\h D
P\T$-$dpD\TXX ,<X<$0Lt4'5 find all candidates (those that are divisible by 11)~<$'Ronald$8 q%+17=>DJPV\]ciopu#)/9RX{"2R](8CIOX^deimquy}gp:qdrdsdtdudvdwdxdydzd{d|d}d~g^
gg^
g^
g^
g^
gg^
g^
g^
gg^
g^
g^
gg^
g^
g^
gg^
g^
g^
g^
gg^!
g^"
g^#
g^$
g^%
g^&
g^'
gg^(
g^)
g^*
g^+
g^,
gg^-
g^.
g^/
ggu:0Wgv:1W^2
g^3
ggy:k^4
g^5
gw:v6W^7
g|:8Wv^9
g^:
g^;
g^<
g^=
g^>
g^?
g^@
g}:AWv^B
g~:CWgp:k^D
g]owu6Wg.o}|g ^E
g|:}:}`~FWa`~6WaFWg~:6WgogWowGWgw:`HWHW wIWaw|^J
gogw:``HWHW wKWaLWGW
waw|^M
g4og|:}wNW|^O
gg^P
gw:u6W^Q
ggs:o`LIWa#vLouw`vIWa^R
gt:uws^S
gy:``` ta ya va!y^T
gg^U
g^V
ggo6W
HW w^W
g ^X
g ^Y
gz:`ZW
ZWsbIWcagz:`zHWaZW#LW`HW` sazaZWgoLW zg{:3!@
sbzc`tbzcIWa#Gybzctbzc^[
gogy:t^\
go^]
gWogo^^
g ^_
g{:3!@
os`LIWa#GLWyLots^`
g ^a
gog^b
g{:HW-o`@bIWcL+La@Lo``HW v6Wa@HWa.{gNoLW {^c
gp:@{^d
gog-ogy:t^\
gog^e
ggf
gg
gh
gi
gj
gk
gl
gm
gn
go
gp
gq
gr
gs
gt
gu
gv
gw
gx
gh
gy
gz
g{
gh
g|
g}
g~
g
g
gh
g
g
g
g
g
g
gg
g
g
gg
gg
g
g
g
g
3B`$!$$({EJ,@ h |X4P0Hqn ]# quick way of finding lots of sequence indices (but will not look above Max, so will not find everything)'RonaldD@8/(5 ]# initialise sequence to get rid of 1-2-4 cycle(J ]# a quick way of finding the step lengths of lots of starting values(] ]# but explodeFrom leaves lots of gaps (in the interests of speed, doesn't go above Max)(E ]# so simulate stepping through the chains from each of the gaps(! ]# and return final sequence($ " R!get Y;i;seq ]# Y is 8 minimum' :Access Public(8 Max!8#Y ]# works better with at least 8 in sequence( Max2!
#Max2(" Sequence!Maxt#1 ]# initialize' ( Sequence[1 2 4]!0 1 2' ( 3 explodeFrom 1t#8' ' ' simultaneousSimulation' ( R!Sequence( "(J ]# contains all starting at [1;] which after [3;] steps, reaches [2;](I ]# [2;]d"Max, but we don't yet know step length after [2;] to reach 1(+ ]# test if any now at known points(J ]# check if known points of interest also have known lengths to 1(]# Sequence[hf[1;]]!2( ]# process half-founds(9 ]# Note: It is unfortunate that worst case is O(N*2)(m ]# There is no good way of writing this due to interpretation (only array operations are very efficient)(9 ]# idealling, a topological sort would improve speed(K " simultaneousSimulation;seq;s;sub;subseq;done;found;hf;halffound;split(A seq!(Sequence<0)/s#t#Sequence ]# find all gaps in the sequence(g seq!(2,(t#seq))t#seq ]# 1st row is starting point (the gaps), 2nd row is current value after s steps( s!0 ]# no steps taken yet' ( halffound!3 0t#0' (R :While 1<(t#seq)[2] ]# while step lengths still unfound for some starting gaps(B seq[2;]!{((2|u#)1+3u#)+(0=2|u#)u#2}seq[2;] ]# make a step( s+!1' ( sub!seq[2;]d"Max(B :If 0e"+/sub ]# if nothing, can shortcut to next iteration' :Continue' :EndIf(F subseq!sub/seq ]# subseq is array of known points of interest' (% done!Sequence[subseq[2;]]e"0(w found!done/subseq ]# those found we have both known point of interest, and known steps after point of interest(m hf!((~done)/subseq) ]# halffound for known point of interest, but yet unknown step length afterwards(X halffound,!hfj#s ]# j#s is to add row giving steps required from hf[1;] to hf[2;]' (< seq!((~sub)/seq) ]# AKA unfound, for next iteration(S Sequence[found[1;]]!Sequence[found[2;]]+s ]# put those found into Sequence' :EndWhile(: :While seq[2;1]>Max ]# can step faster if only 1 left(6 seq[2;1]!{((2|u#)1+3u#)+(0=2|u#)u#2}seq[2;1]( s+!1' :EndWhile' :If Sequence[seq[2;1]]<0( halffound,!seqj#s' :Else(1 Sequence[seq[1;1]]!Sequence[seq[2;1]]+s' :EndIf' (? :While 0<(t#halffound)[2] ]# while some yet to be processed(9 done!Sequence[halffound[2;]]e"0 ]# if can process( found!done/halffound(R Sequence[found[1;]]!Sequence[found[2;]]+found[3;] ]# process any possible(C halffound!(~done)/halffound ]# find those still to process' :EndWhile( "(3 ]# also does reverse 2, if answer is <Max([ ]# there no testing for 1-2-4 cycle, assume calling function won't call with these(} ]# we can do this, because this function is private, and we assume ppl changing this class is familiar with the code( " X explodeFrom Y( :If 0=a"Y(= Y!1t#Y ]# make Y a 1D array (for assumption purposes)' :EndIf( :While 0<t#Y( Sequence[Y]!X' ( Y!((((4=6|Y)/Y)-1)3),2(Yd"Max2)/Y ]# does the reverse 3n+1 thing if a"4 mod 6 (since iff that gives answer that would choose 3n+1)' ' ( X+!1 ]# increment step' :EndWhile( "HPOPPX|O0gHPOtPOOA006577lbPUZOP0gVOQ QOA006577O@`PQtStQOSequenceL DQQQOMax QPRROMax2G QRRRS$SĴQ0|<QDQL;ldtS\LSDQOR0ȜVVTOget\tVOYVOiSOseq[f!0RRh`OexplodeFrom0V$V[OsimultaneousSimulation>qenzgp:qrdsdt^
gj+ogw:Wr^
gz:wWg|:w
W^
gg^
g|bVc:Vgg^
gWW Wgg^
gg^
ggg^
gp:|^sB`$,RS/|EJHST@$SSRRUYRS$SV$VHVtVVVVWDQDتP\8QPԭ<8WȯlX8ȵ$LİS$SOsWHVOsubPOsubseqtSOdoneROfoundDQSOhfVOhalffound$VOsplit(= j#s is to add row giving steps required from hf[1;] to hf[2;]@W' can step faster if only 1 left,W(.p#)12H 48>S%+KY_gpdqdrdsdtdudvdwdxdygq:`zWa@# z^
gq:`
W!` qaa q^
gr:W^
gg^
g^
gx:V Wgg=oW` qab
Wc^
gqb
Wdc:|o``
W
LaWWLa`W
W
LaL
WToqb
Wdc^
gr:Wgg
^
gs:qb
WdcgoW@s^
g7ogogt:s@q^
gg
^
gu:zbtb
WdccWgv:u@t^
gw:``ua@ta^
gx!:*w"r^
ggq:``sa@qa^
gzbvbWdcc:zbvb
Wdccr^
g!
g7ogoqb
WdWc^"
gqb
WdWc:o``
W
LaWWLa`W
W
LaL
Waoqb
WdWcgr:WgCogozbqb
WdWccWgx!:*q"rgogzbqbWdWcc:zbqb
WdWccrgogg^#
g^$
g^%
g^&
g^oW` xab
Wc^'
gu:zbxb
WdccW^(
gv:u@xgzbvbWdcc:zbvb
WdccvbWdc^)
gx:`ua@x^*
go3@`$LU,X/|EJ[@ WVVVtVHV$VV$SUY,USL\tSRD\]DQp|-Q]4^^H__ROX', make Y a 1D array (for assumption purposes)x\(] does the reverse 3n+1 thing if a"4 mod 6 (since iff that gives answer that would choose 3n+1)]'( also does reverse 2, if answer is 8>\6P>>(?P?p?@6$@@AlB,CDCCh7DD(EEEE FdFFFG778l9(GG1]>0(7 ]# this is equivalent to and99, or andho if nh=0(Z ]# this is also the case for more than Y[1], it applies to the most inferior thousand(m ]# to take this into account, below, the partial inferior thousands count, full inferior thousands count(w ]# full millions count (count to 1000 + count inferiorly to 1000, 999 times + count to 1000 + thousand, 1000 times( ]# full billions count(' ]# assume input is less than 10*12(2 ]# if most significant not max, count all(@ ]# for most significant being max, count for first part(/ ]# say "Y[4] billion" 1+Y[1 2 3] times(C ]# let continue with next part as with that was the number(- ]# say "Y[3] million" 1+Y[1 2] times(, ]# say "Y[2] thousand" 1+Y[1] times(u " R!lettersinnumbers1to Y;units;teens;tens;subhundred;hundred;and;superbasethousand;nh;ho;ptc;ltc;pitc;ftc;fitc;d(; :Access Public ]# Y<10*12, anything above is truncated(J units!'one' 'two' 'three' 'four' 'five' 'six' 'seven' 'eight' 'nine'(i teens!'eleven' 'twelve' 'thirteen' 'fourteen' 'fifteen' 'sixteen' 'seventeen' 'eighteen' 'nineteen'(V tens!'ten' 'twenty' 'thirty' 'forty' 'fifty' 'sixty' 'seventy' 'eighty' 'ninety'' ( hundred!'hundred'( and!'and'(6 superbasethousand!'thousand' 'million' 'billion'' ( units!"(t#units)( teens!"(t#teens)( tens!"(t#tens)( hundred!t#hundred( and!t#and(/ superbasethousand!"(t#superbasethousand)' ( subhundred!99t#0(C subhundred[(s#9),10,10+s#9]+!units,(1!tens),teens ]# counts 1-19' (; subhundred[(101+s#8)".+(s#10)-1]+!(1!tens)".+(0,units)' (> subhundred!0,(+\subhundred) ]# cumulative count is better(2 units!0,+\units ]# make units also cumulative' ( d!1000 1000000 1000000000' ( Y!=#(4/1000)"Y' (1 nh!(
#Y100) ]# stands for Number of Hundreds(, ho!100|Y ]# stands for Hundred Overflow' ( ptc!(subhundred[100]nh)+subhundred[1+ho] ]# all subhundred letters: first term for full cycles of 100, second term for the last partial cycle' (& ptc+!(and(honhe"1)+(990#nh-1))' (= ptc+!((100units[1#nh])+(ho+1)units[nh+1]-units[1#nh])' (+ ptc+!hundred((ho+1)nhe"1)+1000#nh-1' (h ltc!((hundred+units[nh+1]-units[nh#1])nhe"1)+(subhundred[ho+1]-subhundred[ho#1])+and(ho>0)'"(nhe"1)' (I ftc!(subhundred[100]10)+(and999)+(hundred1009)+(units[10]100)' ' (( pitc!ptc+(andhonh=0)+and99nh`"0( fitc!ftc+and99' (9 ftc,!ftc+(fitc999)+(ftc+superbasethousand[1])d[1]( fitc,!ftc[2]+and992' (? ftc,!ftc[2]+(fitc[2]999)+(ftc+superbasethousand[2])d[2]( fitc,!ftc[3]+and993' ( R!0' ' :If Y[4]>0(% R+!ftc[3] ]# count to 1 bill(V R+!fitc[3]Y[4]-1 ]# count 1 bill to Y[4] bill inferiorly (lower digit parts)(d R+!d[3](superbasethousand[3]Y[4]-1)+ptc[4]-ltc[4] ]# count to Y[4] bill (this digit part)' (; R+!(1+d[1]"=#Y[1 2 3])ltc[4]+superbasethousand[3](. R+!and99
#Y[3] ]# for and in millions' ' :EndIf' :If Y[3]>0(% R+!ftc[2] ]# count to 1 mill(V R+!fitc[2]Y[3]-1 ]# count 1 mill to Y[3] mill inferiorly (lower digit parts)(d R+!d[2](superbasethousand[2]Y[3]-1)+ptc[3]-ltc[3] ]# count to Y[3] mill (this digit part)' (9 R+!(1+d[1]"=#Y[1 2])ltc[3]+superbasethousand[2](/ R+!and99
#Y[2] ]# for and in thousands' :EndIf' :If Y[2]>0(% R+!ftc[1] ]# count to 1 thou(V R+!fitc[1]Y[2]-1 ]# count 1 thou to Y[2] thou inferiorly (lower digit parts)(d R+!d[1](superbasethousand[1]Y[2]-1)+ptc[2]-ltc[2] ]# count to Y[2] thou (this digit part)' (1 R+!(1+Y[1])ltc[2]+superbasethousand[1](* R+!and99
#Y[1] ]# for and in ones' :EndIf(X :If Y[1]>0 ]# separated into two lines to show similarity with previous superdigits( R+!ptc[1]-ltc[1]' ( R+!ltc[1]' :EndIf' ( "\P$X|0g\summationsy̭UZ0gDsummationsH@`rܮĴ\ R8ܮdsum1to
Y[gH!>q!*:gp:qr^
g&+ogp:`r`rWaaWSB`$h(@smtIJ@ܮUYܮĴ\|-0ȴsumsquares1to[)!>q!*Dgp:qr^
g&+ogp:`r`Wra`WWraaWSB`$دh@smtIJ<ذ@ܮUY ܮĴDL;\x,ܮX8sumofmultiplestoX<encode[U!(F ('"/1#X,.encode) contains the lcm of all different combinations in Xth\.L(M (1*1-h#+/[1]encode) checks how many numbers were lcm-ed to form each producttNrcl|gp:qrsdtgh+ogoWq^
gt:V%*`` qa@ Wa.# W q^
g
^
ggp:@`W
WJ@b
Wcta`@G
Wq!DtarGsg
^
g
^
g
^
g
^
g
^
g
^
g
^
g
^
g
^
g
^
gogp:q`sqagqo)B`$$ĳ@smtIJ @ܮUY<ܮз,X|(Ltttttt(uTuuuu0`$T,{v P\{{{xy|RD<(\z0|y,yDzp8z||xz@}}0~~|~dp|`LHtHH$t0,lettersinnumbers1tounits|зteenstenssubhundred<hundredandsuperbasethousand(nhHt,hotLptcltcpitcHftctfitctd[Hb!'thirteen'sixteen<'nineteen$(sl'seventyT'thousand<̺'million)>q-BCHMVW]gq{ %&,9?@O[\b{|@AGstz128=>LR`w#NOUv!':IJSYZgp:qrdsdtdudvdwdxdydzd{d|d}d~dddg+ogs:WWWWWWWWWgt:WWWW W!W"W#W$Wgu:%W&W'W(W)W*W+W,W-Wggw:.Wgx:/Wgy:0W1W2Wgg^3
gs:3G` Gsagt:3G` Gtagu:3G` Guagw: wgx: xgy:3G` Gyagg^4
gv:5W 6Wg^7
gvb`#8Wa!9W!9W#8Wc:s!`:W$ua!t^;
gg^<
gvb`9W:W#=Wa8D`#9Wa:Wc:`:W%ua8D`6W!saggv:6W!`Bva^>
gs:6W!Bs^?
gg^@
g:AVgg^B
gr:*`CW@DWa.rg^E
ggz:`rFWa^G
g{:FW
r^H
gg^I
g|:`vbFWczavb:W{c^J
gg^K
g^L
g|:`x`{z:Wa`5W6Wz:Waagg^M
g|:``FWsb:Wzca`{:Wasbz:Wcsb:Wzcagg^N
g|:w``{:Waz:WaFW6Wz:Wgg^O
g}:``wsbz:Wcsbz:Wcaz:Wa`vb{:Wcvb{:Wcax`{6Wa`z:Wagg^P
g:`vbFWc9Wa`x5W8Wa`wFW8Wa`sb9WcFWagg^Q
g^R
g^S
g^T
gg^U
g~:|`x{z6Wax5Wz6Wg:x5Wgg^V
g!:*`WWa`yb:Wcab:Wcg!:*bXWcx5WXWgg^Y
g!:*bXWc`bXWcWWa`ybXWcabXWcg!:*bZWcx5WZWgg^[
gp:6WggorbCWc6Wg
^\
gp:bZWc^]
gp:bZWcrbCWc:W^^
gp:bZWc`ybZWcrbCWc:Wa|bCWc}bCWc^_
gg
^`
g
^a
gp:`:Wb:Wc-*rbbVca}bCWcybZWcgp:x5WrbZWc^c
gg
^d
gCogorbZWc6Wgp:bXWc^e
gp:bXWcrbZWc:W^f
gp:bXWc`ybXWcrbZWc:Wa|bZWc}bZWc^g
gg
^h
gp:`:Wb:Wc-*rbiVca}bZWcybXWcgp:x5WrbXWc^j
gog&orbXWc6Wgp:b:Wc^k
gp:b:WcrbXWc:W^l
gp:b:Wc`yb:WcrbXWc:Wa|bXWc}bXWc^m
gg
^n
gp:`:Wrb:Wca}bXWcyb:Wcgp:x5Wrb:Wc^o
gogXorb:Wc6W^p
gp:|b:Wc}b:Wcggp:}b:Wcg,ogsB`$l,@smtIJ@tL(|X,зܮUYL<!fPpsss0tLttt0u| }D}~Lu~~u\vwwx\yLz${{|pPLԐx\0p4t,Xȕ|̖TllԘP$<h0hHܛ0X̞܉DȊdȋ|Tlpȡ$tУXĤܤt0| 0Ph@X̪0LPhԬTTl|TTT8TPY@Y@<
specialName('A?C:\Users\Ronald\Documents\DyalogContest\ronald_ping_man_chan_208|print"gW#W'BCADCuTl0 D0!-Ver-|X'RonaldTXs$ hD\8'3 this function is used to display character vectors'! containing newlines (paragraphs)8' in a legible format, on screenU8' find location of newline'$ display all up to newline on a linem' drop processed portionBp4:@FQaozgpqdrg^
g^
g^
goW qgr:q#?bWc^
g`r Wa$q^
gq:r%q^
gKo*@s@`$TP$0KJ@
|`'Q9**