Post Reply 
Programming puzzle: Longest list of regular numbers?
04-16-2017, 08:22 PM (This post was last modified: 04-16-2017 09:43 PM by e_emil.)
Post: #3
RE: Programming puzzle: Longest list of regular numbers?
Greetings from a new user on the forumSmile

105 seconds on a 50g was enough to find 580 first "regular" numbers, put them in order on the stack and tag each number by its consecutive number.

580'th regular number is 2073600

RPL code:
<< 20 2. LN 3. LN / 2. LN 5. LN / 0. 0. -> smax a b m n
<< 1. smax
FOR s 0. s
FOR x 0. s 1. + x - a * FLOOR
FOR y s x - y a / - b * DUP CEIL 0. MAX SWAP b + FLOOR DUP ROT ==
IF THEN 5. SWAP ^ 2. x ^ 3. y ^ * * 1. 'm' STO+
ELSE DROP
END
NEXT
NEXT
m ->LIST SORT 'k+n' 'k' 1. m 1. SEQ 2. << ->TAG >> DOLIST
OBJ-> DROP m 'n' STO+ 0. 'm' STO
NEXT
>>
>>

Description of the code: the outer loop (FOR s) finds all regular numbers between 2^s and 2^(s+1). The list is then sorted and output on the stack. The code proceeds to the next value of s, until smax (20 in the example above).

In other words, the code above finds all regular numbers smaler than 2^21, and it seems that there are 580 such numbers.

The number immediately after the last one found, will be always a power of two and it can be added manually:

580th number = 2073600 (last line of the program)
581st number = 2^21 = 2097152

I was thinking geometrically when writing the code: in a 3-d coordinate system, every point with non-negative integer coordinates corresponds to a regular number, i.e. (x,y,z) corresponds to 2^x*3^y*5^z. The inequality s <= x + y*(ln 3/ln2) + z(ln 5/ln2) < s+1 represents a "slab" in the coordinate system which contains all regular numbers greater than 2^s but smaller than 2^(s+1). (You can say that "slabs" are perpendicular to the direction of increasing regular numbers.) My code searches each such slab for points of integral coordinates, then generates a sorted list of 2^x3^y5^z and proceeds to the nest "slab" a bit further from the origin. "smax" in the beginning is the total number of slabs to be searched.
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-16-2017 08:22 PM



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