Archive for September, 2007

Pleasing small victories

Monday, September 10th, 2007

So a coworker got me hooked on Project Euler today, and I’ve been spending far too much of my free time on it. However, it did lead to a very pleasing moment.

One of the problems deals with Collatz sequences: For any number, divide by two if the number is evenly divisible by two, multiply by three and add one otherwise. Stop when you reach the number 1. The task at hand was to find the number between 1 and 1,000,000 with the longest Collatz sequence.

My first attempt at counting this sequence, rather predictably, failed on large input:

 collatzsz 1 = 1
 collatzsz n = 1 + collatzsz nxt where
     nxt = if 0 == mod n 2 then div n 2 else 3 * n + 1

Duh. Stack overflows everywhere. (Note: there’s probably a flag for GHC that will make this Just Work.) I figured that Haskell would probably go ahead and optimize tail calls for me, so I gave it a go:

 collatzsz 1 accum = 1 + accum
 collatzsz n accum = collatzsz nxt (1+accum) where
     nxt = if 0 == mod n 2 then div n 2 else 3 * n + 1

Sure enough, it works for even the most obnoxiously large values of n.

Yes, I know that this is exactly what the language is supposed to do, but sometimes it seems like a small victory when a piece of software does even that. So thanks to the good folks who make GHC. You made me smile today.

The iPhone price drop makes me happy to be a gadget late adopter

Wednesday, September 5th, 2007

Apple announced some new products and prices today, and apparently some people aren’t exactly (update: not all that displeased, as it turns out) pleased about the prices of iPhones dropping by $200 so quickly after they were introduced. Which I sort of get and then sort of don’t. Yeah, it’s a bummer and all that it cost more when you bought it, but then they’re not taking any of your functionality away. I think John Gruber sums the situation up nicely:

And for those of you who’ve already bought one and are pissed about the price cut, if you didn’t think the iPhone was worth $599, you shouldn’t have bought it. That’s how supply and demand works.

Indeed.

My price point for an iPhone is “free with a service contract like my current crappy phone.” When it hits there, I’ll probably get one. Why not?

For the time being, however, the prices on “classic” iPods — the kind that just plays music, which is all I’d use it for, anyway — have dropped and the disks have gotten bigger. For the same price that I got my 40GB model for a few years back they now have a 160GB model. That’s more space than my laptop has! I’m already having to filter out tracks when I load the iPod, so seeing these much bigger models at the same old prices is quite nice. (Not that I’m going to buy one, mind you. But still.)

Best. Television. Program. Ever.

Wednesday, September 5th, 2007

If you don’t watch Top Gear, you should. It’s by far the funniest thing I’ve seen on TV in years. Here’s their absolutely hilarious north pole episode. Can a car make it to the north pole? The Top Gear crew races a Toyota pickup against a sled dog team to try to find out.

Many thanks to Jill and Tej for turning Stephanie and me on to this superb program!

I’m glad last week is over.

Tuesday, September 4th, 2007

I’m just sayin’.

Thanks to the comment thread over at Eye Level Pasadena for pointing out the JPL Weather Station. No thanks to that rotten sun for cooking all of us over the last week.

An ode to Python 3000

Tuesday, September 4th, 2007

Inspired by the what’s new page:

 def reduce(f, seq, val = None):
     if val is None: val = next(seq)        
     for x in seq:
         val = f(val, x)
     return val

Java programmers are funny

Sunday, September 2nd, 2007

Having dealt with code of the ObjectModelAdapterFactoryBuilderInterfaceFacade variety before, I of course find Stevey’s comments about Java to be spot on.

Sun Microsystems Demands University Study Retraction

The University of Washington, apparently hoping to capitalize on the recent hype around their controversial study on Baby Einstein™-style videos, followed up yesterday with another, similar study. In the new study, researchers found that Java programmers understand an average of seven fewer Computer Science concepts per hour spent with Java each day compared to similar programmers using other languages. Sun calls the study “seriously flawed”, citing the fact that you can combine the names of Gang of Four Design Patterns to form new Computer Science concepts that all Java programmers understand, such as the ObserverFactoryBridge, the BridgeFactoryObserver, and the well-known FactoryObserverBridgeChainOfCommandSingletonProxy, beloved of Java programmers everywhere. Java experts at Sun say they’re not sure how many combinations there are of the twenty-three pattern names, but there are “definitely a lot of them.”


This is a free Wordpress template provided by Mathew Browne | Web Design | SEO