I'm trying to write a monadic function that will take a number,
create a list of that number times 1..6, with each number's
characters sorted, and return whether they are all the same. So f 17
would look at the list 17 34 15 68 58 012 and return 0. Here's my
closest attempt so far:
=/ /:~ each ": each <"0 (>:i.6)*]
<"0 (>:i.6)*26 returns
+--+--+--+---+---+---+
|26|52|78|104|130|156|
+--+--+--+---+---+---+
But
f=:<"0 (>:i.6)*]
f 26
0 1 1 1 1 1
That looks to me like < is being treated dyadically, and returning
false, true, true, etc. What do I need to do to force it to box instead?
=/ /:~ each ": each NB. seems to work, but is there a better way than
two eaches?
Finally, putting it all together:
f=: =/ /:~ each ": each <"0 (>:i.6)*]
f 4
|domain error: f
| f 4
Any suggestions?
thanks,
geoff
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm