Blog

Haskell is an interesting language. Forces you to break the problem up into small pieces. Haskell is the seventh language featured in Seven Languages in Seven Weeks and the fifth problem for day 1 of Haskell has kept me stumped for a couple of days now. You are expected to write a Haskell version of the map-coloring problem from the Prolog chapter.

You are given a map of the southeast corner of the United States. You have to write a program to color the five states so that no two states that border each other are colored the same.

Charlieplexing is a multiplexing technique for driving LED’s using fewer IO pins. You can use it to control N*(N-1) LED’s where N is the number of IO pins that you are using. It works because the IO pins on a microcontroller have three available states. If the pin is set to output then it can output a 1 or 0. The third state is input, where the pin is set to high impedance and is effectively disconnected from the circuit.

This is the example circuit from the Wikipedia entry referenced above. There are three pins being used to drive six LED’s. Two pins have to be set to output, one high and one low, and one pin has to be disconnected from the circuit in order to address an LED.

Here is the example circuit on my breadboard. It’s being driven by a TI MSP430.

I found that the quickest way to make it work was to set all the pins so that they were inputs, then override the two that I needed as outputs and finally set the one pin that I wanted to output a 1.

The solution for calculating the distance between any two points on a sphere is an equation called the Haversine Formula. It can be used to estimate the distance between any two points on Earth using their latitude and longitude by making the assumption that the Earth is a perfect sphere. It isn’t, but for some applications the approximation is good enough.

Here’s an example calculating the distance of two points using Python: