Post Reply 
Programming puzzle: Longest list of regular numbers?
04-17-2017, 05:52 PM (This post was last modified: 04-17-2017 06:23 PM by e_emil.)
Post: #18
RE: Programming puzzle: Longest list of regular numbers?
Just 2% difference, you should probably repeat it several times to make sure it's not random Wink

At last, I generated a complete list of (almost) 10,000 first regular numbers in one variable! I got around the memory problem on the nspire by allocating a table of zeros beforehand and making the program fill in the table without changing the structure. The entire calculation took about 13 minutes (just creating a table of zeros was half a minute, a total surprise to me). Sorting the output table is no more than 2 seconds using the built-in command.

   

the code:

Define hamming(smax)=
(C) A global table 'h' has to be defined with enough space for all generated numbers.
(C) The table is not sorted at output. The calculator has to be in exact mode if smax>=39
Prgm
:Local a,b,x,y,zlow,z,s,m
:a:=((ln(2.))/(ln(3.)))
:b:=((ln(2.))/(ln(5.)))
:m:=0
:For s,1,smax
:For x,0,s
: For y,0,floor((s+1-x)*a)
: zlow:=(s-x-((y)/(a)))*b
: z:=floor(zlow+b)
: If ceiling(zlow)=z Then
: m:=m+1
: 2^(x)*3^(y)*5^(z)→h[m]
: EndIf
: EndFor
: EndFor
: EndFor
:EndPrgm

Learning lua has never been my priority so far...
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming puzzle: Longest list of regular numbers? - e_emil - 04-17-2017 05:52 PM



User(s) browsing this thread: 1 Guest(s)