RiderX

Motorcycling, Bicycling, Software Programming, Linux, etc

Erlang uniq function

Posted by Andy Thu, 11 Jun 2009 02:59:00 GMT

I’ve been spending some time playing with erlang. I could not find a library function to purge duplicates from a list. So I decided to take a crack at writing one of my own.

The solution is quite simple, but it took me some time to come up with. I’m just learning to think functionally, or at least I’m still new to the erlang way.

dedup([]) -> []; dedup([A]) -> [A]; dedup([A,B|T]) when A =:= B -> dedup([B] ++ T); dedup([A|T]) -> [A] ++ dedup(T).

This is about the simplest most straight forward way of doing it that I could come up with. It uses tail recursion, so it’ll be memory friendly. Note that the list needs to be sorted. Only consecutive duplicates are purged.

Consider

dedup([1,1,2,2,2,3,3,4,5,6]).

The first call will match dedup([A,B|T]) when A =:= B. with [1,1,2,2,2,3,3,4,5,6]. This will drop the first element of the list returning the second element and the tail after further deduplication.

The next call will match dedup([A|T]) with [1,2,2,2,3,3,4,5,6].which saves the first element of the list, and dduplicates the rest.

The next few calls drop the next two '2', etc.

Eventually ending up with [1,2,3,4,5,6].

More code than something like Ruby’s Array#uniq, but I’ll take it.

For now I’m having fun with erlang. I hope to build my chops up to a place where I can write some useful applications. I’m thinking DHCP server or something like that maybe.

Posted in | no comments |

Memorial Day Ride

Posted by Andy Tue, 26 May 2009 00:11:00 GMT

Great ride this morning. I set out with a grandiose vision of getting up to Shamokin, PA. This didn’t work out as planned. I got in a 100 mile ride. The following map does not indicate 100 miles. I did some squirreling around up above Posttstown that I can’t quite recall.

http://tinyurl.com/oebrny

Left about 9:00 a.m. Had a lot of hard work on the house on Saturday and Sunday. After power washing the deck at my house I have sunburn on my neck. This didn’t bother me as much as the sore muscles from doing a yard waste burn in the yard. But I digress….

I find myself slowing down some these days. I was never a fast rider. I keep it between 50 and 60. I try to stay in that range no matter what I encounter. Snow, rain, canyon, red light, you get the drift. But seriously… 282 is always fun. For once I had little traffic. Typically I win up following traffic all the way through.
I even had the great pleasure of having an SUV wave me past at the zig/ zag near Pine Swamp. That’s a first.

The road surfaces were still wet in shady areas. It’d rained overnight. Falling spring foliage complicated the matter some, but the riding was still good. Some traffic up on towards 724, but I’d shaken that by taking Old Reading Pike.

Typically the highlight of any ride for me is the end. I try to hit roads around the Limerick nuclear power plant before heading home. These roads seem to be forgotten by time and modern road construction sensibilities. Severe elevation changes in a remote setting so close to civilization.

It’s probably because few people want to build/ develop right next to the power plant. The roads are fantastic in the areas directly adjacent.

So it was a good ride. Wound up cutting it short, home by noon. I hope for other rides as idyllic as far as weather and roads. It’s me that needs to be in shape for it.

Posted in , | no comments |

Dunlop Roadsmart on the R1100RS

Posted by Andy Tue, 12 May 2009 12:47:00 GMT

Put a set of Dunlop Roadsmart tires on the R1100RS. I’m very, very happy with them. I don’t have a ton of experience with different tires. For a few years now I’ve gone with Bridgestone tires, BT010, 020 and then more recently 014 and 021. The reasons for this had been that http://www.swmototires.com/ drop ships them from a warehouse local to Philadelphia. So I’d get them pretty quickly.

After talking to friends and folks at Martin Motosports, I decided to experiment a bit. I considered Michelin Pilot Roads but the cost was prohibitive. Ultimately I wound up choosing the Dunlop Roadsmarts. This was partially based on cost. Mostly though it was based on recommendations from some of the folks I ride with.

These tires feel great. New tires always feel great. It’s difficult to tell if the feel is the tires or the newness. The R1100RS falls into corners at predictable and manageable rate. The feedback from these tires is very good. I’ve never gotten feedback from tires that is so straight forward.

I’m going to be interested to see if the Roadsmarts cup on the front, and wear unevenly (left of center wears much fasster with the telelever on the BMW on the Bridgestones).

So far I’m very happy.

Posted in | no comments |

Older posts: 1 2 3 ... 17