Ulam numbers: Difference between revisions
Content added Content deleted
(→{{header|Vlang}}: Rename "Vlang" in "V (Vlang)") |
PatGarrett (talk | contribs) (→{{header|360 Assembly}}: Section added) |
||
Line 54: | Line 54: | ||
The 1000th Ulam number is 12294 |
The 1000th Ulam number is 12294 |
||
The 10000th Ulam number is 132788 |
The 10000th Ulam number is 132788 |
||
</pre> |
|||
=={{header|360 Assembly}}== |
|||
<syntaxhighlight lang="360asm">* Ulam numbers 25/01/2021 |
|||
ULAMNUM CSECT |
|||
USING ULAMNUM,R13 base register |
|||
B 72(R15) skip savearea |
|||
DC 17F'0' savearea |
|||
SAVE (14,12) save previous context |
|||
ST R13,4(R15) link backward |
|||
ST R15,8(R13) link forward |
|||
LR R13,R15 set addressability |
|||
LA R1,1 1 |
|||
ST R1,ULAM ulam(1)=1 |
|||
LA R1,2 2 |
|||
ST R1,ULAM+4 ulam(2)=2 |
|||
LA R9,2 k=2 |
|||
LA R8,2 n=2 |
|||
DO WHILE=(C,R9,LT,NN) do while k<nn |
|||
LA R8,1(R8) n=n+1 |
|||
XR R10,R10 count=0 |
|||
LR R0,R9 k |
|||
BCTR R0,0 -1 |
|||
LA R6,1 i=1 |
|||
DO WHILE=(CR,R6,LE,R0) do i=1 to k-1 |
|||
LR R7,R6 i |
|||
LA R7,1(R7) j=i+1 |
|||
DO WHILE=(CR,R7,LE,R9) do j=i+1 to k |
|||
LR R1,R6 i |
|||
SLA R1,2 ~ |
|||
L R2,ULAM-4(R1) ulam(i) |
|||
LR R1,R7 j |
|||
SLA R1,2 ~ |
|||
L R3,ULAM-4(R1) ulam(j) |
|||
AR R2,R3 ulam(i)+ulam(j) |
|||
IF CR,R2,EQ,R8 THEN if ulam(i)+ulam(j)=n then |
|||
LA R10,1(R10) count=count+1 |
|||
ENDIF , endif |
|||
LA R7,1(R7) j++ |
|||
ENDDO , enddo j |
|||
LA R6,1(R6) i++ |
|||
ENDDO , enddo i |
|||
IF C,R10,EQ,=F'1' THEN if count=1 then |
|||
LA R9,1(R9) k=k+1 |
|||
LR R1,R9 k |
|||
SLA R1,2 ~ |
|||
ST R8,ULAM-4(R1) ulam(k)=n |
|||
LR R4,R9 k |
|||
SRDA R4,32 ~ |
|||
D R4,=F'50' k/50 |
|||
IF LTR,R4,Z,R4 THEN if mod(k,50)=0 then |
|||
XDECO R9,PG k |
|||
XDECO R8,PG+12 n |
|||
XPRNT PG,L'PG print buffer |
|||
ENDIF , endif |
|||
ENDIF , endif |
|||
ENDDO , enddo n |
|||
L R13,4(0,R13) restore previous savearea pointer |
|||
RETURN (14,12),RC=0 restore registers from calling save |
|||
U EQU 500 u : max value |
|||
NN DC A(U) nn |
|||
ULAM DS (U)F ulam(u) |
|||
PG DC CL80' ' buffer |
|||
REGEQU |
|||
END ULAMNUM</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
50 253 |
|||
100 690 |
|||
150 1257 |
|||
200 1792 |
|||
250 2484 |
|||
300 3068 |
|||
350 3632 |
|||
400 4326 |
|||
450 4996 |
|||
500 5685 |
|||
</pre> |
</pre> |
||