Fractran: Difference between revisions

2,184 bytes added ,  2 years ago
Added Quackery.
m (Updated description and link for Fōrmulæ solution)
(Added Quackery.)
Line 3,327:
Generated prime 43 from the 117832'th member of the fractran series
Generated prime 47 from the 152026'th member of the fractran series</pre>
 
=={{header|Quackery}}==
 
<code>run</code> performs the first step of executing a Fractran program, returning a rational number (represented as two stack items: numerator and denominator) and a boolean. The boolean is <code>true</code> if the halting condition is satisfied, and <code>false</code> otherwise.
 
In this task the parsed Fractran program is stored on the ancillary stack <code>program</code>.
 
To execute a Fractran program until the halting condition is satisfied, use <code>[ program share run until ]</code>. The Fractran prime generator will never satisfy the halting condition, so in this task the <code>drop</code> after <code>run</code> discards the boolean.
 
<lang Quackery> [ 1 & not ] is even ( n --> b )
[ nip 1 = ] is vint ( n --> b )
[ [ dup even while
1 >> again ]
1 = ] is powerof2 ( n --> b )
[ 0 swap
[ dup even while
dip 1+
1 >> again ]
drop ] is lowbit ( n --> n )
[ [] swap nest$
witheach
[ char / over find
space unrot poke
quackery join
nested join ] ] is parse$ ( $ --> [ )
[ stack ] is program ( s --> )
[ true temp put
witheach
[ do 2over v*
2dup vint iff
[ false temp replace
conclude ]
else 2drop ]
2swap 2drop
temp take ] is run ( n/d [ --> n/d b )
[ stack ] is primes ( --> s )
$ "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" join
parse$ program put
2 n->v
15 times
[ program share run
drop over echo sp ]
cr
2drop
2 n->v
[] primes put
[ program share run
drop over dup powerof2 iff
[ lowbit primes take
swap join primes put ]
else drop
primes share size 20 = until ]
2drop
primes take echo
program release</lang>
 
{{out}}
 
<pre>
15 825 725 1925 2275 425 390 330 290 770 910 170 156 132 116
[ 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 ]
</pre>
 
=={{header|Racket}}==
1,462

edits