Ulam numbers: Difference between revisions

Added solution for Action!
(Added solution for Action!)
Line 54:
The 1000th Ulam number is 12294
The 10000th Ulam number is 132788
</pre>
 
=={{header|Action!}}==
Calculations on a real Atari 8-bit computer take quite long time. It is recommended to use an emulator capable with increasing speed of Atari CPU.
<lang Action!>PROC Main()
DEFINE MAX="1000"
INT ARRAY ulam(MAX)
INT uCount,n,count,x,y
BYTE flag
 
ulam(0)=1 ulam(1)=2 uCount=2
PrintI(ulam(0)) Put(32) PrintI(ulam(1))
n=3
WHILE uCount<MAX
DO
flag=0 count=0
FOR x=0 TO uCount-2
DO
FOR y=x+1 TO uCount-1
DO
IF ulam(x)+ulam(y)=n THEN
flag=1 count==+1
FI
OD
OD
IF flag=1 AND count=1 THEN
ulam(uCount)=n uCount==+1
Put(32) PrintI(n)
FI
n==+1
OD
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Ulam_numbers.png Screenshot from Atari 8-bit computer]
<pre>
1 2 3 4 6 8 11 13 16 18 26 28 36 38 47 48 53 57 62 69 72 77 82 87 97 99 102 106 114 126 131 138 145 148 155 175 ...
</pre>
 
Anonymous user