General introduction to Programming Languages ([SCOTT] chapter 1).
Clojure fundamentals.
def, let).
+, +', -, *, *', /, <, <=, =, not=, ==, >, >=, boolean, char, char?, dec, even?, format, inc, keyword?, neg?, nil?, number?, odd?, pos?, quot, rem, str, string?, symbol?, and zero?.
quote (') special form.
not, and, or. Short-circuit evaluation.
if, cond, case). Truthy and falsy values.
defn) and application. Parameters. Multi-arity and variadic functions. Docstrings. Anonymous functions and closures. The apply, fn?, and ifn? functions.
loop/recur.
Clojure collections.
butlast, concat, cons, count, cycle, distinct, drop, drop-while, empty?, every?, filter, first, interleave, interpose, iterate, last, map, mapcat, nth, partition, partition-by, range, reduce, remove, repeat, rest, reverse, seq, seq?, some, sort, split-at, split-with, take, and take-while.
conj and list.
assoc, conj, get, nth, vec, and vector.
assoc, contains?, dissoc, frequencies, get, keys, merge, vals, and zipmap.
conj, contains?, disj, get, and set.
Parallel programming.
pmap function.
NOTE: Once the exam starts you are not allowed to share any items with anyone else.
Pen, pencil, eraser, pencil sharpener.
Simple scientific calculator. You are not allowed to use a cell phone, programmable calculator, tablet, computer, or any other electronic device.
Personal cheat sheet with the following characteristics:
|
Give three examples of Clojure built-in higher-order functions.
What is the result of the following Clojure expression?
(take-while #(< % 10) (iterate #(+ % %) 1)))
Write a Clojure function called contains-all-digits? that takes an integer argument \(n\) and returns true if \(n\) contains each of the ten digits from 0 to 9 at least once, or false otherwise.
Examples:
(contains-all-digits 1023456789) => true (contains-all-digits 1236) => false
You are given the following Clojure code:
(defn mystery ([x] (mystery x #(* 2 %) #(inc %))) ([a b c] (c (b a)))) (defn wierd [& t] (let [n (count t)] (cond (zero? n) 1 :else (inc (apply wierd (rest t))))))
What is the result of evaluating the following expressions?
(mystery 5)
(wierd 4 8 15 16 23 42)
(mystery 2 dec inc)
(mystery 10 wierd (fn [z] (* z z)))
Write a function in Clojure called how-many-div-3 that receives as input a sequence of integers and returns the result of counting how many of these numbers are exactly divisible by 3. For example:
(how-many-div-3 ()) => 0 (how-many-div-3 [6 2 3 12 4]) => 3 (how-many-div-3 '(2 5 7 11 19)) => 0 (how-many-div-3 [0 33 66 99]) => 4
You have a sequential program that takes 10 seconds to execute using 1 processor. The parellel version of the same program takes 2 seconds to execute using 8 processors. Calculate its speedup.