sln_2015_12
Copyright(c) Eric Mertens 2015
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Main

Description

https://adventofcode.com/2015/day/12

Sum up the numbers in a JSON value.

Rather than pull in a heavy JSON parsing dependency, this just parses out the subset of JSON that the problem uses.

>>> :main + "[1,2,3]\n"
6
6
>>> :main + "{\"a\":2,\"b\":4}\n"
6
6
>>> :main + "{\"a\":{\"b\":4},\"c\":-1}\n"
3
3
>>> :main + "[1,{\"c\":\"red\",\"b\":2},3]\n"
6
4
>>> :main + "{\"d\":\"red\",\"e\":[1,2,3,4],\"f\":5}\n"
15
0
>>> :main + "[1,\"red\",5]\n"
6
6
Synopsis

Documentation

main :: IO () Source #

>>> :main
119433
68466

numbers :: Value -> Int Source #

Sum of all the number values in in JSON value.

nonredNumbers :: Value -> Int Source #

Sum of all the number values in in JSON value excluding objects containing the value "red".

data Value Source #

Constructors

Number !Int 
Array [Value] 
Object [Value] 
String String 

Instances

Instances details
Show Value Source # 
Instance details

Defined in Main

Methods

showsPrec :: Int -> Value -> ShowS #

show :: Value -> String #

showList :: [Value] -> ShowS #

Eq Value Source # 
Instance details

Defined in Main

Methods

(==) :: Value -> Value -> Bool #

(/=) :: Value -> Value -> Bool #

Ord Value Source # 
Instance details

Defined in Main

Methods

compare :: Value -> Value -> Ordering #

(<) :: Value -> Value -> Bool #

(<=) :: Value -> Value -> Bool #

(>) :: Value -> Value -> Bool #

(>=) :: Value -> Value -> Bool #

max :: Value -> Value -> Value #

min :: Value -> Value -> Value #