-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from andreas-roehler/master
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** author: Sergei Winitzki */ | ||
|
||
/** | ||
Factorial of 10 | ||
Find the product of integers from 1 to 10 (the factorial of 10). | ||
*/ | ||
|
||
val result = (1 to 10).product | ||
val expected = 3628800 | ||
|
||
assert(result == expected) | ||
|
||
// scala> :load solution1.1.1.1.scala | ||
// Loading solution1.1.1.1.scala... | ||
// result: Int = 3628800 | ||
// expected: Int = 3628800 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** author: Andreas Röhler */ | ||
|
||
/** | ||
Factorial of 10 | ||
Find the product of integers from 1 to 10 (the factorial of 10). | ||
*/ | ||
|
||
val a = 10 | ||
val b = (1 to a) | ||
// val c = b.length | ||
var result = 1 | ||
var counter = 0 | ||
|
||
while (counter < a) { | ||
// println("counter: %s".format(counter)) | ||
result = result * b(counter) | ||
// println("result: %s".format(result)) | ||
counter += 1 | ||
|
||
} | ||
|
||
println("result: %s".format(result)) | ||
|
||
val expected = 3628800 | ||
assert(result == expected) | ||
|
||
// scala> :load solution1.1.1.1_AR.scala | ||
// Loading solution1.1.1.1_AR.scala... | ||
// a: Int = 10 | ||
// b: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) | ||
// result: Int = 1 | ||
// counter: Int = 0 | ||
// result: 3628800 | ||
// expected: Int = 3628800 |