I am not sure I follow. Are you saying it doesn't work in your input? If
so, can you paste your input somewhere?
On Dec 12, 2015 4:51 PM, "'Pascal Jasmin' via Programming" <
[email protected]> wrote:

> not working for me,
>
>
> with a = dec_json input
>
>
> traverse1 = your first traverse
>
>
> I do get part 1 answer with either
>
> +/ ( 0:`]@.(2 ~:3 !:0)S:0) {. traverse1 a
> 119433
>
> +/ ( 0:`]@.(2 ~:3 !:0)S:0)  a
>
> the reason for difference is that
>
>
> $ each each traverse1 a
>
> includes a as its 2nd item in top row.
>
>
> $ each  a
>
> ----- Original Message -----
> From: Joe Bogner <[email protected]>
> To: [email protected]
> Sent: Saturday, December 12, 2015 3:47 PM
> Subject: [Jprogramming] advent of code day 12
>
> 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