This is mine (honestly without cheating ;) ).
The notation of the complex directions can be very nicely written as
subsequent powers of 0j1 : 0j1^i.4

NB. 3) Number of houses getting at least one gift!

NB. use complex numbers for directions

NB. Every unique number is at least once on the list...

s2a =: [: #@~. 0 , [: +/\ s2parse

   s2parse =: (0j1^i.4) {~ '>^<v'&i. NB. convert to complex


NB. including robot santa

s2b =: [: #@~.@, [: (0 ,+/\)"1 s2distrib NB. Same as above, per line.

   s2distrib =: [: |: _2 ]\ s2parse            NB. distribute over Santa &
RoboSanta


i2 =: }: freads D,'input3.txt' NB. drop trailing

2015-12-03 21:21 GMT+01:00 Alex Shroyer <ashro...@gmail.com>:

> Heh, I value sleep more than getting my name on the leaderboard... plus I
> was stumped until I read Reddit user Godspiral's solution
> <
> https://www.reddit.com/r/adventofcode/comments/3v8roh/day_3_solutions/cxldcnx
> >
> .
>
> I did enjoy how part 2 can be solved with just 3 more strategically-placed
> characters.  I really like *]\* as an alternative to dyad *$* (reshape).
>
> On Thu, Dec 3, 2015 at 11:36 AM, 'Pascal Jasmin' via Programming <
> programm...@jsoftware.com> wrote:
>
> > Winner solution, (but you didn't submit it at 12:18 :P)
> >
> >
> > using complex encoding for pairs should probably always be done?  It
> makes
> > your part 2 especially elegant.
> >
> >
> >
> >
> > ----- Original Message -----
> > From: Alex Shroyer <ashro...@gmail.com>
> > To: programm...@jsoftware.com
> > Sent: Thursday, December 3, 2015 11:25 AM
> > Subject: Re: [Jprogramming] advent of code - day 3
> >
> > I was stuck at '^v<>'i.s , but came up with these after I peeked at
> someone
> > else's solution:
> >
> > part1=:#~.,+/\0,0j1 0j_1 _1 1{~'^v<>'i.s
> > part2=:#~.,+/\0,0j1 0j_1 _1 1{~'^v<>'i._2]\s
> >
> > On Thu, Dec 3, 2015 at 8:59 AM, Joe Bogner <joebog...@gmail.com> wrote:
> >
> > > Mine:
> > >
> > > data=:fread 'advent2015/day3.txt'
> > > getMoves=:  ((0,1),(0,_1),(1,0),:(_1,0)) {~ ('^v><' i. ])
> > > addStart =: (1 2 $ 0) , ]
> > > smoutput answer1 =: #  ~.  +/\ addStart @: getMoves data
> > > smoutput answer2 =: # ~. _2[\ ; +/\"2 (((0,1) $~ #) addStart@,./.
> > > getMoves) data
> > >
> > >
> > >
> > >
> > > On Thu, Dec 3, 2015 at 7:00 AM, Ryan Eckbo <ec...@cim.mcgill.ca>
> wrote:
> > > > Data=. }: freads'/tmp/input.txt'
> > > > houses=: 3 : '+/\ (0 0), (4 2$0 1  1 0  0 _1  _1 0){~ ''^>v<'' i. y'
> > > >
> > > > # part 1
> > > > {. $ ~. houses Data
> > > >
> > > > # part 2
> > > > santa=. 2 | i. # Data
> > > > robo=. -. santa
> > > > {. $ ~. (santa&#  ,&shouses  robo&#) Data
> > > >
> ----------------------------------------------------------------------
> > > > 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