Increasing gaps between consecutive Niven numbers: Difference between revisions

Add MAD
(Add Cowgol)
(Add MAD)
Line 712:
276 1,039,028,518 18,879,988,824
</pre>
 
=={{header|MAD}}==
The original hardware MAD ran on had 36-bit words, so in theory it could calculate
32 gaps. However, that takes a couple of minutes even on modern hardware, so that would probably
not count as "practical" to actually try on an IBM 704. Therefore, this program only prints
as many as required by the task.
 
Furthermore, the optimization in the divisibility check that others do here
(checking divisibility by 2 using bitwise operations), has to be left out since
MAD does not have bitwise operations. It's possible to fake them using division,
but that would not be much of an optimization.
<lang MAD> NORMAL MODE IS INTEGER
INTERNAL FUNCTION REM.(A,B) = A-A/B*B
PRINT COMMENT $ GAP NO GAP NIVEN INDEX NIVEN NUMBER$
PRINT COMMENT $ ****** *** *********** ************$
VECTOR VALUES FMT = $I6,S2,I3,S2,I11,S2,I12*$
 
PREV = 1
GAP = 0
SUM = 0
NIVIX = 0
GAPIX = 1
THROUGH LOOP, FOR NIVEN=1, 1, GAPIX.G.22
SUM = SUM + 1
N = NIVEN
DSUM WHENEVER N.G.0 .AND. REM.(N,10).E.0
SUM = SUM - 9
N = N / 10
TRANSFER TO DSUM
END OF CONDITIONAL
WHENEVER REM.(NIVEN,SUM).E.0
WHENEVER NIVEN.G.PREV+GAP
GAP = NIVEN-PREV
PRINT FORMAT FMT,GAPIX,GAP,NIVIX,PREV
GAPIX = GAPIX + 1
END OF CONDITIONAL
PREV = NIVEN
NIVIX = NIVIX + 1
END OF CONDITIONAL
LOOP CONTINUE
 
END OF PROGRAM </lang>
 
{{out}}
 
<pre>GAP NO GAP NIVEN INDEX NIVEN NUMBER
****** *** *********** ************
1 1 1 1
2 2 10 10
3 6 11 12
4 7 26 63
5 8 28 72
6 10 32 90
7 12 83 288
8 14 102 378
9 18 143 558
10 23 561 2889
11 32 716 3784
12 36 1118 6480
13 44 2948 19872
14 45 4194 28971
15 54 5439 38772
16 60 33494 297864
17 66 51544 478764
18 72 61588 589860
19 88 94748 989867
20 90 265336 2879865
21 99 800054 9898956
22 108 3750017 49989744</pre>
 
=={{header|Nim}}==
2,094

edits