Clojure recursive:

"P04 (*) Find the number of elements of a list." (loop [num 0 xs xs] (if (next xs) (recur (+ num 1) (next xs)) (+ num 1)))) read more# Other articles

# P03 - Find the nᵗʰ Element of a List

This problem is very nice because the Clojure and Scala implementations are practically the same. It allows to appreciate the different syntaxes better.

Below is Peter’s solution to the problem, in Clojure:

{:doc "P03 (*) Find the Kth element of a list." :pre [(seq? xs)]} (if (= 0 n) (first xs) (recur (- n 1) (next xs))) ) read more# P02 - Find the Penultimate Element of a List

# P01 - Find the last element of a list

The first problem is to find the last element of a list.

This is Peter’s Clojure version:

"P01 (*) Find the last element of a list." (if (next input) (recur (next input)) (first input)))And here is my Scala version:

read more# Me too! 99 Problems in Scala

Inspired by my friend Peter Brachwitz, I also decided to tackle on the “99 problems“.

He had the noble new-year resolution to solve these problems in Clojure, and post the solutions on his blog.

read more

Page 1 / 1