Further note: The entire sequence should be reversed, to properly take
advantage of J's right-to-left evaluation. The version I posted on the
wiki - 
http://code.jsoftware.com/wiki/Essays/Advent_Of_Code_2016#A_concise_approach
- deals with this.

In other words:

   +/|+. 3 L 2 R 0
5
   +/|+. 2 R 2 R 2 R 0
2
   +/|+. 3 R 5 R 5 L 5 R 0
12

(I probably make too many careless mistakes...)

Thanks,

-- 
Raul

On Fri, Dec 2, 2016 at 11:04 AM, Raul Miller <rauldmil...@gmail.com> wrote:
> Eh...
>
> I seem to have made a mistake here.
>
>    R=: + 0j1&*
>    L=: + 0j_1&*
>
>    +/+. 2 R 3 L 0
> 5
>    +/+. 2 R 2 R 2 R 0
> 2
>    +/+. 5 R 5 L 5 R 3 R 0
> 18
>
> I was thinking that that should be symmetrical, but at the last
> minute, I swapped my definitions of L and R (without rerunning the
> code) based on how I thought it should look on a graph.
>
> But, apparently, that gives a different answer:
>
>    +/+. 2 R 3 L 0
> _1
>    +/+. 2 R 2 R 2 R 0
> _2
>    +/+. 5 R 5 L 5 R 3 R 0
> 2
>
> After a bit of thought, though, I think I see where I went wrong:
>
>    L=: + 0j1&*
>    R=: + 0j_1&*
>
>    +/|+. 2 R 3 L 0
> 5
>    +/|+. 2 R 2 R 2 R 0
> 2
>    +/|+. 5 R 5 L 5 R 3 R 0
> 18
>
> My apologies for the sloppy initial post. I should have tested it
> rather than just thinking it would work.
>
> Thanks,
>
> --
> Raul
>
>
>
> On Fri, Dec 2, 2016 at 12:37 AM, Raul Miller <rauldmil...@gmail.com> wrote:
>> Here's how I'd approach the computational part of this problem:
>>
>>    L=: + 0j1&*
>>    R=: + 0j_1&*
>>
>>    +/+. 2 R 3 L 0
>> 5
>>    +/+. 2 R 2 R 2 R 0
>> 2
>>    +/+. 5 R 5 L 5 R 3 R 0
>> 18
>>
>> Thanks,
>>
>> --
>> Raul
>>
>> On Thu, Dec 1, 2016 at 6:09 PM, Jan-Pieter Jacobs
>> <janpieter.jac...@gmail.com> wrote:
>>> My solution for day 1, using complex notation for X Y.
>>>
>>>
>>> NB. in contains the input
>>> d =: */\ 0j1 * 'R L' i. in #~ 'RL' e. ~ in NB. get directions for each move
>>> st =: ". in -. 'RL' NB. step lengths
>>> NB. get the manhattan distance (+/@:+. of all steps after each other, i.e.
>>> their sum
>>> ]r =: +/ | +. +/ d * st
>>>
>>> NB. Part two: the first crossing.
>>> t =: <@:>:@i."0 st NB. prepare tracks of lengths ~ step length
>>> dl =: (<"0 d) *&.>t NB. put each track in the right direction
>>> ll =: > ([ ,{:@[ + ])&.>/ dl NB. sum from previous end point, and
>>> concatenate.
>>> NB. find the distance to the first place encountered more than once.
>>> ]rr =: +/|+. {. (~. #~ (1<#)/.~) ll
>>>
>>> Cheers,
>>>
>>> Jan-Pieter
>>>
>>> 2016-12-01 21:23 GMT+01:00 'Pascal Jasmin' via Programming <
>>> programm...@jsoftware.com>:
>>>
>>>> looks like I double pasted?  all one line.
>>>>
>>>>
>>>>  +&| /}. {: > f each/ (,: 0 0 0) (, <)~ |. dltb each ',' cut 'R2, R2, R2'
>>>>
>>>> or
>>>>
>>>> +&| /}. {: > f each/ (,: 0 0 0) (, <)~ |. dltb each ',' cut a
>>>>
>>>>
>>>>
>>>> ----- Original Message -----
>>>> From: Joe Bogner <joebog...@gmail.com>
>>>> To: programm...@jsoftware.com
>>>> Sent: Thursday, December 1, 2016 2:39 PM
>>>> Subject: Re: [Jprogramming] advent of code 2016
>>>>
>>>> Nice, that sounds like what i had in mind. I get a domain error though:
>>>>
>>>> a =. 'R2, R2, R2'
>>>>
>>>> O =: 4 2 $ _1 0 0 1 1 0 0 _1
>>>> f =: 4 : 0
>>>> a =. 4 | x ({.@] +  _1 1 {~ 'R' = {.@[) {: y
>>>> y ,   a , (}. {: y) + x (".@}.@[  * O {~ ]) a
>>>> )
>>>>
>>>> +&|/ }. {: > f each/ (,: 0 0 0) (, <)~ |. dltb each ',' cut a f each/
>>>> (,: 0 0 0) (, <)~ |. dltb each ',' cut a  NB. part 1
>>>>
>>>>
>>>> plot <"1 |: }."1 > f each/ (,: 0 0 0) (, <)~ |. dltb each ',' cut a
>>>> NB. part 2, find intersection in plot
>>>>
>>>>
>>>> Running all gives me:
>>>>
>>>>
>>>>    +&|/ }. {: > f each/ (,: 0 0 0) (, <)~ |. dltb each ',' cut a f
>>>> each/ (,: 0 0 0) (, <)~ |. dltb each ',' cut a  NB. part 1
>>>> |domain error: f
>>>> |   a=.4|x    ({.@]+_1 1{~'R'={.@[){:y
>>>>
>>>>
>>>>
>>>> This is what it works up to:
>>>>
>>>> (,: 0 0 0) (, <)~ |. dltb each ',' cut a  NB. part 1
>>>> ┌──┬──┬──┬─────┐
>>>> │R2│R2│R2│0 0 0│
>>>> └──┴──┴──┴─────┘
>>>>
>>>> This seems to work though:
>>>>
>>>> +&|/ }. {: > f each/ (,: 0 0 0) (, <)~ |. dltb each ',' cut a
>>>> 2
>>>>
>>>>    +&|/ }. {: > f each/ (,: 0 0 0) (, <)~ |. dltb each ',' cut 'R2,R2,R2'
>>>> 2
>>>>
>>>> +&|/ }. {: > f each/ (,: 0 0 0) (, <)~ |. dltb each ',' cut 'R5,L5,R5,R3'
>>>> 12
>>>>
>>>>
>>>> It looks like there may be a typo  in your paste
>>>>
>>>> This
>>>>
>>>> +&|/ }. {: > f each/ (,: 0 0 0) (, <)~ |. dltb each ',' cut a f each/
>>>> (,: 0 0 0) (, <)~ |. dltb each ',' cut a  NB. part 1
>>>>
>>>> Should be this:
>>>>
>>>>
>>>> +&|/ }. {: > f each/ (,: 0 0 0) (, <)~ |. dltb each ',' cut a
>>>>
>>>>
>>>>
>>>> On Thu, Dec 1, 2016 at 2:11 PM, 'Pascal Jasmin' via Programming
>>>> <programm...@jsoftware.com> wrote:
>>>> > I posted an alternate solution,
>>>> >
>>>> > a =. wdclippaste '' NB. input from clipboard
>>>> >
>>>> > O =: 4 2 $ _1 0 0 1 1 0 0 _1
>>>> > f =: 4 : 0
>>>> > a =. 4 | x ({.@] +  _1 1 {~ 'R' = {.@[) {: y
>>>> > y ,   a , (}. {: y) + x (".@}.@[  * O {~ ]) a
>>>> > )
>>>> >
>>>> > +&|/ }. {: > f each/ (,: 0 0 0) (, <)~ |. dltb each ',' cut a f each/
>>>> (,: 0 0 0) (, <)~ |. dltb each ',' cut a  NB. part 1
>>>> >
>>>> >
>>>> > plot <"1 |: }."1 > f each/ (,: 0 0 0) (, <)~ |. dltb each ',' cut a  NB.
>>>> part 2, find intersection in plot
>>>> >
>>>> > general description,
>>>> >
>>>> > O holds direction vectors,
>>>> > 0 0 0 is appended to reversed list of commands, where position 0 is the
>>>> orientation index into 0, and other 2 are x y positions of taxi.
>>>> >
>>>> > f/ updates orientation and x y on each iteration, where intermediate
>>>> value a is new orientation.
>>>> >
>>>> >
>>>> >
>>>> >
>>>> > ----- Original Message -----
>>>> > From: Joe Bogner <joebog...@gmail.com>
>>>> > To: programm...@jsoftware.com
>>>> > Sent: Thursday, December 1, 2016 1:43 PM
>>>> > Subject: Re: [Jprogramming] advent of code 2016
>>>> >
>>>> > I added an alternate solution to problem 1, part 1 -
>>>> > http://code.jsoftware.com/wiki/Essays/Advent_Of_Code_
>>>> 2016#Imperative_Style_.28cleanup.29
>>>> >
>>>> > If I had the time, I would think about how to reformulate it so I
>>>> > could use / to reduce the input to a single solution. I recall using
>>>> > that pattern last year
>>>> >
>>>> >
>>>> > On Thu, Dec 1, 2016 at 12:53 PM, Joe Bogner <joebog...@gmail.com> wrote:
>>>> >> I've started a wiki page for it so we don't have to go back and add
>>>> >> them later. Feel free to edit/add
>>>> >>
>>>> >> http://code.jsoftware.com/wiki/Essays/Advent_Of_Code_2016
>>>> >>
>>>> >> My solution to the first problem is pretty bad (works though). I
>>>> >> intend to add another solution that's in a more functional style
>>>> >>
>>>> >> On Thu, Dec 1, 2016 at 11:16 AM, 'Pascal Jasmin' via Programming
>>>> >> <programm...@jsoftware.com> wrote:
>>>> >>> back again this year,
>>>> >>>
>>>> >>>
>>>> >>> http://adventofcode.com/2016
>>>> >>> ----------------------------------------------------------------------
>>>> >>> 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