neat,
byunique =: ("_1) (@:[) ((i.`{)`)(`:6)(~.`)(`])(`:6)
is it just habit to do 'byunique' f.
It doesn't seem to change anything.
----- Original Message -----
From: Jose Mario Quintana <[email protected]>
To: Programming forum <[email protected]>
Sent: Monday, July 4, 2016 3:16 PM
Subject: Re: [Jprogramming] Adverbial Tacit Jym
A solution to Exercise 6 is shown below; but, since the challenge was
posed a long time ago, the exercise is shown first as a reminder
(explicit solutions are allowed but tacit solutions, particularly
fixed tacit solutions, are preferred).
Exercise 6. Let us assume that u is an arbitrary monadic verb which
is expensive to compute. Produce a6 such that (u a6)Y -: (u ("_1))Y
but u a6 does not repeat the computation of the same items of Y.
For example,
cheap=. 'a6'f.
delay=. 6!:3
timer=. 6!:2
timer'delay ("_1) (5$%:2)'
7.07262802
timer'delay cheap (5$%:2)'
1.41460927
(delay cheap -: delay ("_1)) (5$%:2)
1
(([echo) o (+/) cheap ; +/ ("_1))4 3 2 $ i.4
2 5
4 7
┌───┬───┐
│2 5│2 5│
│4 7│4 7│
│2 5│2 5│
│4 7│4 7│
└───┴───┘
____ _ _ _
/ ___| ___ | |_ _| |_(_) ___ _ __
\___ \ / _ \| | | | | __| |/ _ \| '_ \
___) | (_) | | |_| | |_| | (_) | | | |_ _ _
|____/ \___/|_|\__,_|\__|_|\___/|_| |_(_|_|_)
This session shows a classic solution (there is no need to load first
the J Wicked Toolkit).
a6=. ("_1) (@:[) ((i.`{)`)(`:6)(~.`)(`])(`:6)
cheap=. 'a6'f.
assert (+/cheap -: +/"_1) (4 3 2 $ i.4)
u cheap
~. (i. { u"_1@:[) ]
(; ([ echo@:<)@:|.cheap) 10 3$'mississippi'
┌───┐
│sim│
└───┘
┌───┐
│sis│
└───┘
┌───┐
│pis│
└───┘
┌───┐
│mip│
└───┘
┌───┐
│ssi│
└───┘
┌───┐
│ppi│
└───┘
┌───┐
│imi│
└───┘
┌───┐
│iss│
└───┘
┌───┬───┐
│mis│sim│
│sis│sis│
│sip│pis│
│pim│mip│
│iss│ssi│
│iss│ssi│
│ipp│ppi│
│imi│imi│
│ssi│iss│
│ssi│iss│
└───┴───┘
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm