’ AttilaOn Thu, May 13, 2010 at 9:54 AM, effbiae wrote:> hi guys,>> been looking at rosettacode.org. ?can anyone help me work out the K> solution for> ? ? http://rosettacode.org/wiki/Apply_a_callback_to_an_array#J>> and here is the J code that was posted:> Solution:>> ? “_1>> Example:>> ? callback =: ?*:> ? array ? ?=: ?1 2 3 4 5>> ? callback”_1 array> 1 4 9 16 25>>> ta, jack.> ?can K beat a 3 character solution? ?:)>> –>
q)k){x,x*x}'1 2 3 4 51 12 43 94 165 25 AttilaOn Thu, May 13, 2010 at 10:45 AM, Jack Andrews wrote:> output:> 1 4 9 16 25>> how could you extend the k solution to print both the input and result:>> 1 ?1> 2 ?4> 3 ?9> 4 ?16> 5 ?25>> ?>> –>
On Thu, May 13, 2010 at 7:55 PM, Attila Vrabecz<attila.vrabecz> wrote:> q)k){x,x*x}'1 2 3 4 5i guess there is a ‘square’ function and ‘identity’ function that couldmake the above faster?how would you express it? i know this is probably wrong:(identity,square) ’ 1 2 3 4 5> 1 1> 2 4> 3 9> 4 16> 5 25>> ?Attila>>>> On Thu, May 13, 2010 at 10:45 AM, Jack Andrews wrote:>> output:>> 1 4 9 16 25>>>> how could you extend the k solution to print both the input and result:>>>> 1 ?1>> 2 ?4>> 3 ?9>> 4 ?16>> 5 ?25>>>> ?>>>> –>>
this whole thing is quite pointlesssquare and identity are atomic in both J and Kso no need for map (each ’ "_1) whatsoever AttilaOn Thu, May 13, 2010 at 11:04 AM, Jack Andrews wrote:> On Thu, May 13, 2010 at 7:55 PM, Attila Vrabecz> <attila.vrabecz> wrote:>> q)k){x,x*x}'1 2 3 4 5>> i guess there is a ‘square’ function and ‘identity’ function that could> make the above faster?>> how would you express it? ?i know this is probably wrong:>> (identity,square) ’ 1 2 3 4 5>>>> 1 1>> 2 4>> 3 9>> 4 16>> 5 25>>>> ?Attila>>>>>>>> On Thu, May 13, 2010 at 10:45 AM, Jack Andrews wrote:>>> output:>>> 1 4 9 16 25>>>>>> how could you extend the k solution to print both the input and result:>>>>>> 1 ?1>>> 2 ?4>>> 3 ?9>>> 4 ?16>>> 5 ?25>>>>>> ?>>>>>> –>>>