I had the great idea of tackling it pretty much the same way as the day 6
problem: parsing the input into executable phrases.
The it seems to work, but it takes AGES to complete on the entire input,
but works perfectly on the little example.
I wonder if there's a way of improving this performance, or that it's
better to take a different route...

It's a bad idea to execute s6a, so that's why it's commented out.

NB. Little Bobby Table's logic gates

i6 =: freads D,'input7.txt'

NB. s6a =: (a@0:)@:".@:s6parse i6 NB. parse, do sentences and evaluate a.

s6parse =: (s6rep&.;:) ;. _2 NB. parse input into executable J lines.

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

   s6rep =: s6numV@s6atNOT@({~ s6use)@('=:'&;) NB. re-arrange lines

s6atNOT =: (,&'@') ^:('NOT'&-:)&.> NB. add @ after NOT

s6numV =: (,&'"_')^:(*./@e.&(,":"0 i.10))&.>NB. make numbers into constant
funcions


s6bit =: (16$2)&#: NB. convert to 16 bit representation

AND =: *.&.s6bit

NB. under is not working here, as the amount of shift is to be passed in

LSHIFT =: s6bit inv@((|.!.0 s6bit)~ ) NB. Shift left = rotate filling 0's

RSHIFT =: s6bit inv@((|.!.0 s6bit)~ -) NB. Shift right = negative rotation

NOT =: (-.&.s6bit)


2015-12-09 21:17 GMT+01:00 'Pascal Jasmin' via Programming <
programm...@jsoftware.com>:

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

Reply via email to