Here goes my latest (this time correct) attempt.
it parses input lines into executable J code, and checks which lines are
fully determined.
Those are executed, added to the valid list, and removed from the input to
be executed.
This continues until all input has been processed.

Have fun!

D =: 'C:\Users\Jan-Pieter\Dropbox\scripts\J\adventofcode\'

i6 =: freads D,'input7.txt'

valid =: ;:'LSHIFT NOT RSHIFT AND OR'


s6a =: [: ".@('a'"_) s6proc^:(#>0)^:_@s6parse

 s6parse =: (s6rear&.;:) ;. _2

  s6rear =: ({~ s6use)@('=:'&;) NB. Re-arrange lines

   s6use =: (<: , [: i. 3 -~ ])@# NB. which elements to use,based on number
of words

NB. Do and remove valid (ie. fully determined) sentences.

 s6proc =: (s6isvalid (s6dosel ] s6remsel) ]) NB. process step:

  s6dosel =: (s6markvalid@:{.@;: ] ".)@# NB. Do selected

  s6markvalid =: 3 : 'valid =: valid , y' NB. add to valid symbols

  s6remsel=: (#~ -.)~ NB. remove selected

  s6isvalid =: (# = [: +/ s6num +. s6def)@(2&}.)@;: NB. valid right hand
side? :

   s6num =: (*./@e.&(,":"0 i.10)&> NB. numeric litteral

   s6def =: 3 : 'valid e.~"_ 0 y' NB. already defined


NB. Thanks to David Lambert:

B16 =: 16bffff

LSHIFT=: B16 AND 33 b.~

NOT=: B16 AND 0&(2b11000 b.)

RSHIFT=: LSHIFT -

AND=: 2b10001 b.

OR=: 2b10111 b.




2015-12-10 3:06 GMT+01:00 'Pascal Jasmin' via Programming <
programm...@jsoftware.com>:

> 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
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to