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.

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...
(Loop)

 Take the first member of the resultant array as the next ludic number   2.
 Remove every   2nd   indexed item from the array (including the first).
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...
 (Unrolling a few loops...)
 Take the first member of the resultant array as the next ludic number   3.
 Remove every   3rd   indexed item from the array (including the first).
3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 ...
 Take the first member of the resultant array as the next ludic number   5.
 Remove every   5th   indexed item from the array (including the first).
5 7 11 13 17 19 23 25 29 31 35 37 41 43 47 49 53 55 59 61 65 67 71 73 77 ...
 Take the first member of the resultant array as the next ludic number   7.
 Remove every   7th   indexed item from the array (including the first).
7 11 13 17 23 25 29 31 37 41 43 47 53 55 59 61 67 71 73 77 83 85 89 91 97 ...
  ... 
 Take the first member of the current array as the next ludic number   L.
 Remove every   Lth   indexed item from the array (including the first).
  ... 


Task

 Generate and show here the first 25 ludic numbers.
 How many ludic numbers are there less than or equal to 1000?
 Show the 2000..2005th ludic numbers.


Stretch goal

Show all triplets of ludic numbers < 250.

 A triplet is any three numbers     



x
,


{\displaystyle x,}

   



x
+
2
,


{\displaystyle x+2,}

   



x
+
6


{\displaystyle x+6}

      where all three numbers are also ludic numbers. 


*        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