Ludic numbers: Difference between revisions

Content added Content deleted
Line 29: Line 29:
* Show the 2000..2005'th ludic numbers.
* Show the 2000..2005'th ludic numbers.
* A triplet is any three numbers <math>x,</math> <math>x+2,</math> <math>x+6</math> where all three numbers are also ludic numbers. Show all triplets of ludic numbers < 250 (Stretch goal)
* A triplet is any three numbers <math>x,</math> <math>x+2,</math> <math>x+6</math> where all three numbers are also ludic numbers. Show all triplets of ludic numbers < 250 (Stretch goal)

=={{header|360 Assembly}}==
{{trans|Fortran}}
<lang 360asm>
* 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
</lang>
{{out}}
<pre>
First 25 ludic numbers:
1 2 3 5 7
11 13 17 23 25
29 37 41 43 47
53 61 67 71 77
83 89 91 97 107
Ludic numbers below 1000: 142
Ludic numbers 2000 to 2005: 21475 21481 21487 21493 21503 21511
Ludic triplets below 250:
[ 1 3 7]
[ 5 7 11]
[ 11 13 17]
[ 23 25 29]
[ 41 43 47]
[ 173 175 179]
[ 221 223 227]
[ 233 235 239]
</pre>


=={{header|ABAP}}==
=={{header|ABAP}}==