aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TUTORIAL.md20
-rw-r--r--solutions/collatz.slip6
2 files changed, 22 insertions, 4 deletions
diff --git a/TUTORIAL.md b/TUTORIAL.md
index 30e7d62..ba6b8a1 100644
--- a/TUTORIAL.md
+++ b/TUTORIAL.md
@@ -424,7 +424,19 @@ language. The solutions can be found in the `solutions`
folder under the project root.
-Exercise 1: Running code
+Exercise 1: Collatz conjecture step
+-----------------------------------
+
+Given an integer `x`, compute the next step of the sequence
+famous from the Collatz conjecture. In other words, if `x`
+is even, return half of `x`, and if `x` is odd, return
+`3x + 1`.
+
+This should make you familiar with arithmetic and
+conditional logic.
+
+
+Exercise 2: Running code
------------------------
Write a function `cond-add-inv` in a file called `a.slip`.
@@ -448,7 +460,7 @@ may want to try out the `--babysteps` feature
(see `myslip --help`).
-Exercise 2: Fibonacci sequence
+Exercise 3: Fibonacci sequence
------------------------------
Write a function that calculates the n:th fibonacci number,
@@ -468,7 +480,7 @@ n saved
```
-Exercise 3: Generic functions – the identity
+Exercise 4: Generic functions – the identity
--------------------------------------------
Write the identity function for any type.
@@ -477,7 +489,7 @@ This should make you familiar with typing function
definitions that contain generics.
-Exercise 4: Map left / right (integers)
+Exercise 5: Map left / right (integers)
---------------------------------------
Write functions `map-left` and `map-right` that take a
diff --git a/solutions/collatz.slip b/solutions/collatz.slip
new file mode 100644
index 0000000..e561b17
--- /dev/null
+++ b/solutions/collatz.slip
@@ -0,0 +1,6 @@
+
+(let x 7)
+(if (= (* (/ x 2) 2) x)
+ (/ x 2)
+ (+ (* 3 x) 1))
+