Skip to content

Commit

Permalink
Exercise 1.6.1.1, description added
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Roehler <[email protected]>
  • Loading branch information
andreas-roehler committed Dec 23, 2023
1 parent 3ca83b1 commit 5c46eee
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions chapter01/worksheets/solution1.6.1.1.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
Exercise 1.6.1.1
Define a function that computes a “staggered factorial” (denoted by n!!) for positive
integers. It is defined as either 1 · 3 · ... · n or as 2 · 4 · ... · n, depending on whether n is even or odd.
For example, 8!! = 384 and 9!! = 945.
*/

def staggeredFactorial(n: Int): Int = (n to 1 by -2).product

assert(staggeredFactorial(8) == 384)

0 comments on commit 5c46eee

Please sign in to comment.