Created
December 12, 2015 22:35
-
-
Save joebo/7edea8f07db4596e8efb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment