Here's my attempt at toponm without $:

}. {. > ( -.&a:)L:2@:(] ((] -.~ each  }.@[) ,~ {.@[  (, L: 1) ])  
<@,@(]S:1)@:(#~ 1 = # every L:2)@}.)^:(1 < # )^:_ '';Nm

Yours is about twice as fast, though memory hoggish.




----- Original Message -----
From: Henry Rich <henryhr...@gmail.com>
To: programm...@jsoftware.com
Sent: Monday, December 7, 2015 7:18 PM
Subject: Re: [Jprogramming] advent 7

No, it's an ad-hoc topological sort I wrote for this problem.

Input is a list of boxes, each containing a list.
Boxes containing 0 or 1 item are 'ripe'; the contents are run
together and become the first part of the result.  The contents of
the ripe boxes are removed from the contents of all the unripe boxes, and
the then the newly-shortened unripe boxes are processed by recursion, with
the result of the recursion becoming the second part of the result.

It recurs to the depth of the longest path through the tree.  It's not a 
good general-purpose topological sort, but it's about right for this 
problem.

Henry rich

On 12/7/2015 6:14 PM, 'Pascal Jasmin' via Programming wrote:
> Toponm is very impressive.  Is there a writeup somewhere on it?
>
>
>
>
> ----- Original Message -----
> From: Henry Rich <henryhr...@gmail.com>
> To: programm...@jsoftware.com
> Sent: Monday, December 7, 2015 3:18 PM
> Subject: Re: [Jprogramming] advent 7
>
> Does this solution depend on being able to evaluate the results in
> lexicographic order of name?  The spec doesn't guarantee that.
>
> My version:
>
> NB. Advent 7
> LC =: 'abcdefghijklmnopqrstuvwxyz'
> '`NOT OR AND LSHIFT RSHIFT' =: (65535&-)`(23 b.)`(17 b.)`(65535 (17 b.)
> (33 b.)~)`(33 b.~ -)
> NB. Read input, convert to words.  There seems to be an extra LF
> NB. Extract signal-names
> Nm =: (#~ e.&LC@{.@>)&.> I =: a: -.~ <@;:;._2 wd 'clippaste'
> NB. topo sort names.  Move defined names to front, recur
> Toponm =: ((;@#~ ([ , $:@(-.L:1~)^:(*.&*&#)) (#~ -.)) 1&>:@#@>) Nm
> NB. Sort lines by result-name, convert, execute
> ([: ".@(;:^:_1) {: , '=:' ; _3&}.)@> I /: Toponm i. {:@> I
> NB. Result?
> a
>
>
> Henry Rich
>
> On 12/7/2015 12:48 PM, 'Pascal Jasmin' via Programming wrote:
>> Y =: (&{::)(@:])
>> X =: (&{::)(@:[)
>> excludesolved =: 2 : '(] #~ v) , [ u ] #~ -.@v'
>>
>>
>> c =. (('abcdefghijklmnopqrstuvwxyz' ('z' , leaf ])^:([ e.~ {.every@])"1 0  
>> ])&.;:) each b =. <@( (0 Y ),~ '=:' ,~ }.@(1 Y))@:('-'&cut)"1 a =. > cutLF 
>> wd'clippaste'
>>
>>
>> wd 'clipcopy *' , LF joinstring 1 |. ,&>/((2 = # every@{.@;:every ) </. 
>> ])/:~ c
>>
>> then paste clipboard into a new file (could have used 3 : trick)  where the 
>> file header is:
>>
>> RSHIFT =: ((65535) 17 b. [ 33 b.~ -@])
>> LSHIFT =: (65535) 17 b. 33 b.~
>> AND =:(65535) 17 b. 17 b.
>> OR =:(65535) 17 b. 23 b.
>> NOT =:(65535) 17 b. 26 b.
>>
>> load that file and inspect za
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm



>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to