very neat, and good writeup. The only part I couldn't quite follow is the STOR _2, or STOR _1 0 (is STOR _1 the same?). OR 1 _1 I assume is the number 1 with the memlocation _1?
----- Original Message ----- From: Joe Bogner <joebog...@gmail.com> To: programm...@jsoftware.com Sent: Wednesday, December 9, 2015 1:12 PM Subject: Re: [Jprogramming] advent 7 Here's a fixed tacit[1] version of day 7 ((0 (<@:[ 1} ]) (0 {:: ])&] (>:@:(1 {:: ]) (<@:[ 1 } ]) ])@:(((1 {:: ]) { 0 {:: ]) (] (<@:[ 4} ])~ 65 535&-@(1&({::)@[ (([: <:@| [) { 2 {:: ])~^:(0 > ]) ~ ]))`]@.(_1 -: 1&({::)@[ (([: <:@| [) { 2 {:: ])~ ^:(0 > ])~ ])`((] (<@:[ 4} ])~ (1&({::)@[ (([: <:@ | [) { 2 {:: ])~^:(0 > ])~ ]) 17 b. 2&({::)@[ (([: <:@| [) { 2 {:: ])~^:(0 > ])~ ])`]@.(_1 -: <./@(( 1&({::)@[ (([: <:@| [) { 2 {:: ])~^:(0 > ])~ ]) , 2&({::)@[ (([: <:@| [) { 2 {:: ])~^:(0 > ])~ ])))` ((] (<@:[ 4} ])~ (1&({::)@[ (([: <:@| [) { 2 {:: ] )~^:(0 > ])~ ]) (33 b.~ -) 2&({::)@[ (([: <:@| [) { 2 {:: ])~^:(0 > ])~ ])`]@.(_1 -: <./@((1&({::)@[ (([: <:@| [) { 2 {:: ])~^:(0 > ])~ ]) , 2&({::)@[ (([: <:@| [) { 2 {:: ])~^:(0 > ])~ ])))`((] (<@:[ 4} ])~ (1&({::)@[ (([: <:@| [) { 2 {:: ])~^:(0 > ])~ ]) ((65535) 17 b. 33 b.~) 2&({::)@[ (([: <:@| [) { 2 {:: ])~^:(0 > ])~ ])`]@.(_1 -: <./@((1&({:: )@[ (([: <:@| [) { 2 {:: ])~^:(0 > ])~ ]) , 2&({:: )@[ (([: <:@| [) { 2 {:: ])~^:(0 > ])~ ])))`((] (< @:[ 4} ])~ (1&({::)@[ (([: <:@| [) { 2 {:: ])~^:(0 > ])~ ]) 23 b. 2&({::)@[ (([: <:@| [) { 2 {:: ])~ ^:(0 > ])~ ])`]@.(_1 -: <./@((1&({::)@[ (([: <:@| [) { 2 {:: ])~^:(0 > ])~ ]) , 2&({::)@[ (([: <:@| [) { 2 {:: ])~^:(0 > ])~ ])))`((] (<@:[ 4} ])~ 1&( {::)@[ (([: <:@| [) { 2 {:: ])~^:(0 > ])~ ])`]@.(_ 1 -: 1&({::)@[ (([: <:@| [) { 2 {:: ])~^:(0 > ])~ ]))`((] (<@:[ 2} ])~ (0: {:: ])`(1: {:: ])`(2: {:: ])}~@((4 {:: ])@] ; -@>:@(1&{)@[ ; (2 {:: ])&]))` ]@.(0 = #@:(4 {:: ])))`(_&(<@:[ 1} ]))@.(0 {:: [) ])^:(1 = (1 {:: ]) < <:@:#@:[)^:_ ])^:_ ((<;._1 ' ') ,~ (0 {:: ]) ; 0 ; 2 {:: ]))@:(_1&(<@:[ 4} ])@ :((702$_1)&(<@:[ 2} ]))@:(0&(<@:[ 1} ]))@:(1&({::) (<@:[ 0} ]) 0&({::))) Of course, this would be ridiculous to write, so we use the J to write the code, still it's approximately 250 lines of code vs the < 10 from Henry or Pascal http://code.jsoftware.com/wiki/User:Joe_Bogner/AdventDay7 I am happy to bulk up the essay or answer questions if anyone's interested [1] - http://www.jsoftware.com/pipermail/programming/2014-July/038522.html On Mon, Dec 7, 2015 at 7:18 PM, Henry Rich <henryhr...@gmail.com> wrote: > 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm