Fractran: Difference between revisions
Content added Content deleted
(Updated to work with Nim 2.0.) |
|||
Line 2,090: | Line 2,090: | ||
{{FormulaeEntry|page=https://formulae.org/?script=examples/FRACTRAN}} |
{{FormulaeEntry|page=https://formulae.org/?script=examples/FRACTRAN}} |
||
'''Solution''' |
|||
[[File:Fōrmulæ - FRACTRAN 01.png]] |
|||
It is a function that accepts the program to run (as a list), the initial value of n and the number of values to generate. |
|||
It uses a local nested function next() that calculates the next value of . If it can be calculated, it is added to a result array and return true, elsewhere return false. |
|||
The main work is to iterate while the next() returns true and the number of values to generate is not reached. |
|||
The following is the call with the program for primes, initial n value of 2, and returning 20 values: |
|||
[[File:Fōrmulæ - FRACTRAN 02.png]] |
|||
[[File:Fōrmulæ - FRACTRAN 03.png]] |
|||
'''Bonus''' using the previous FRACTAN program to generate the first 20 primes. |
|||
It requires a modification to the previous program. |
|||
[[File:Fōrmulæ - FRACTRAN 04.png]] |
|||
[[File:Fōrmulæ - FRACTRAN 05.png]] |
|||
[[File:Fōrmulæ - FRACTRAN 06.png]] |
|||
'''FRACTRAN program for addition''' |
|||
[[File:Fōrmulæ - FRACTRAN 07.png]] |
|||
[[File:Fōrmulæ - FRACTRAN 08.png]] |
|||
[[File:Fōrmulæ - FRACTRAN 09.png]] |
|||
'''FRACTRAN program for multiplication''' |
|||
[[File:Fōrmulæ - FRACTRAN 10.png]] |
|||
[[File:Fōrmulæ - FRACTRAN 11.png]] |
|||
[[File:Fōrmulæ - FRACTRAN 12.png]] |
|||
=={{header|Go}}== |
=={{header|Go}}== |