From 5c46eee1bf187b95f3ef614611c12903faabcc27 Mon Sep 17 00:00:00 2001 From: Andreas Roehler Date: Sat, 23 Dec 2023 09:54:02 +0100 Subject: [PATCH] Exercise 1.6.1.1, description added Signed-off-by: Andreas Roehler --- chapter01/worksheets/solution1.6.1.1.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/chapter01/worksheets/solution1.6.1.1.scala b/chapter01/worksheets/solution1.6.1.1.scala index 9af891c..7026704 100644 --- a/chapter01/worksheets/solution1.6.1.1.scala +++ b/chapter01/worksheets/solution1.6.1.1.scala @@ -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)