Skip to content

Commit

Permalink
Merge pull request #46 from andreas-roehler/master
Browse files Browse the repository at this point in the history
  • Loading branch information
winitzki authored Dec 25, 2023
2 parents cf2aa28 + 8e83482 commit e157002
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
16 changes: 16 additions & 0 deletions chapter01/worksheets/solution1.1.1.1.scala
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
34 changes: 34 additions & 0 deletions chapter01/worksheets/solution1.1.1.1_AR.scala
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

0 comments on commit e157002

Please sign in to comment.