Yes, this was my original part 1

+/ (". :: 0:) every ;: ('-';'_') stringreplace input
191164
On Dec 12, 2015 4:19 PM, "Moon S" <[email protected]> wrote:

> For part1 you don't need json actually ;)
>
> part1 =: 3 : 0 NB. replace all non-digits to spaces, replace '-' to '_', do
> +/".
>   a=.'abcdefghijklmnopqrstuvwxyz"'',[]{}:',CRLF
>   +/". ('-';'_')rplc~ ' '((i.#y)#~+./a=/y)}y
> )
>
>
> On Sat, Dec 12, 2015 at 10:47 PM, Joe Bogner <[email protected]> wrote:
>
> > somewhat tricky as I hadn't done recursion in J prior to this:
> >
> > require 'convert/json'
> >
> > input =: fread 'c:/joe/lang-lab/j/advent2015/day12.txt'
> >
> > json=: dec_json input
> >
> > traverse=: (".@":@(0&{))`($: each)@.(0 >~ L.)
> > smoutput pt1=: +/ ; S:0 (traverse json)
> >
> >
> > hasRed=:(<'red') e.~ [
> > NB. check for 1 in 2nd row only if it's a rank 2 array
> > NB. attributes of objects show up in the 2nd row
> > NB. we have to skip rank 1 arrays because [1,"red",5] is 6
> > onAttr=: 0:`(*@(+/)@,)@.([: 2&<: #@:$)
> > traverse=: (".@":@(0&{))`($: each)`(0:)@.( (2:^:(onAttr@:hasRed))^:(])
> > (0 >~ L.))
> > smoutput pt2=: +/ ; S:0 (traverse json)
> > ----------------------------------------------------------------------
> > 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