Format
This commit is contained in:
parent
cf0b23d5a5
commit
b0222f3f42
|
@ -40,9 +40,13 @@ object Day03 extends Day {
|
|||
}
|
||||
def sumOfSurrounding(p: (Int, Int), m: Map[(Int, Int), Int]): Int = {
|
||||
val surrounding = List(
|
||||
(-1, 1), ( 0, 1), ( 1, 1),
|
||||
(-1, 1),
|
||||
(0, 1),
|
||||
(1, 1),
|
||||
(-1, 0), /* */ (1, 0),
|
||||
(-1, -1), ( 0, -1), ( 1, -1)
|
||||
(-1, -1),
|
||||
(0, -1),
|
||||
(1, -1)
|
||||
)
|
||||
surrounding.map(o => m.getOrElse(p + o, 0)).sum
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ object Day07 extends Day {
|
|||
def childrenParser[_: P]: P[List[String]] =
|
||||
P(("->" ~ CharIn("a-z").rep(1).!.rep(1, ",")).?).map(_.fold(List[String]())(_.toList))
|
||||
|
||||
def towerParser[_: P]: P[TowerRef] = P(CharIn("a-z").rep(1).! ~ "(" ~ CharIn("0-9").rep(1).! ~ ")" ~ childrenParser).map {
|
||||
def towerParser[_: P]: P[TowerRef] =
|
||||
P(CharIn("a-z").rep(1).! ~ "(" ~ CharIn("0-9").rep(1).! ~ ")" ~ childrenParser).map {
|
||||
case (name, weight, children) => TowerRef(name, weight.toInt, children)
|
||||
}
|
||||
|
||||
|
|
|
@ -44,10 +44,12 @@ object Day08 extends Day {
|
|||
|
||||
def registerParser[_: P] = P(CharIn("a-z").rep(1).!)
|
||||
def numberParser[_: P] = P(("-".? ~ CharIn("0-9").rep(1)).!).map(_.toInt)
|
||||
|
||||
def instructionParser[_: P] = P(("inc" | "dec").!).map {
|
||||
case "inc" => Inc
|
||||
case "dec" => Dec
|
||||
}
|
||||
|
||||
def testParser[_: P] = P(("<=" | ">=" | "<" | ">" | "==" | "!=").!).map {
|
||||
case "<" => Lt
|
||||
case ">" => Gt
|
||||
|
@ -56,12 +58,15 @@ object Day08 extends Day {
|
|||
case "==" => Eq
|
||||
case "!=" => Neq
|
||||
}
|
||||
|
||||
def fullInstructionParser[_: P] = P(registerParser ~ " " ~ instructionParser ~ " " ~ numberParser).map {
|
||||
case (reg, op, v) => FullInstruction(reg, op, v)
|
||||
}
|
||||
|
||||
def fullTestParser[_: P] = P(registerParser ~ " " ~ testParser ~ " " ~ numberParser).map {
|
||||
case (reg, op, v) => FullTest(reg, op, v)
|
||||
}
|
||||
|
||||
def lineParser[_: P] = P(fullInstructionParser ~ " if " ~ fullTestParser).map {
|
||||
case (i, t) => Line(i, t)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue