Create worksheet8.sc

a bit more normal
This commit is contained in:
kamoshi 2019-12-08 07:40:06 +01:00 committed by GitHub
parent 7a12b4c2a2
commit e24125e2c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,8 @@
import kamlib.Reader
val zeroes = Reader.readString("/input8.txt").toList.map(_.asDigit).grouped(150).toList.map(x => (x.foldLeft(0){(acc, elem) => if (elem==0) acc+1 else acc}, x))
val minimum = zeroes.minBy(_._1)._2
val ones = minimum.foldLeft(0){(acc, next) => if (next==1) acc+1 else acc}
val twos = minimum.foldLeft(0){(acc, next) => if (next==2) acc+1 else acc}
println(ones*twos)