I am just wondering if the beginner understands what happened and what magic
Roger performed.
These kind of solutions are of course brilliant and telling of the power of
J.
I personally do understand it but fro the sake of the beginner it would be
nice to put some comments in.
create a verb containing the string of items one on each line or in its own
box as one prefers.
split each line or item in subitem depending on blanks
create a list of all unique items in the lists
Look for all occurances in the original list
As an exercise it is best to split the operations into pieces and
investigate each step
[a=:'ab'; 'abc de'; 'ab de'; 'de ef'
+--+------+-----+-----+
|ab|abc de|ab de|de ef|
+--+------+-----+-----+
[all=:chop each a
+----+--------+-------+-------+
|+--+|+---+--+|+--+--+|+--+--+|
||ab|||abc|de|||ab|de|||de|ef||
|+--+|+---+--+|+--+--+|+--+--+|
+----+--------+-------+-------+
[uni=: ~. ;all
+--+---+--+--+
|ab|abc|de|ef|
+--+---+--+--+
uni ,. <@I."1 |: (<uni) e.&> all
+---+-----+
|ab |0 2 |
+---+-----+
|abc|1 |
+---+-----+
|de |1 2 3|
+---+-----+
|ef |3 |
+---+-----+
2008/8/17 Raul Miller <[EMAIL PROTECTED]>
> On Sun, Aug 17, 2008 at 10:39 AM, Roger Hui <[EMAIL PROTECTED]> wrote:
> > s=: 'ab',LF,'abc de',LF,'ab de',LF,'de ef',LF
> > w=: <;._1@(' '&,)&.> <;._2 s
> > u=: ~. ; w
> > u ,. <@I."1 |: (<u) e.&> w
>
> I would have been tempted to use
> w=: <@;:;._2 s
> u=: ~. ; w
> u,.u [EMAIL PROTECTED]:1 w
>
> (or maybe even a variable-free rephrasing of that?)
>
> But, without knowing what a "sentence" was, maybe my use of ;:
> would not be a good thing?
>
> --
> Raul
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
Björn Helgason, Verkfræðingur
Fugl&Fiskur ehf,
Fornustekkum II, 781 Hornafirði
Po Box 127,801 Selfoss ,
t-póst: [EMAIL PROTECTED]
gsm: +3546985532
Landslags og skrúðgarðagerð, gröfuþjónusta
http://groups.google.com/group/J-Programming
Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans
góður kennari getur stigið á tær án þess að glansinn fari af skónum
/|_ .-----------------------------------.
,' .\ / | Með léttri lund verður |
,--' _,' | Dagurinn í dag |
/ / | Enn betri en gærdagurinn |
( -. | `-----------------------------------'
| ) | (\_ _/)
(`-. '--.) (='.'=)
`. )----' (")_(")
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm