Fractran: Difference between revisions

4,467 bytes added ,  2 years ago
m
→‎{{header|REXX}}: commatized the numbers.
m (→‎{{header|REXX}}: added/changed comments and whitespace, optimized a DO loop.)
m (→‎{{header|REXX}}: commatized the numbers.)
Line 3,541:
do k=1 for # /* " " " " " " fraction*/
if N // d.k \== 0 then iterate /*Not an integer? Then ignore it. */
saycN= rightcommas('term'N); j, 35) L= length(cN) "──► " N /*displaymaybe theinsert commas Nthinto N; term get with the Nlen. */
say right('term' commas(j), 44) "──► " right(cN, max(15, L)) /*show Nth term & N*/
N= N % d.k * n.k /*calculate next term (use %≡integer ÷)*/
leave /*go start calculating the next term. */
end /*k*/ /* [↑] if an integer, we found a new N*/
end /*j*/
exit 0 end /*j*/ /*stick a fork in it, we're all done. */</lang>
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</lang>
{{out|output|text=&nbsp; when using the default input:}}
<pre style="height:63ex">
Line 3,551 ⟶ 3,555:
N is starting at 2
100 terms are being shown:
term 1 ──► 2
term 2 ──► 15
term 3 ──► 825
term 4 ──► 725
term 5 ──► 1925 1,925
term 6 ──► 2275 2,275
term 7 ──► 425
term 8 ──► 390
term 9 ──► 330
term 10 ──► 290
term 11 ──► 770
term 12 ──► 910
term 13 ──► 170
term 14 ──► 156
term 15 ──► 132
term 16 ──► 116
term 17 ──► 308
term 18 ──► 364
term 19 ──► 68
term 20 ──► 4
term 21 ──► 30
term 22 ──► 225
term 23 ──► 12375 12,375
term 24 ──► 10875 10,875
term 25 ──► 28875 28,875
term 26 ──► 25375 25,375
term 27 ──► 67375 67,375
term 28 ──► 79625 79,625
term 29 ──► 14875 14,875
term 30 ──► 13650 13,650
term 31 ──► 2550 2,550
term 32 ──► 2340 2,340
term 33 ──► 1980 1,980
term 34 ──► 1740 1,740
term 35 ──► 4620 4,620
term 36 ──► 4060 4,060
term 37 ──► 10780 10,780
term 38 ──► 12740 12,740
term 39 ──► 2380 2,380
term 40 ──► 2184 2,184
term 41 ──► 408
term 42 ──► 152
term 43 ──► 92
term 44 ──► 380
term 45 ──► 230
term 46 ──► 950
term 47 ──► 575
term 48 ──► 2375 2,375
term 49 ──► 9625 9,625
term 50 ──► 11375 11,375
term 51 ──► 2125 2,125
term 52 ──► 1950 1,950
term 53 ──► 1650 1,650
term 54 ──► 1450 1,450
term 55 ──► 3850 3,850
term 56 ──► 4550 4,550
term 57 ──► 850
term 58 ──► 780
term 59 ──► 660
term 60 ──► 580
term 61 ──► 1540 1,540
term 62 ──► 1820 1,820
term 63 ──► 340
term 64 ──► 312
term 65 ──► 264
term 66 ──► 232
term 67 ──► 616
term 68 ──► 728
term 69 ──► 136
term 70 ──► 8
term 71 ──► 60
term 72 ──► 450
term 73 ──► 3375 3,375
term 74 ──► 185625 185,625
term 75 ──► 163125 163,125
term 76 ──► 433125 433,125
term 77 ──► 380625 380,625
term 78 ──► 1010625 1,010,625
term 79 ──► 888125 888,125
term 80 ──► 2358125 2,358,125
term 81 ──► 2786875 2,786,875
term 82 ──► 520625 520,625
term 83 ──► 477750 477,750
term 84 ──► 89250 89,250
term 85 ──► 81900 81,900
term 86 ──► 15300 15,300
term 87 ──► 14040 14,040
term 88 ──► 11880 11,880
term 89 ──► 10440 10,440
term 90 ──► 27720 27,720
term 91 ──► 24360 24,360
term 92 ──► 64680 64,680
term 93 ──► 56840 56,840
term 94 ──► 150920 150,920
term 95 ──► 178360 178,360
term 96 ──► 33320 33,320
term 97 ──► 30576 30,576
term 98 ──► 5712 5,712
term 99 ──► 2128 2,128
term 100 ──► 1288 1,288
</pre>
 
Line 3,678 ⟶ 3,682:
if tell then say terms ' terms are being shown:' /*display header.*/
else say 'only powers of two are being shown:' /* " " */
q@a= '(max digits used:' /*a literal used in the SAY below. */
 
