Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.88 KB | None | 0 0
  1. import scala.io.Source
  2.  
  3. val input = Source.fromFile("C:/work/advent05/input2").getLines.toList
  4.  
  5. def toTuple3(list: List[Int]) = (list(0), list(1), list(2))
  6.  
  7. def surfaceArea(w: Int, l: Int, h: Int) =
  8.   (2 * l * w) + (2 * w * h) + (2 * h * l)
  9.  
  10. def smallestSideArea(w: Int, l: Int, h: Int) =
  11.   List(w, l, h).sorted.take(2).product
  12.  
  13. def wrappingPaperAmount(w: Int, l: Int, h: Int) =
  14.   surfaceArea(w,l,h) + smallestSideArea(w,l,h)
  15.  
  16. input.map(_.split('x').toList.map(_.toInt))
  17.   .map(toTuple3)
  18.   .map((wrappingPaperAmount _).tupled)
  19.   .sum
  20.  
  21.  
  22. def smallestPerimeter(w: Int, l: Int, h: Int) =
  23.   List(w, l, h).sorted.take(2).sum * 2
  24.  
  25. def bowLength(w: Int, l: Int, h: Int) =
  26.   w * l * h
  27.  
  28. def ribbonLength(w: Int, l: Int, h: Int) =
  29.   smallestPerimeter(w,l,h) + bowLength(w,l,h)
  30.  
  31. input.map(_.split('x').toList.map(_.toInt))
  32.   .map(toTuple3)
  33.   .map((ribbonLength _).tupled)
  34.   .sum
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement