Sorry, Here's the first part. NB.If a square, which one? A=:'^<v>' f=: 13 :'((|.|:|.4|+/~i.4),4|+/~i.4){y' f A v<^> <^>v ^>v< >v<^ ^<v> <v>^ v>^< >^<v B=:'<v>^' ((f A)-:"1 B)#1+i.8 6 ((f A)-:"1 '<>^v')#1+i.8
Linda -----Original Message----- From: programming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Linda A Alvord Sent: Wednesday, December 16, 2015 6:00 AM To: programm...@jsoftware.com Subject: Re: [Jprogramming] advent of code - day 3 Here's an approach to Santa's problem 3 for elementary school children: NB. How many get more than one present? T=:'v^^>^^^^v^^^^v^<v^^^vv^vvv^^vv<' $T 31 h T v^^ >^^ ^^v ^^^ ^v^ <v^ ^^v v^v vv^ ^vv +/(0{"1 h T)=2{"1 h T 3 NB. Make lists to test squares p1=: 13 :'(?(6+?y)#4){''^>v<''' [U=:p1 28 v^<vv^>^v>>^^<<<v^v^^v^v>v<> $U 28 Now write a verb to test for more than one present. Linda -----Original Message----- From: programming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Ryan Eckbo Sent: Thursday, December 3, 2015 5:45 PM To: programm...@jsoftware.com Subject: Re: [Jprogramming] advent of code - day 3 I like these answers using complex numbers, nicely done. On 4 Dec 2015, at 8:16, Jan-Pieter Jacobs wrote: > 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 ---------------------------------------------------------------------- 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