Fractran: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 133: Line 133:
100 : 1288
100 : 1288
</pre>
</pre>



=={{header|Ada}}==
=={{header|Ada}}==
Line 389: Line 388:


This file can be opened with a spreadsheet to draw the successive states of the prime numbers (with countif) and then look how the computation is done in successive steps.
This file can be opened with a spreadsheet to draw the successive states of the prime numbers (with countif) and then look how the computation is done in successive steps.



=={{header|Batch File}}==
=={{header|Batch File}}==
Line 1,032: Line 1,030:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71
</pre>
</pre>

=={{header|Fōrmulæ}}==

In [https://wiki.formulae.org/Fractran this] page you can see the solution of this task.

Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.

The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.


=={{header|Fortran}}==
=={{header|Fortran}}==
Line 1,723: Line 1,713:
42 34533967 181
42 34533967 181
43 40326168 191</pre>
43 40326168 191</pre>

=={{header|Fōrmulæ}}==

In [https://wiki.formulae.org/Fractran this] page you can see the solution of this task.

Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.

The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.


=={{header|Go}}==
=={{header|Go}}==
Line 2,657: Line 2,655:


If you uncomment the <pre>#print $n</pre>, it will print all the steps.
If you uncomment the <pre>#print $n</pre>, it will print all the steps.

=={{header|Perl 6}}==
{{works with|rakudo|2015-11-03}}
A Fractran program potentially returns an infinite list, and infinite lists are a common data structure in Perl 6. The limit is therefore enforced only by slicing the infinite list.
<lang perl6>sub fractran(@program) {
2, { first Int, map (* * $_).narrow, @program } ... 0
}
say fractran(<17/91 78/85 19/51 23/38 29/33 77/29 95/23 77/19 1/17 11/13 13/11
15/14 15/2 55/1>)[^100];</lang>
{{out}}
<pre>(2 15 825 725 1925 2275 425 390 330 290 770 910 170 156 132 116 308 364 68 4 30 225 12375 10875 28875 25375 67375 79625 14875 13650 2550 2340 1980 1740 4620 4060 10780 12740 2380 2184 408 152 92 380 230 950 575 2375 9625 11375 2125 1950 1650 1450 3850 4550 850 780 660 580 1540 1820 340 312 264 232 616 728 136 8 60 450 3375 185625 163125 433125 380625 1010625 888125 2358125 2786875 520625 477750 89250 81900 15300 14040 11880 10440 27720 24360 64680 56840 150920 178360 33320 30576 5712 2128 1288)</pre>
'''Extra credit:'''
We can weed out all the powers of two into another infinite constant list based on the first list. In this case the sequence is limited only by our patience, and a ^C from the terminal. The <tt>.msb</tt> method finds the most significant bit of an integer, which conveniently is the base-2 log of the power-of-two in question.
<lang perl6>sub fractran(@program) {
2, { first Int, map (* * $_).narrow, @program } ... 0
}
for fractran <17/91 78/85 19/51 23/38 29/33 77/29 95/23 77/19 1/17 11/13 13/11
15/14 15/2 55/1> {
say $++, "\t", .msb, "\t", $_ if 1 +< .msb == $_;
}</lang>
{{out}}
<pre>
0 1 2
1 2 4
2 3 8
3 5 32
4 7 128
5 11 2048
6 13 8192
7 17 131072
8 19 524288
9 23 8388608
^C</pre>


=={{header|Phix}}==
=={{header|Phix}}==
Line 2,962: Line 2,927:
<pre>First 15 members of fractran(2):
<pre>First 15 members of fractran(2):
2 15 825 725 1925 2275 425 390 330 290 770 910 170 156 132</pre>
2 15 825 725 1925 2275 425 390 330 290 770 910 170 156 132</pre>

=={{header|Raku}}==
(formerly Perl 6)
{{works with|rakudo|2015-11-03}}
A Fractran program potentially returns an infinite list, and infinite lists are a common data structure in Perl 6. The limit is therefore enforced only by slicing the infinite list.
<lang perl6>sub fractran(@program) {
2, { first Int, map (* * $_).narrow, @program } ... 0
}
say fractran(<17/91 78/85 19/51 23/38 29/33 77/29 95/23 77/19 1/17 11/13 13/11
15/14 15/2 55/1>)[^100];</lang>
{{out}}
<pre>(2 15 825 725 1925 2275 425 390 330 290 770 910 170 156 132 116 308 364 68 4 30 225 12375 10875 28875 25375 67375 79625 14875 13650 2550 2340 1980 1740 4620 4060 10780 12740 2380 2184 408 152 92 380 230 950 575 2375 9625 11375 2125 1950 1650 1450 3850 4550 850 780 660 580 1540 1820 340 312 264 232 616 728 136 8 60 450 3375 185625 163125 433125 380625 1010625 888125 2358125 2786875 520625 477750 89250 81900 15300 14040 11880 10440 27720 24360 64680 56840 150920 178360 33320 30576 5712 2128 1288)</pre>
'''Extra credit:'''
We can weed out all the powers of two into another infinite constant list based on the first list. In this case the sequence is limited only by our patience, and a ^C from the terminal. The <tt>.msb</tt> method finds the most significant bit of an integer, which conveniently is the base-2 log of the power-of-two in question.
<lang perl6>sub fractran(@program) {
2, { first Int, map (* * $_).narrow, @program } ... 0
}
for fractran <17/91 78/85 19/51 23/38 29/33 77/29 95/23 77/19 1/17 11/13 13/11
15/14 15/2 55/1> {
say $++, "\t", .msb, "\t", $_ if 1 +< .msb == $_;
}</lang>
{{out}}
<pre>
0 1 2
1 2 4
2 3 8
3 5 32
4 7 128
5 11 2048
6 13 8192
7 17 131072
8 19 524288
9 23 8388608
^C</pre>


=={{header|REXX}}==
=={{header|REXX}}==
Line 3,544: Line 3,543:
1288
1288
</pre>
</pre>



=={{header|VBA}}==
=={{header|VBA}}==