Programming Challenges

Let's solve some coding challenges to practice building function abstractions.

Challenge 1: Prime number

Write an OCaml function, is_prime: integer -> bool, that returns true if the input number is a prime number and false otherwise.

Press + to interact
(** [is_prime x] is [true] if [x] is a prime and [false] otherwise. *)
let is_prime x = false (* TODO: Replace the hard-coded value with your code here *)

Challenge 2: Naive Fibonacci

The Fibonacci series looks like this: 1 1 2 3 5 8 13 ...

Formally,

Fibonacci 0 = 0
Fibonacci 1 = 1
Fibonacci 2 = 1
Fibonacci n = Fibonacci (n-1) + Fibonacci (n-2) for n > 2

Write an OCaml function, fib: int -> int, that returns the n-th Fibonacci number where ...