From f885b79568a221f9d1cf8edc612f69bec5aad1cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 3 Apr 2013 22:05:32 +0200 Subject: Scala : add sandbox/sum --- Scala/sandbox/sum.scala | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Scala/sandbox/sum.scala diff --git a/Scala/sandbox/sum.scala b/Scala/sandbox/sum.scala new file mode 100644 index 0000000..a09f26b --- /dev/null +++ b/Scala/sandbox/sum.scala @@ -0,0 +1,14 @@ + +object Sum { + + def sum (f: Int => Int, a: Int, b: Int) = { + def loop(a: Int, acc: Int): Int = + if (a > b) acc + else loop(a + 1, f(a) + acc) + loop(a, 0) + } + + def run = + println(sum(x => x * x, 3, 5)) + +} -- cgit v1.1-2-g2b99