Tag Archives: code

Intelligence and Prediction

Cleaning my office today, I found a sheet of paper covered in my own handwriting. I had been somewhere without my journal when an epiphany had struck. I’m cleaning office now, and didn’t want to throw it away. Here it is for posterity, such as that may be.

One measure of intelligence is the ability to take a set of observations at varying degrees of confidence and accurately predict outcomes. The greater the intelligence, experience, and capacity for reason, the more detailed the predictions become, the more distant they can be and the fewer and less confident the observations upon which they are based.

When I was the Director of Technology at RESMARK, the president was my good friend and we would spent long hours planning and discussing strategy. One afternoon we were his office, discussing his weekly meeting with our investor. He told me of the struggles and debates in the meeting over our ship date and our budget; over perceived velocity; over staffing and technology requirements. Partway through our discussion, he said that the investor had asked him to produce a line-item budget breakdown.

I jerked upright, startled. Suddenly something was wrong. This request was not in keeping with everything I knew about the relationship between the investor and the president up this point. I reevaluated my assumptions, and nothing fit. Then one assumption change DID fit. I considered it, thought through the range of consequences and they all ended up at the same place. I looked at the president and announced, “You’re going to get fired in the next three months.”

I was right. About 10 weeks later, the president called me in and told me he had been let go.

Two Beautiful Things

Here are a couple of pages from my journal for today. These are two things I find beautiful, have studied, and can draw… but have only begun to understand.


Click for larger image

The formula on the left is the Y Combinator, derived in Ruby, by Tom Moertel. His writeup and explanation are on raganwald.com. The owl is Aurora, a barn owl who lives and performs daily at Tracy Aviary.

Having time to just noodle around in a journal is something I’ve missed immensely. So great to have time for a life again.

Twitterable Mandelbrot II: The Mandelbrottening

Yesterday I posted my Twitterable Mandelbrot, a ruby script that generates the Mandelbrot Set in 134 characters. A few of you took this as a challenge to shorten my code even further. I didn’t mind, and in fact was interested to see your results; I was sure that an extra character here or there could be shaved off.

What I didn’t expect at all was that somebody would shave fourteen characters off.

Reader brahbur on rubyflow came up with this:

a couple of these changes could be considered “cheating” (-:

80.times{|a|p (0..300).map{|b|x=y=i=0;(x,y,i=x*x-y*y+b/150.0-1.5,2*x*y+a/40.0-1,i+1)until(x*x+y*y>4||i>98);i>98?0:1}*''}

Brahbur’s solution does look different; there are quote marks on each line and it outputs 1s and 0s instead of #s and .s, but the mandelbrot is still clearly visible (Edit: I reduced the size from 300×80 to 240×60 just to keep the outputs roughly the same size):


Click for larger version (1400×800)

I think this is just awesome. Once we’re playing with 0’s and 1’s, I can see another optimization: i>98?0:1 can be replaced with 99i. This bring us down to 118:

60.times{|a|p (0..240).map{|b|x=y=i=0;(x,y,i=x*x-y*y+b/120.0-1.5,2*x*y+a/30.0-1,i+1)until(x*x+y*y>4||i>98);99i}*''}

I have to give most of the credit to brahbur, though–I just saw a tiny tweak, on top of the amazing rewrite they already did. So great. THANK YOU brahbur!

Now, the challenge continues: can you shorten this further? Brahbur was concerned about “cheating”, so let’s define the rules for clarity: Output should be 240×60 (extra quotes and padding are okay) and it should be visually recognizable as a Mandelbrot set. Other than that, go for it.

Twitterable Mandelbrot

As a kid I always thought fractals were neat, but every time I tried to learn how to do them, I got lost in the math. I guess 20 years makes all the difference: today I went and read up on the Mandelbrot set and had one of those “wait, that’s it?” moments.

It took me about 15 minutes to write the program. Here’s the output:


Click for larger version (1400×800)

The whole program was about 400 characters long. I got to thinking, “that’s *almost* small enough to fit into a single tweet…” and then I spent the next hour and a half refactoring my code for size.

Victory:


http://twitter.com/dbrady/status/12546255974

What do you mean I need a hobby? I have one. See?