Fractran: Difference between revisions

m
Line 1,918:
'''Solution'''
 
This is a variation of the previous solution which it is not entirely tacit due to the use of the explicit standard library verb (function) charsub. The adverb (functional) fractan is defined as a fixed tacit adverb (that is, a stateless point-free functional),
 
<lang j>fractan=. (((({~ (1 i.~ (= <.)))@:* ::]^:)(`]))(".@:('1234567890r ' {~ '1234567890/ '&i.)@:[`))(`:6)</lang>
Line 1,932:
'''Extra credit'''
 
The prime numbers are produced via the stateless point-free adverb primes; its argument has the same specifications as the argument for the fractan adverb (which is used in its definition),
 
<lang j>primes=. ('fractan'f.) ((1 }. 2 ^. (#~ *./@:e.&2 0"1@:q:))@:)
Line 1,939:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71</lang>
 
theprimes is also a stateless point-free code of the tacit adverb primes isfunctional,
<lang j> primes
Line 1,945:
 
'''StatelessTuring completeness of J's stateless point-free Turing completenessdialect'''
 
When _ is the limit argument; that is(i.e., when no limit is imposed,) the run will halt according to the FRACTAN programming language specifications (the run might also be forced to halt if a changeless single cycle is detected). Thus, the FRACTAN associated verb (function) is,
<lang j> _ fractan
".@:('1234567890r ' {~ '1234567890/ '&i.)@:[ ({~ (1 i.~ (= <.)))@:* ::]^:_ ]</lang>
 
Actually, most of the code above is there to comply with the task's requirement of a "natural format." When J's format for fractions is used the FRACTAN verb emulator code is reduced tobecomes,
 
<lang j>FRACTAN=. ({~ (1 i.~ (= <.)))@:* ::]^:_</lang>
 
Thiswhich is aan indirect concise confirmation that theJ's fixed tacit dialect of J is Turing complete.
 
In the following example, FACTRANFRACTAN calculates the product 24 * 3 where6, the initial value 7211664 = (2^34)*(3^26) whereholds 3 is4 in the register associated with 2 and 2holds is6 in the register associated with 3 and; the result 1562559604644775390625 = 5^624 holds the product 24 = 4 * 6 in the register associated with 5.,
 
<lang j> 455r33 11r13 1r11 3r7 11r2 1r3 FRACTAN 7211664
1562559604644775390625</lang>
 
=={{header|Java}}==
Anonymous user