Mercurial > repos > other > SevenLanguagesInSevenWeeks
view 6-Clojure/fibonaci.clj @ 93:39084e2b8744
Add a function for word-aware text wrapping
Potentially hugely inefficient because we iterate through the
string character by character, but then splitting it first and
iterating over words still needs to iterate over the string to
know where to split.
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 18 Jun 2019 21:05:00 +0100 |
parents | eccc649d49a2 |
children |
line wrap: on
line source
; For a pair of (assumed) consecutive (assumed) Fibonacci numbers and generates the next pair (defn fib-pair [[a b]] ; I *think* this a vector and not just two parameters so that we can iterate (because you can't return two values) [b (+ a b)]) (print (fib-pair [3 5])) (print (take 5 (map first (iterate fib-pair [1 1])))) (print (nth (map first (iterate fib-pair [1 1])) 50)) ;The book says 500th, but even 100th gives java.lang.ArithmeticException: integer overflow!