Fractran: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added/changed comments and whitespace, optimized a DO loop.) |
m (→{{header|REXX}}: commatized the numbers.) |
||
Line 3,541: | Line 3,541: | ||
do k=1 for # /* " " " " " " fraction*/ |
do k=1 for # /* " " " " " " fraction*/ |
||
if N // d.k \== 0 then iterate /*Not an integer? Then ignore it. */ |
if N // d.k \== 0 then iterate /*Not an integer? Then ignore it. */ |
||
cN= commas(N); L= length(cN) /*maybe insert commas into N; get len.*/ |
|||
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 ÷)*/ |
N= N % d.k * n.k /*calculate next term (use %≡integer ÷)*/ |
||
leave /*go start calculating the next term. */ |
leave /*go start calculating the next term. */ |
||
end /*k*/ /* [↑] if an integer, we found a new N*/ |
end /*k*/ /* [↑] if an integer, we found a new N*/ |
||
end /*j*/ |
|||
exit 0 /*stick a fork in it, we're all done. */ |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</lang> |
|||
{{out|output|text= when using the default input:}} |
{{out|output|text= when using the default input:}} |
||
<pre style="height:63ex"> |
<pre style="height:63ex"> |
||
Line 3,551: | Line 3,555: | ||
N is starting at 2 |
N is starting at 2 |
||
100 terms are being shown: |
100 terms are being shown: |
||
term 1 ──► 2 |
term 1 ──► 2 |
||
term 2 ──► 15 |
term 2 ──► 15 |
||
term 3 ──► 825 |
term 3 ──► 825 |
||
term 4 ──► 725 |
term 4 ──► 725 |
||
term 5 ──► |
term 5 ──► 1,925 |
||
term 6 ──► |
term 6 ──► 2,275 |
||
term 7 ──► 425 |
term 7 ──► 425 |
||
term 8 ──► 390 |
term 8 ──► 390 |
||
term 9 ──► 330 |
term 9 ──► 330 |
||
term 10 ──► 290 |
term 10 ──► 290 |
||
term 11 ──► 770 |
term 11 ──► 770 |
||
term 12 ──► 910 |
term 12 ──► 910 |
||
term 13 ──► 170 |
term 13 ──► 170 |
||
term 14 ──► 156 |
term 14 ──► 156 |
||
term 15 ──► 132 |
term 15 ──► 132 |
||
term 16 ──► 116 |
term 16 ──► 116 |
||
term 17 ──► 308 |
term 17 ──► 308 |
||
term 18 ──► 364 |
term 18 ──► 364 |
||
term 19 ──► 68 |
term 19 ──► 68 |
||
term 20 ──► 4 |
term 20 ──► 4 |
||
term 21 ──► 30 |
term 21 ──► 30 |
||
term 22 ──► 225 |
term 22 ──► 225 |
||
term 23 ──► |
term 23 ──► 12,375 |
||
term 24 ──► |
term 24 ──► 10,875 |
||
term 25 ──► |
term 25 ──► 28,875 |
||
term 26 ──► |
term 26 ──► 25,375 |
||
term 27 ──► |
term 27 ──► 67,375 |
||
term 28 ──► |
term 28 ──► 79,625 |
||
term 29 ──► |
term 29 ──► 14,875 |
||
term 30 ──► |
term 30 ──► 13,650 |
||
term 31 ──► |
term 31 ──► 2,550 |
||
term 32 ──► |
term 32 ──► 2,340 |
||
term 33 ──► |
term 33 ──► 1,980 |
||
term 34 ──► |
term 34 ──► 1,740 |
||
term 35 ──► |
term 35 ──► 4,620 |
||
term 36 ──► |
term 36 ──► 4,060 |
||
term 37 ──► |
term 37 ──► 10,780 |
||
term 38 ──► |
term 38 ──► 12,740 |
||
term 39 ──► |
term 39 ──► 2,380 |
||
term 40 ──► |
term 40 ──► 2,184 |
||
term 41 ──► 408 |
term 41 ──► 408 |
||
term 42 ──► 152 |
term 42 ──► 152 |
||
term 43 ──► 92 |
term 43 ──► 92 |
||
term 44 ──► 380 |
term 44 ──► 380 |
||
term 45 ──► 230 |
term 45 ──► 230 |
||
term 46 ──► 950 |
term 46 ──► 950 |
||
term 47 ──► 575 |
term 47 ──► 575 |
||
term 48 ──► |
term 48 ──► 2,375 |
||
term 49 ──► |
term 49 ──► 9,625 |
||
term 50 ──► |
term 50 ──► 11,375 |
||
term 51 ──► |
term 51 ──► 2,125 |
||
term 52 ──► |
term 52 ──► 1,950 |
||
term 53 ──► |
term 53 ──► 1,650 |
||
term 54 ──► |
term 54 ──► 1,450 |
||
term 55 ──► |
term 55 ──► 3,850 |
||
term 56 ──► |
term 56 ──► 4,550 |
||
term 57 ──► 850 |
term 57 ──► 850 |
||
term 58 ──► 780 |
term 58 ──► 780 |
||
term 59 ──► 660 |
term 59 ──► 660 |
||
term 60 ──► 580 |
term 60 ──► 580 |
||
term 61 ──► |
term 61 ──► 1,540 |
||
term 62 ──► |
term 62 ──► 1,820 |
||
term 63 ──► 340 |
term 63 ──► 340 |
||
term 64 ──► 312 |
term 64 ──► 312 |
||
term 65 ──► 264 |
term 65 ──► 264 |
||
term 66 ──► 232 |
term 66 ──► 232 |
||
term 67 ──► 616 |
term 67 ──► 616 |
||
term 68 ──► 728 |
term 68 ──► 728 |
||
term 69 ──► 136 |
term 69 ──► 136 |
||
term 70 ──► 8 |
term 70 ──► 8 |
||
term 71 ──► 60 |
term 71 ──► 60 |
||
term 72 ──► 450 |
term 72 ──► 450 |
||
term 73 ──► |
term 73 ──► 3,375 |
||
term 74 ──► |
term 74 ──► 185,625 |
||
term 75 ──► |
term 75 ──► 163,125 |
||
term 76 ──► |
term 76 ──► 433,125 |
||
term 77 ──► |
term 77 ──► 380,625 |
||
term 78 ──► |
term 78 ──► 1,010,625 |
||
term 79 ──► |
term 79 ──► 888,125 |
||
term 80 ──► |
term 80 ──► 2,358,125 |
||
term 81 ──► |
term 81 ──► 2,786,875 |
||
term 82 ──► |
term 82 ──► 520,625 |
||
term 83 ──► |
term 83 ──► 477,750 |
||
term 84 ──► |
term 84 ──► 89,250 |
||
term 85 ──► |
term 85 ──► 81,900 |
||
term 86 ──► |
term 86 ──► 15,300 |
||
term 87 ──► |
term 87 ──► 14,040 |
||
term 88 ──► |
term 88 ──► 11,880 |
||
term 89 ──► |
term 89 ──► 10,440 |
||
term 90 ──► |
term 90 ──► 27,720 |
||
term 91 ──► |
term 91 ──► 24,360 |
||
term 92 ──► |
term 92 ──► 64,680 |
||
term 93 ──► |
term 93 ──► 56,840 |
||
term 94 ──► |
term 94 ──► 150,920 |
||
term 95 ──► |
term 95 ──► 178,360 |
||
term 96 ──► |
term 96 ──► 33,320 |
||
term 97 ──► |
term 97 ──► 30,576 |
||
term 98 ──► |
term 98 ──► 5,712 |
||
term 99 ──► |
term 99 ──► 2,128 |
||
term 100 ──► |
term 100 ──► 1,288 |
||
</pre> |
</pre> |
||
Line 3,678: | Line 3,682: | ||
if tell then say terms ' terms are being shown:' /*display header.*/ |
if tell then say terms ' terms are being shown:' /*display header.*/ |
||
else say 'only powers of two are being shown:' /* " " */ |
else say 'only powers of two are being shown:' /* " " */ |
||
@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 j=1 for abs(terms) /*perform DO loop once for each term. */ |
||
do k=1 for # /* " " " " " " fraction*/ |
do k=1 for # /* " " " " " " fraction*/ |
||
if N // d.k \== 0 then iterate /*Not an integer? Then ignore it. */ |
if N // d.k \== 0 then iterate /*Not an integer? Then ignore it. */ |
||
cN= commas(N); cj=commas(j) /*maybe insert commas into N. */ |
|||
if tell then say right('term' cj, 44) "──► " cN /*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 ÷)*/ |
N= N % d.k * n.k /*calculate next term (use %≡integer ÷)*/ |
||
L= max(L, length(N) ) /*the maximum number of decimal digits.*/ |
L= max(L, length(N) ) /*the maximum number of decimal digits.*/ |
||
leave /*go start calculating the next term. */ |
leave /*go start calculating the next term. */ |
||
end /*k*/ /* [↑] if an integer, we found a new N*/ |
end /*k*/ /* [↑] if an integer, we found a new N*/ |
||
end /*j*/ |
|||
exit 0 /*stick a fork in it, we're all done. */ |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</lang> |
|||
{{out|output|text= when using the input of: <tt> , -50000000 </tt>}} |
{{out|output|text= when using the input of: <tt> , -50000000 </tt>}} |
||
<br>(negative fifty million) |
<br>(negative fifty million) |
||
Line 3,696: | Line 3,704: | ||
N is starting at 2 |
N is starting at 2 |
||
only powers of two are being shown: |
only powers of two are being shown: |
||
term 1 |
term 1 ──► 2**1 (max digits used: 1) 2 |
||
term 20 ──► (prime 2) 2**2 (max digits used: 4) 4 |
term 20 ──► (prime 2) 2**2 (max digits used: 4) 4 |
||
term 70 ──► (prime 3) 2**3 (max digits used: 5) 8 |
term 70 ──► (prime 3) 2**3 (max digits used: 5) 8 |
||
term 281 ──► (prime 5) 2**5 (max digits used: 8) 32 |
term 281 ──► (prime 5) 2**5 (max digits used: 8) 32 |
||
term 708 ──► (prime 7) 2**7 (max digits used: 12) 128 |
term 708 ──► (prime 7) 2**7 (max digits used: 12) 128 |
||
term |
term 2,364 ──► (prime 11) 2**11 (max digits used: 18) 2,048 |
||
term |
term 3,877 ──► (prime 13) 2**13 (max digits used: 21) 8,192 |
||
term |
term 8,069 ──► (prime 17) 2**17 (max digits used: 27) 131,072 |
||
term |
term 11,320 ──► (prime 19) 2**19 (max digits used: 30) 524,288 |
||
term |
term 19,202 ──► (prime 23) 2**23 (max digits used: 36) 8,388,608 |
||
term |
term 36,867 ──► (prime 29) 2**29 (max digits used: 46) 536,870,912 |
||
term |
term 45,552 ──► (prime 31) 2**31 (max digits used: 49) 2,147,483,648 |
||
term |
term 75,225 ──► (prime 37) 2**37 (max digits used: 58) 137,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.) |
(some output elided.) |
||
... |
... |
||
term 193,455,490 ──► (prime 523) 2**523 (max digits used: 808) 27,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> |
</pre> |
||
Output note: There are intermediary numbers (that aren't powers of two) that are hundreds of digits long. <br><br> |
Output note: There are intermediary numbers (that aren't powers of two) that are hundreds of digits long. <br><br> |