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
<[email protected]> 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 <[email protected]>
> To: [email protected]
> 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 <[email protected]> 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
>> <[email protected]> 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