From 426376caf815bcfce23b648a199d6ead2c440fb6 Mon Sep 17 00:00:00 2001 From: ymtk-test Date: Sun, 11 Apr 2021 15:07:14 +0900 Subject: [PATCH] =?UTF-8?q?=E7=B7=B4=E7=BF=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bsp/sbt.json | 1 + Factorial.scala | 9 ++++----- project/build.properties | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 .bsp/sbt.json create mode 100644 project/build.properties diff --git a/.bsp/sbt.json b/.bsp/sbt.json new file mode 100644 index 0000000..823d8e1 --- /dev/null +++ b/.bsp/sbt.json @@ -0,0 +1 @@ +{"name":"sbt","version":"1.5.0","bspVersion":"2.0.0-M5","languages":["scala"],"argv":["C:\\Program Files\\Java\\jdk-11.0.2/bin/java","-Xms100m","-Xmx100m","-classpath","C:\\Program Files (x86)\\sbt\\\\bin\\sbt-launch.jar","xsbt.boot.Boot","-bsp","--sbt-launch-jar=C:\\Program%20Files%20(x86)\\sbt\\\\bin\\sbt-launch.jar"]} \ No newline at end of file diff --git a/Factorial.scala b/Factorial.scala index 65e5bc2..e94a2c8 100644 --- a/Factorial.scala +++ b/Factorial.scala @@ -1,7 +1,6 @@ import scala.math.BigInt -object Factorial extends App { - def factorial(i: BigInt): BigInt = if (i == 0) 1 else i * factorial(i - 1) - - println(factorial(10000)) -} +object FactorialTailRec extends App { + def factorial(i: BigInt, acc: BigInt): BigInt = if (i == 0) acc else factorial(i - 1, i * acc) + println(factorial(10000, 1)) +} \ No newline at end of file diff --git a/project/build.properties b/project/build.properties new file mode 100644 index 0000000..e67343a --- /dev/null +++ b/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.5.0