Anonymous user
Fractran: Difference between revisions
m
→Tacit version
m (→Tacit version) |
|||
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
<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>
<lang j> primes
Line 1,945:
'''
When _ is the limit argument
<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
<lang j>FRACTAN=. ({~ (1 i.~ (= <.)))@:* ::]^:_</lang>
In the following example,
<lang j> 455r33 11r13 1r11 3r7 11r2 1r3 FRACTAN
=={{header|Java}}==
|