2008 01 21

I’ve just started teaching a new module today to second year Computer Science students. It’s the Programming Languages module where students are supposed to be exposed to alternative paradigms and programming languages.

Today I had a lab session with one of the group of students and, as lecture hasn’t started yet, I asked them to write a number of moderately challenging C++ programs for me to make sure they were competent programmers. Those students studied the imperative portions of C++ during Year I and object-oriented Java during the first semester of Year II so I expect them to be able to complete the lab sheet.

Just for fun, here are the problems I’ve asked them to solve. I’m sure most of you will find them relatively easy but, remember, the point is to make sure everyone starts with (more or less) the same grasp of imperative programming.

Problem 1 - Two kinds of Fibonacci

Write a program in C++ that prompts the user for any non-negative integer n and displays on screen the times required (in seconds) to calculate fib(n) both recursively and iteratively.

(I told the students about the C time() function)

Problem 2 - Generation of numbers

Consider the following algorithm to generate a sequence of numbers. Start with an integer n. If n is even, divide it by 2. If n is odd, multiply it by 3 and add 1. Repeat this process with the new value of n, terminating when n = 1. For example, the following sequence of numbers will be generated for n = 22:

22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1

It is conjectured (but not yet proven) that this algorithm will terminate at n = 1 for every integer n. For an input n, the cycle-length of n is the number of numbers generated up to and including the 1. In the example above, the cycle length of 22 is 16.

Write a program in C++ that prompts the user for any positive integer n and displays on screen (i) the sequence of numbers generated for that n and (ii) the cycle length.

(This is a slightly modified version of a real ACM ICPC problem)

Problem 3 - String subsequence

Given two strings a and b, print the longest string x of letters which is a subsequence of both a and b. For example,

  • if a is pretty and b is typing, then x is ty,
  • if a is walking and b is king, then x is king and
  • if a is iris and b is aqua, then x is an empty string.

Write a program in C++ that prompts the user for the two strings a and b and displays on screen the appropriate x.

(I told the students about C++’s extensive string manipulation facilities)

Objective

My first objective is to make sure that students understand than programming can be fun and rewarding as an intellectual (unmarked) activity. My second objective is to make sure that the students are ready to digest whatever I’ve prepared for them as from Friday…

Factor? Scheme? Ruby? I’ll tell you on Friday :-)

Popularity: 4% [?]

written by avinash

2007 12 19

Someone said that Linux was progressing only through sheer luck… And this make Linus Torvalds react:

And don’t EVER make the mistake that you can design something better than
what you get from ruthless massively parallel trial-and-error with a feedback cycle. That’s giving your intelligence much too much credit.

Linus was referring to the open source development model (have you read The Cathedral and the Bazaar? You really really should!) compared to the classical corporate model of software development.

And, of course, he is right.

Popularity: 2% [?]

written by avinash

2007 12 03

Father Christmas will shortly give my son and myself a brand new Saitek Cyborg Evo joystick.

I am a flight simulator addict. And my three years old son too. I always wanted to be a pilot. How I became a computer scientist is a complete mystery to me.

When I have nothing to do (or, more precisely, when I really want to have fun), I boot my PC under Windows XP (I feel I have lost all credibility now…) and I load Flight Simulator 2002:

I know it’s old. But it runs perfectly on my (rather limited) GeForce FX5200 graphics card. Being a perfectionist, I only pilot two airplanes: the default Cessna 172SP Skyhawk and an Airbus A320 which I’ve obtained at Flightsim.

What my son and I really like is to fly from an airport, say, Toulouse Blagnac in France, and land at another airport not so far, say, Paris Orly. I like flying the A320 in IFR conditions with real weather and under the control of ATC.

But it does not work with Linux or Mac OS X

Yep. And this is crap as I routinely use an Apple MacBook and a lot of Linux boxes. So I’ve been looking at multiplatform flight simulators recently.

The first one is X-Plane:

According to the blurb, “X-Plane is the most thorough, flexible, and realistic flight simulator available for personal computers, and is available for Mac, Windows, and Linux platforms.” I’ve read numerous forums and people seem to agree that X-Plane is vastly superior to Flight Simulator.

Unfortunately, it seems very difficult to buy. It is not available on Amazon for instance. It’s only available at the X-Plane Store and shipping it to Mauritius is prohibitive.

I’ve downloaded the demo and used it a little but I really needs to get the Saitek first to appreciate it.

Another issue is the amount of disk space it requires: at least 4Gb! And, if you buy the complete version, you require 60Gb of hard disk space for the scenery! On my small laptop, I don’t have 60Gb, not even 4Gb free.

Perhaps I should try a previous version which had much more modest requirements…

Opensource?

Another contender is FlightGear which is an open source flight simulator. I tried it once. And I have to try it again.

Conclusion

2008 will be an interesting year. There will be a lot of transitions.

Will my son and I move to X-Plane or FlightGear after years and years of Flight Simulator? Only time will tell.

Popularity: 3% [?]

written by avinash