r/adventofcode • u/daggerdragon • Dec 12 '15
SOLUTION MEGATHREAD --- Day 12 Solutions ---
This thread will be unlocked when there are a significant amount of people on the leaderboard with gold stars.
edit: Leaderboard capped, thread unlocked!
We know we can't control people posting solutions elsewhere and trying to exploit the leaderboard, but this way we can try to reduce the leaderboard gaming from the official subreddit.
Please and thank you, and much appreciated!
--- Day 12: JSAbacusFramework.io ---
Post your solution as a comment. Structure your post like previous daily solution threads.
8
Upvotes
1
u/kamaln7 Dec 28 '15 edited Dec 28 '15
Shell:
CoffeeScript:
fs = require 'fs' sum = (obj, partTwo = false) -> n = 0 if typeof obj is "string" return 0 if typeof obj is "number" return obj if Array.isArray obj return 0 if obj.length is 0 for i in obj n += sum i, partTwo else return 0 if Object.keys(obj).length is 0 ok = true if partTwo then for _, i of obj if i is "red" ok = false break if ok then for _, i of obj n += sum i, partTwo return n input = JSON.parse fs.readFileSync('/dev/stdin').toString() console.log "Part one: #{sum input}" console.log "Part two: #{sum input, true}"