Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.io.Source
- val input = Source.fromFile("C:/work/advent05/input2").getLines.toList
- def toTuple3(list: List[Int]) = (list(0), list(1), list(2))
- def surfaceArea(w: Int, l: Int, h: Int) =
- (2 * l * w) + (2 * w * h) + (2 * h * l)
- def smallestSideArea(w: Int, l: Int, h: Int) =
- List(w, l, h).sorted.take(2).product
- def wrappingPaperAmount(w: Int, l: Int, h: Int) =
- surfaceArea(w,l,h) + smallestSideArea(w,l,h)
- input.map(_.split('x').toList.map(_.toInt))
- .map(toTuple3)
- .map((wrappingPaperAmount _).tupled)
- .sum
- def smallestPerimeter(w: Int, l: Int, h: Int) =
- List(w, l, h).sorted.take(2).sum * 2
- def bowLength(w: Int, l: Int, h: Int) =
- w * l * h
- def ribbonLength(w: Int, l: Int, h: Int) =
- smallestPerimeter(w,l,h) + bowLength(w,l,h)
- input.map(_.split('x').toList.map(_.toInt))
- .map(toTuple3)
- .map((ribbonLength _).tupled)
- .sum
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement