Archives for Uncategorized

A note on fractions

I ran across a blog post called Why 0.1 Does Not Exist In Floating-Point. The author uses long division in binary to demonstrate his point. This is understandable, given that the host blog is called Exploring Binary, but there is a an easier way to determine whether the fraction p/q has a terminating floating point […]

An invitation to FP for Clojure noobs

I’ve heard newcomers to Clojure ask how to get started with functional programming. I believe that learning to program in the functional style is mostly a matter of practice. The newcomer needs to become familiar with a handful of higher order functions, and how they are used in common idioms. This can be done by […]

The transpose function

I am going to discuss a function I think belongs in the Clojure core language. The function is called transpose. It is defined as follows. (defn transpose [xs] (apply map vector xs)) Here is what it does: user> (def m [ [‘a ‘b ‘c ‘d] [1 2 3 4] ]) #’user/m user> m [[a b […]

Cracker Barrel puzzle

A recent posting to the Trifunc group invited the members to solve the Cracker Barrel puzzle. Brian Adkins, the author of the challenge, posted a solution in Haskell. Here is my Clojure solution. The game is played on a triangular board with 15 holes, labeled 0 through 14. Initially, 14 of the holes contain pegs, […]

The expressiveness of functional programming

I’d like to revisit the discrete convolution problem described in my previous post, to consider the expressiveness of functional programming. Here I am interested in the power of code to communicate intent; the bare metal speed of the code is secondary. The various comments and proposed implementations in this Google Groups thread are what got […]

British Lottery Puzzle

Have I mentioned that I’m a sucker for probability puzzles? I found this one at ibbly.com: Two teams from opposite ends of the country have been drawn to play each other in a competition. They need to determine which team plays at home and do so fairly at a distance. They decide to try to […]

syntax coloring

I happend to read a new (to me) blog, Thoughts on life, computers, and eternal happiness. The lead post featured some Erlang code, presented with very nice syntax coloring. I asked the author how he managed that. Emacs. Of course. He had used a package called htmlize.el. Emacs never ceases to surprise me with new […]