do j=1 for abs(terms) /*perform DO loop once for each term. */
do k=1 for # /* " " " " " " fraction*/
if N // d.k \== 0 then iterate /*Not an integer? Then ignore it. */
ifcN= tell then say rightcommas('term'N); j, 35) "──► " N cj=commas(j) /*displaymaybe Nthinsert termcommas into and N. */
else if !.Ntell then say right('term' jcj,15 44) "──► " @.NcN q right(L,w)") "/*display Nth term and N.*/
else if !.N then say right('term' cj,15) "──►" @.N @a right(L,w)") " cN
N= N % d.k * n.k /*calculate next term (use %≡integer ÷)*/
L= max(L, length(N) ) /*the maximum number of decimal digits.*/
leave /*go start calculating the next term. */
end /*k*/ /* [↑] if an integer, we found a new N*/
end /*j*/
exit 0 end /*j*/ /*stick a fork in it, we're all done. */</lang>
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</lang>
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> , &nbsp; -50000000 </tt>}}
<br>(negative fifty million)
Line 3,696 ⟶ 3,704:
N is starting at 2
only powers of two are being shown:
term 1 ──► 2**1 (max digits used: 1) 2
term 20 ──► (prime 2) 2**2 (max digits used: 4) 4
term 70 ──► (prime 3) 2**3 (max digits used: 5) 8
term 281 ──► (prime 5) 2**5 (max digits used: 8) 32
term 708 ──► (prime 7) 2**7 (max digits used: 12) 128
term 23642,364 ──► (prime 11) 2**11 (max digits used: 18) 20482,048
term 38773,877 ──► (prime 13) 2**13 (max digits used: 21) 81928,192
term 80698,069 ──► (prime 17) 2**17 (max digits used: 27) 131072131,072
term 1132011,320 ──► (prime 19) 2**19 (max digits used: 30) 524288524,288
term 1920219,202 ──► (prime 23) 2**23 (max digits used: 36) 83886088,388,608
term 3686736,867 ──► (prime 29) 2**29 (max digits used: 46) 536870912536,870,912
term 4555245,552 ──► (prime 31) 2**31 (max digits used: 49) 21474836482,147,483,648
term 7522575,225 ──► (prime 37) 2**37 (max digits used: 58) 137438953472137,438,953,472
term 101,113 ──► (prime 41) 2**41 (max digits used: 64) 2,199,023,255,552
term 117,832 ──► (prime 43) 2**43 (max digits used: 67) 8,796,093,022,208
term 152,026 ──► (prime 47) 2**47 (max digits used: 73) 140,737,488,355,328
term 215,385 ──► (prime 53) 2**53 (max digits used: 83) 9,007,199,254,740,992
term 293,376 ──► (prime 59) 2**59 (max digits used: 92) 576,460,752,303,423,488
term 327,021 ──► (prime 61) 2**61 (max digits used: 95) 2,305,843,009,213,693,952
term 428,554 ──► (prime 67) 2**67 (max digits used: 104) 147,573,952,589,676,412,928
term 507,520 ──► (prime 71) 2**71 (max digits used: 110) 2,361,183,241,434,822,606,848
term 555,695 ──► (prime 73) 2**73 (max digits used: 113) 9,444,732,965,739,290,427,392
term 700,064 ──► (prime 79) 2**79 (max digits used: 123) 604,462,909,807,314,587,353,088
term 808,332 ──► (prime 83) 2**83 (max digits used: 129) 9,671,406,556,917,033,397,649,408
term 989,527 ──► (prime 89) 2**89 (max digits used: 138) 618,970,019,642,690,137,449,562,112
term 1,273,491 ──► (prime 97) 2**97 (max digits used: 151) 158,456,325,028,528,675,187,087,900,672
term 1,434,367 ──► (prime 101) 2**101 (max digits used: 157) 2,535,301,200,456,458,802,993,406,410,752
term 1,530,214 ──► (prime 103) 2**103 (max digits used: 160) 10,141,204,801,825,835,211,973,625,643,008
...
(some output elided.)
...
term 193455490193,455,490 ──► (prime 523) 2**523 (max digits used: 808) 2745919064052243885992760319632557286907774120057322163757785383674217273359062420849023856264581821990918524556592343214848795199886657525029611316446022860827,459,190,640,522,438,859,927,603,196,325,572,869,077,741,200,573,221,637,577,853,836,742,172,733,590,624,208,490,238,562,645,818,219,909,185,245,565,923,432,148,487,951,998,866,575,250,296,113,164,460,228,608
</pre>
Output note: &nbsp; There are intermediary numbers (that aren't powers of two) that are hundreds of digits long. <br><br>