Doan Courant

The semi-whenever newsletter for one of the many Doan Families.

Thursday, February 25, 2010

Basic programming

One of the college classes I am taking is a problem solving/programming class. It is fun. I am learning some basic programming techniques.
Challenge, for all you math/programming oriented people out there. What does this simple script do?

numerator = 1;
denominator = 1;
term = numerator/denominator;
num=0;
sumt = 1;
tic;
while abs(term) >= 0.0000001
denominator=denominator+2;
term=numerator/denominator;
if mod(num,2)==0
sumt=sumt-term;
else
sumt=sumt+term;
end
num=num+1;
end
toc;

The prize is a year's supply of dog hair.
Also, if you know what it does, can you show me a more efficient way to do it?
Thank thee.

**Note: Due to circumstances beyond my control, there should be some indenting in the code (specifically for the while and if/else loops). I apologize for any confusion.

1 comment:

Bradley W. Maston said...

Does it make waffles? Faster way? Waffle iron.