Skip to content

Instantly share code, notes, and snippets.

@tong92
Created December 30, 2022 13:04
Show Gist options
  • Save tong92/0001a9751a202a5fd3d55d2b79528918 to your computer and use it in GitHub Desktop.
Save tong92/0001a9751a202a5fd3d55d2b79528918 to your computer and use it in GitHub Desktop.
day1
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