-
-
Save tong92/0001a9751a202a5fd3d55d2b79528918 to your computer and use it in GitHub Desktop.
day1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.io.Source | |
def makeBag(xs: List[String]): List[Int] = | |
def cal(xs: List[String], store: Int): List[Int] = xs match | |
case (h :: t) if h != "" => cal(t, store + h.toInt) | |
case (h :: t) if h == "" => store :: cal(t, 0) | |
case _ => Nil | |
cal(xs, 0) | |
def ans1(xs: List[String]): Int = makeBag(xs).max | |
def ans2(xs: List[String]): Int = makeBag(xs).sortWith(_ > _).take(3).sum | |
@main | |
def app = | |
val input = Source.fromFile("day1.txt").getLines.toList | |
print(ans2(input)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment