Fractran: Difference between revisions
Content added Content deleted
m (→showing prime numbers: added some numbers.) |
(add fermat) |
||
Line 1,144: | Line 1,144: | ||
First 20 primes: |
First 20 primes: |
||
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> |
|||
=={{header|Fermat}}== |
|||
<lang fermat>Func FT( arr, n, m ) = |
|||
;{executes John H. Conway's FRACTRAN language for a program stored in [arr], an} |
|||
;{input integer stored in n, for a maximum of m steps} |
|||
;{To allow the program to run indefinitely, give it negative or noninteger m} |
|||
exec:=1; {boolean to track whether the program needs to halt} |
|||
len:=Cols[arr]; {length of the input program} |
|||
while exec=1 and m<>0 do |
|||
m:-; |
|||
!!n; {output the memory} |
|||
i:=1; {index variable} |
|||
exec:=0; |
|||
while i<=len and exec=0 do |
|||
nf:=n*arr[i]; |
|||
if Denom(nf) = 1 then |
|||
n:=nf; {did we find an instruction to execute?} |
|||
exec:=1 |
|||
fi; |
|||
i:+; |
|||
od; |
|||
od; |
|||
.; |
|||
;{Here is the program to run} |
|||
[arr]:=[( 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 )]; |
|||
FT( [arr], 2, 20 );</lang> |
|||
{{out}}<pre> |
|||
2 |
|||
15 |
|||
825 |
|||
725 |
|||
1925 |
|||
2275 |
|||
425 |
|||
390 |
|||
330 |
|||
290 |
|||
770 |
|||
910 |
|||
170 |
|||
156 |
|||
132 |
|||
116 |
|||
308 |
|||
364 |
|||
68 |
|||
4 |
|||
</pre> |
</pre> |
||