Delete worksheet1.sc

This commit is contained in:
kamoshi 2019-12-06 22:26:25 +01:00 committed by GitHub
parent 4eeef93071
commit 483f962bc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,18 +0,0 @@
import scala.io.Source
val lines = Source.fromFile(getClass.getResource("/input1.txt").getFile).getLines().toList
// 1
val result1 = lines.foldLeft (0) { (acc, i) => acc + (i.toInt/3-2)}
println(result1)
// 2
@scala.annotation.tailrec
def findRecursiveFuel(fuel:Int, acc:Int):Int =
{
val nextFuel = (fuel/3)-2
if (nextFuel <= 0) acc
else findRecursiveFuel(nextFuel, nextFuel+acc)
}
val result2 = lines.foldLeft (0) { (acc, i) => acc + findRecursiveFuel(i.toInt, 0)}
println(result2)