author | Christian Urban <christian.urban@kcl.ac.uk> |
Tue, 02 Nov 2021 14:40:06 +0000 | |
changeset 848 | 2e868b5867d8 |
parent 409 | fb8ee3f58d19 |
permissions | -rw-r--r-- |
409
fb8ee3f58d19
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
def collatz(n: BigInt) : Boolean = n match { |
fb8ee3f58d19
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
case n if (n == 1) => true |
fb8ee3f58d19
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
case n if (n % 2 == 0) => collatz(n / 2) |
fb8ee3f58d19
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
case _ => collatz(3 * n + 1) |
fb8ee3f58d19
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
} |