Skip to content

Commit

Permalink
Merge pull request #45 from andreas-roehler/master
Browse files Browse the repository at this point in the history
Exercise 1.6.1.1, description added
  • Loading branch information
winitzki authored Dec 23, 2023
2 parents 3ca83b1 + 5c46eee commit cf2aa28
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 cf2aa28

Please sign in to comment.