My solutions to the Day2 problems:
Probably there's better solutions around, but well... NB. the surface of a box is the product of 2 elements of each permutation of sides NB. Needed paper surface s1a =: [: +/ (+/ + s1slack)@s1facesurf@s1parse NB. paper needed = sum of surfaces + slack s1parse =: [: |: ([: ". ;. _1 'x', ]) ;. _2 NB. parse box sizes s1facesurf =: */@(}:"2)@((i.@!@#) A. ]) NB. face surfaces s1slack =: <./ NB. Slack space = smallest face NB. Ribbon length s1b =: [: +/ (s1vol + s1faceperm)@s1parse NB. ribon = volume + smallest perimeter s1vol =: */ NB. Volume s1faceperm=: ([: <./ +:@(+/)@(}:"2))@((i.@!@#) A. ]) NB. smallest perimeter. NB. input as text. Best regards, Jan-Pieter 2015-12-03 17:35 GMT+01:00 Thomas Costigliola <tcost...@gmail.com>: > Here's my solution to part 1. > > I=. /:~@:(do;._1)@:('x'&,);._2 ] 0 : 0 > > 3x11x24 > > 13x5x19 > > 1x9x27 > > 24x8x21 > > 6x8x17 > > ... > > ) > > > M=. 7 3 $ 1 1 0 1 0 1 0 1 1 > > I +/@(+/@:(*/) . ^) |:M > > 1588178 > > > > > On Thu, Dec 3, 2015 at 6:47 AM, Ryan Eckbo <ec...@cim.mcgill.ca> wrote: > > > And mine: > > > > # part 1 > > Presents=. do each ('x'&cut);._2 freads'/tmp/input.txt' > > sa=: 3 : '(l*w) + (2*l*w) + (2*w*h) + 2*h*l [ ''l w h''=. /:~y' > > +/ sa"1 Presents > > > > # part 2 > > ribbon=. +/@:+:@:}:@:(/:~)@:> > > vol=. */@:> > > +/ (vol + ribbon)"1 Presents > > > > Ryan > > > > > > On 3 Dec 2015, at 13:54, Ric Sherlock wrote: > > > > > Here's mine: > > > > > > require 'tables/csv stats' > > > parcels=: _99 ". > 'x' readdsv jpath '~temp/aoc_day2_inp.txt' > > > > > > NB. Part 1 > > > +/ (<./ + [: +/ +:)"1 */"1 (0 1 , 1 2 ,: 0 2) {"_ 1 parcels > > > > > > NB. or... > > > getFaceSides=: (2 comb 3) {"_ 1 ] > > > calcFaceArea=: */"1@:getFaceSides > > > calcPaper=: (<./ + +/@:+:)"1 > > > calcTotalPaper=: +/@:calcPaper@calcFaceArea > > > > > > calcTotalPaper parcels > > > > > > NB. Part 2 > > > +/ (*/"1 + ([: <./"1 [: (+/@:+:)"1 (2 comb 3)&{"_ 1)) parcels > > > > > > NB. or ... > > > volume=: */"1 > > > perimeters=: (+/@:+:)"1@getFaceSides > > > calcRibbonLength=: (volume + <./"1@:perimeters) > > > calcTotalRibbonLength=: +/@calcRibbonLength > > > echo calcTotalRibbonLength parcels > > > > > > > > > > > > On Thu, Dec 3, 2015 at 3:36 PM, 'Pascal Jasmin' via Programming < > > > programm...@jsoftware.com> wrote: > > > > > >> outfix is quite forgettable, but this is much more elegant than what I > > >> did. > > >> > > >> > > >> 1 */\. 2 3 4 > > >> 12 8 6 > > >> > > >> > > >> > > >> ----- Original Message ----- > > >> From: Joe Bogner <joebog...@gmail.com> > > >> To: programm...@jsoftware.com > > >> Sent: Wednesday, December 2, 2015 8:54 PM > > >> Subject: Re: [Jprogramming] advent of code - day 2 > > >> > > >> Pascal's #2 is the answer to part 2 of the question. Both of his > > >> answers match mine and yours matches my part one. > > >> > > >> Pascal - looks similar to mine, albeit compressed in a single line, > > >> which is close to the original problem description > > >> > > >> Henry - I haven't figured the logic of yours out yet at a quick > > >> glance, I will need to look closer > > >> > > >> Thank you both for sharing > > >> > > >> > > >> On Wed, Dec 2, 2015 at 8:40 PM, Henry Rich <henryhr...@gmail.com> > > wrote: > > >>> The 2 versions give different results. > > >>> > > >>> Mine: > > >>> > > >>> i =. ".;._1@('x'&,);._2 wd 'clippaste' > > >>> > > >>> +/ (/:~@(1&(*/\.))"1 i) +/ . * 3 2 2 > > >>> > > >>> > > >>> Henry Rich > > >>> > > >>> > > >>> > > >>> > > >>> On 12/2/2015 8:19 PM, 'Pascal Jasmin' via Programming wrote: > > >>>> > > >>>> was wondering what took 7 lines, but its style > > >>>> > > >>>> 1: with input parsing > > >>>> > > >>>> +/ +/ (<./, 2&*)"1 */every@:(0 2&{ ; 1 2&{ ; 0 1&{)"1 ". > cutLF > 'x ' > > >>>> rplc~ wdclippaste '' > > >>>> > > >>>> 2: > > >>>> > > >>>> +/ +/@(*/ , +:@(2 {. /:~))("1) ". > cutLF 'x ' rplc~ wdclippaste '' > > >>>> > > >>>> > > >>>> > > >>>> ----- Original Message ----- > > >>>> From: Joe Bogner <joebog...@gmail.com> > > >>>> To: programm...@jsoftware.com > > >>>> Sent: Wednesday, December 2, 2015 7:37 PM > > >>>> Subject: [Jprogramming] advent of code - day 2 > > >>>> > > >>>> building upon: > > >>>> > http://jsoftware.com/pipermail/programming/2015-December/043407.html, > > >>>> but starting a new thread since the other one started to go in a > > >>>> different direction. > > >>>> > > >>>> http://adventofcode.com/day/2 > > >>>> > > >>>> Here's my solution: > > >>>> https://github.com/joebo/lang-lab/blob/master/j/advent2015/day2.ijs > > >>>> > ---------------------------------------------------------------------- > > >>>> 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