2018-03-15 16:24:23 +00:00
|
|
|
Advent of Code
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
|
|
--- Day 12: JSAbacusFramework.io ---
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
Santa's Accounting-Elves need help balancing the books after a recent order.
|
|
|
|
Unfortunately, their accounting software uses a peculiar storage format.
|
|
|
|
That's where you come in.
|
2016-12-16 22:21:15 +00:00
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
They have a JSON document which contains a variety of things: arrays
|
|
|
|
([1,2,3]), objects ({"a":1, "b":2}), numbers, and strings. Your first job is
|
|
|
|
to simply find all of the numbers throughout the document and add them
|
|
|
|
together.
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
• [1,2,3] and {"a":2,"b":4} both have a sum of 6.
|
2018-03-15 16:24:23 +00:00
|
|
|
|
2016-12-16 22:21:15 +00:00
|
|
|
• [[[3]]] and {"a":{"b":4},"c":-1} both have a sum of 3.
|
2018-03-15 16:24:23 +00:00
|
|
|
|
2016-12-16 22:21:15 +00:00
|
|
|
• {"a":[-1,1]} and [-1,{"a":1}] both have a sum of 0.
|
2018-03-15 16:24:23 +00:00
|
|
|
|
2016-12-16 22:21:15 +00:00
|
|
|
• [] and {} both have a sum of 0.
|
|
|
|
|
|
|
|
You will not encounter any strings containing numbers.
|
|
|
|
|
|
|
|
What is the sum of all numbers in the document?
|
|
|
|
|
|
|
|
Your puzzle answer was 191164.
|
|
|
|
|
|
|
|
--- Part Two ---
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
Uh oh - the Accounting-Elves have realized that they double-counted
|
|
|
|
everything red.
|
2016-12-16 22:21:15 +00:00
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
Ignore any object (and all of its children) which has any property with the
|
|
|
|
value "red". Do this only for objects ({...}), not arrays ([...]).
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
|
|
• [1,2,3] still has a sum of 6.
|
2018-03-15 16:24:23 +00:00
|
|
|
|
|
|
|
• [1,{"c":"red","b":2},3] now has a sum of 4, because the middle object is
|
2016-12-16 22:21:15 +00:00
|
|
|
ignored.
|
2018-03-15 16:24:23 +00:00
|
|
|
|
|
|
|
• {"d":"red","e":[1,2,3,4],"f":5} now has a sum of 0, because the entire
|
|
|
|
structure is ignored.
|
|
|
|
|
2016-12-16 22:21:15 +00:00
|
|
|
• [1,"red",5] has a sum of 6, because "red" in an array has no effect.
|
|
|
|
|
|
|
|
Your puzzle answer was 87842.
|
|
|
|
|
|
|
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
At this point, you should return to your advent calendar and try another
|
|
|
|
puzzle.
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
|
|
If you still want to see it, you can get your puzzle input.
|
|
|
|
|
|
|
|
References
|
|
|
|
|
|
|
|
Visible links
|
|
|
|
. http://adventofcode.com/
|
|
|
|
. http://adventofcode.com/about
|
|
|
|
. http://adventofcode.com/stats
|
|
|
|
. http://adventofcode.com/leaderboard
|
|
|
|
. http://adventofcode.com/settings
|
|
|
|
. http://adventofcode.com/auth/logout
|
|
|
|
. http://json.org/
|
|
|
|
. http://adventofcode.com/
|
|
|
|
. http://adventofcode.com/day/12/input
|