Commit 987a9bfd authored by Alexander Gehrke's avatar Alexander Gehrke
Browse files

[day6] solution

parent 0dc106ce
package aoc2020
import aoc2020.lib._
def day6(input: List[String]): String =
//countGroupAnswersAny(input).sum.toString
countGroupAnswersAll(input).sum.toString
def countGroupAnswersAny(input: List[String]): LazyList[Int] =
input.split("").map(_.flatMap(_.toArray).toSet.size)
def countGroupAnswersAll(input: List[String]): LazyList[Int] =
input.split("").map(lines => {
val answers = lines.map(_.toSet)
answers.headOption
.map(h => answers.tail.fold(h)(_ intersect _))
.map(_.size)
.getOrElse(0)
})
......@@ -7,5 +7,6 @@ package aoc2020
case 3 => input(boolChar('#'))(day3)
case 4 => input()(day4)
case 5 => input()(day5)
case 6 => input()(day6)
}
println(out)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment