How to resolve the algorithm Ludic numbers step by step in the 360 Assembly programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Ludic numbers step by step in the 360 Assembly programming language
Table of Contents
Problem Statement
Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers. The first ludic number is 1. To generate succeeding ludic numbers create an array of increasing integers starting from 2. (Loop)
Show all triplets of ludic numbers < 250.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Ludic numbers step by step in the 360 Assembly programming language
Source code in the 360 programming language
* Ludic numbers 23/04/2016
LUDICN CSECT
USING LUDICN,R15 set base register
LH R9,NMAX r9=nmax
SRA R9,1 r9=nmax/2
LA R6,2 i=2
LOOPI1 CR R6,R9 do i=2 to nmax/2
BH ELOOPI1
LA R1,LUDIC-1(R6) @ludic(i)
CLI 0(R1),X'01' if ludic(i)
BNE ELOOPJ1
SR R8,R8 n=0
LA R7,1(R6) j=i+1
LOOPJ1 CH R7,NMAX do j=i+1 to nmax
BH ELOOPJ1
LA R1,LUDIC-1(R7) @ludic(j)
CLI 0(R1),X'01' if ludic(j)
BNE NOTJ1
LA R8,1(R8) n=n+1
NOTJ1 CR R8,R6 if n=i
BNE NDIFI
LA R1,LUDIC-1(R7) @ludic(j)
MVI 0(R1),X'00' ludic(j)=false
SR R8,R8 n=0
NDIFI LA R7,1(R7) j=j+1
B LOOPJ1
ELOOPJ1 LA R6,1(R6) i=i+1
B LOOPI1
ELOOPI1 XPRNT =C'First 25 ludic numbers:',23
LA R10,BUF @buf=0
SR R8,R8 n=0
LA R6,1 i=1
LOOPI2 CH R6,NMAX do i=1 to nmax
BH ELOOPI2
LA R1,LUDIC-1(R6) @ludic(i)
CLI 0(R1),X'01' if ludic(i)
BNE NOTI2
XDECO R6,XDEC i
MVC 0(4,R10),XDEC+8 output i
LA R10,4(R10) @buf=@buf+4
LA R8,1(R8) n=n+1
LR R2,R8 n
SRDA R2,32
D R2,=F'5' r2=mod(n,5)
LTR R2,R2 if mod(n,5)=0
BNZ NOTI2
XPRNT BUF,20
LA R10,BUF @buf=0
NOTI2 EQU *
CH R8,=H'25' if n=25
BE ELOOPI2
LA R6,1(R6) i=i+1
B LOOPI2
ELOOPI2 MVC BUF(25),=C'Ludic numbers below 1000:'
SR R8,R8 n=0
LA R6,1 i=1
LOOPI3 CH R6,=H'999' do i=1 to 999
BH ELOOPI3
LA R1,LUDIC-1(R6) @ludic(i)
CLI 0(R1),X'01' if ludic(i)
BNE NOTI3
LA R8,1(R8) n=n+1
NOTI3 LA R6,1(R6) i=i+1
B LOOPI3
ELOOPI3 XDECO R8,XDEC edit n
MVC BUF+25(6),XDEC+6 output n
XPRNT BUF,31 print buffer
MVC BUF(80),=CL80'Ludic numbers 2000 to 2005:'
LA R10,BUF+28 @buf=28
SR R8,R8 n=0
LA R6,1 i=1
LOOPI4 CH R6,NMAX do i=1 to nmax
BH ELOOPI4
LA R1,LUDIC-1(R6) @ludic(i)
CLI 0(R1),X'01' if ludic(i)
BNE NOTI4
LA R8,1(R8) n=n+1
CH R8,=H'2000' if n>=2000
BL NOTI4
XDECO R6,XDEC edit i
MVC 0(6,R10),XDEC+6 output i
LA R10,6(R10) @buf=@buf+6
CH R8,=H'2005' if n=2005
BE ELOOPI4
NOTI4 LA R6,1(R6) i=i+1
B LOOPI4
ELOOPI4 XPRNT BUF,80 print buffer
XPRNT =C'Ludic triplets below 250:',25
LA R6,1 i=1
LOOPI5 CH R6,=H'243' do i=1 to 243
BH ELOOPI5
LA R1,LUDIC-1(R6) @ludic(i)
CLI 0(R1),X'01' if ludic(i)
BNE ITERI5
LA R1,LUDIC+1(R6) @ludic(i+2)
CLI 0(R1),X'01' if ludic(i+2)
BNE ITERI5
LA R1,LUDIC+5(R6) @ludic(i+6)
CLI 0(R1),X'01' if ludic(i+6)
BNE ITERI5
MVC BUF+0(1),=C'[' [
XDECO R6,XDEC edit i
MVC BUF+1(4),XDEC+8 output i
LA R2,2(R6) i+2
XDECO R2,XDEC edit i+2
MVC BUF+5(4),XDEC+8 output i+2
LA R2,6(R6) i+6
XDECO R2,XDEC edit i+6
MVC BUF+9(4),XDEC+8 output i+6
MVC BUF+13(1),=C']' ]
XPRNT BUF,14 print buffer
ITERI5 LA R6,1(R6) i=i+1
B LOOPI5
ELOOPI5 XR R15,R15 set return code
BR R14 return to caller
LTORG
BUF DS CL80 buffer
XDEC DS CL12 decimal editor
NMAX DC H'25000' nmax
LUDIC DC 25000X'01' ludic(nmax)=true
YREGS
END LUDICN
You may also check:How to resolve the algorithm Sum of elements below main diagonal of matrix step by step in the Raku programming language
You may also check:How to resolve the algorithm String length step by step in the OCaml programming language
You may also check:How to resolve the algorithm Sorting algorithms/Cocktail sort step by step in the Tcl programming language
You may also check:How to resolve the algorithm Number names step by step in the zkl programming language
You may also check:How to resolve the algorithm Monads/Writer monad step by step in the AppleScript programming language