quinta-feira, 16 de junho de 2011

What programming is

Programming is a craft. At its simplest, it comes down to getting a computer to do what you want it to do (or what your user wants it to do). As a programmer, you are part listener, part advisor, part interpreter, and part dictator. You try to capture elusive requirements and find a way of expressing them so that a mere machine can do them justice. You try to document your work so that others can understand it, and you try to engineer your work so that others can build on it. What’s more, you try to do all this against the relentless ticking of the project clock. You work small miracles every day.

It’s a difficult job.

I'm reading "The Pragmatic Programmer". The text above is an excerpt from its preface.

segunda-feira, 9 de maio de 2011

Puzzle solution: The 100 light bulbs problem

This post is only an answer for the puzzle I posted last week:

Here's my solution written in python:



segunda-feira, 2 de maio de 2011

The 100 light bulbs problem

Herval, a guy I met some months ago, is creating something he says is a "nerd social network where you can find and upload puzzles". It's not 100% ready but it's on its way, he says.

The fact is that at http://braintea.se I found an interesting puzzle that caught my attention by the end of last friday's afternoon. After my eight regular hours of work, I spent about two hours trying to solve it, but without success. So I left it behind. By the morning of the following saturday, I was looking for a good reason to leave my bed when "The puzzle" came to my mind and a ran to my computer. Thirty minutes lates I was done: Problem solved.

I think puzzles are a very interesting way of improving problem-solving skills. The feeling of "I did it" is really rewarding. So, I'll leave you with The 100 light bulbs problem:

You have 100 toggle switches, each connected to a corresponding light bulb. At first, all lights are off. You then press every single toggle, thus turning on all of the bulbs. Next, you press every second toggle (ie. 2, 4, 6, 8, ..., 96, 98, 100) so that all the even numbered bulbs are turned off. Then you press every third toggle (3, 6, 9, ... 93, 96, 99) and every fourth toggle (4, 8, 12, ... 92, 96, 100), and every fifth toggle (5, 10, 15, ... 90, 95, 100), and so on, and so on, until the last two sequences, which are every ninety ninth toggle (99) and every hundredth toggle (100). Question: Which light bulbs will now be on?
For more puzzles visit: http://braintea.se/

Next week I'll post a little python script with the puzzle solution and some comments.

See ya.

sábado, 30 de abril de 2011

Hello world!

At last I'm starting a blog about technical stuff. As it's name suggests, I'll be writing mainly about code, but not limited to it. One of the most important things is that anonymous comment are allowed. This will provide a way for my readers to criticize the code I write without getting things personal.

The point here is improvement.