Strange Loops

No Matter Where You Go, There You Are

The Coffee Shop Solution

| Comments

The solution I came up with at the coffee shop (Corrected so that it’ll compile)

g :: Int -> Int -> Intg a m  | m == 1         = a  | m `mod` 2 == 1 = g (a + 1) (3 * m + 1)  | otherwise      = g (a + 1) (m `div` 2)

Think Higher Order

| Comments

A couple of weeks back I mentioned this book that I wanted to get:


“Higher-Order Perl: Transforming Programs with Programs” (Mark Jason Dominus)

A friend got their copy first and kindly loaned it to me (mine arrives Friday). The first 3 chapters covering recursion, dispatch tables and memoization respectively are kind of alright. Not particularly interesting to me because I’ve used these techniques in the part.

Chapter 4 is where it starts to get interesting for me.
This simple example has made me think about Perl a little differently:

sub upto { my ($m, $n) = @_; return sub {   $m <= $n ? $m++ : undef;  };}

I’m a quarter of the way through chapter 4. MJD’s solution to permutation makes the normal interviewing solution to that question seem ugly in comparison [Here’s a hint: it uses iterators! Read the book for the solution]

A Solution to a Question

| Comments

A solution to the 3n + 1 problem in Haskell. A different solution to the one I gave in the coffee shop. This one is a little more conventional. The coffee shop solution did work though.

module Main wheremain :: Int -> Int -> Intmain i j = maximum $ map (\x -> f 0 x) [i..j]f :: Int -> Int -> Intf a 1 = a + 1f a m =     if m `mod` 2 == 1       then f (a + 1) (3 * m + 1)       else f (a + 1) (m `div` 2)

Yet Another Dating Quiz

| Comments

Your dating personality profile:

Wealthy/Ambitious - You know what your goals are and you pursue them vigourously. Achieving success is important to you.
Liberal - Politics matters to you, and you aren’t afraid to share your left-leaning views. You would never be caught voting for a conservative candidate.
Stylish - You do not lack for fashion sense. Style matters. You wouldn’t want to be seen with someone who doesn’t care about her appearance.
Your date match profile:

Shy - You are put off by people who are open books. You are drawn to someone who is a bit more mysterious. You want to draw her out of her shell and get to know what she is all about.
Practical - You are drawn to people who are sensible and smart. Flashy, materialistic people turn you off. You appreciate the simpler side of living.
Intellectual - You seek out intelligence. Idle chit-chat is not what you are after. You prefer your date who can stimulate your mind.
Your Top Ten Traits

1. Wealthy/Ambitious
2. Liberal
3. Stylish
4. Adventurous
5. Sensual
6. Intellectual
7. Outgoing
8. Athletic
9. Religious
10. Traditional
Your Top Ten Match Traits

1. Shy
2. Practical
3. Intellectual
4. Traditional
5. Stylish
6. Religious
7. Adventurous
8. Athletic
9. Funny
10. Sensual

Take the Online Dating Personality Quiz at Dating Diversions

Really Tired

| Comments

Got a chunk of stuff done today at work. For some reason though, I’m feeling really drained. I’m going to retire early tonight.

Halfway Through the Gentle Introduction

| Comments

I’ve made pretty good progress through a Gentle Introduction to Haskell. Working through the literate Haskell code supplied with the introduction is really informative. Infinite data structures take some understanding to wrap your brain around.

I’m still having issues with the fibonacci example implemented with list comprehensions, lazy patterns and infinite lists. E.g.


fib@(1:tfib)    
= 1 : 1 : [ a+b | (a,b) <- zip fib tfib ]


Recently I was pointed to two good supplements for Haskell. HaskellDemo and A Concise Introduction to Gofer/Haskell. Looking at these two articles, Haskell doesn’t seem like such an intimidating language after all.

Wrestlemania

| Comments

I admit it’s a little bit of a guilty pleasure. But me and J hung out to watch Wrestlemania XXI yesterday. What are grown men like us doing watching wrestling? Don’t I know it’s fake? Yes. I know it’s fake. Does it make difference though…. It’s still fun to watch. Knowing it’s fake just helps me realize the dangerous risk these people take to entertain the audience. The way those guys land isn’t faked. One wrong move can be fatal or career ending. Like they said in the PSA “Don’t try this at home”.

In tribute to Wrestlemania, my top 7:
Bret Hart
HBK
Stone Cold Steve Austin
The Rock
HHH
Hulk Hogan
Undertaker

Wrote a Little Todo App

| Comments

Based very closely on Howto make a TODO List Application found off the Ruby on rails website. In fact, my code is exactly like the Howto. The differences I had was in my infrastructure:
  • lighttpd vs WEBrick
  • SQLite vs MySQL

Initial impressions: wow! damn! how did they… yeah! wow! damn!

Afterthoughts: I need to write some scripts to simulate parts of the framework for my day job (e.g. rails appname, generate controller name). I wished we used the rails framework at work…

Some cynics say Rails is just another overhyped framework, that Seaside and Wee are better solutions. That might be true but Rails is a clear win over everything mainstream right now.

Side thought: Groovy is very similar to Ruby. Rails takes advantage of Ruby to do the things it does. I wonder if anybody has taken a similar approach using Groovy for the Java world.