Wednesday, May 28, 2014
Sunday, May 25, 2014
Saturday, May 24, 2014
Sqrt
Computers are wonderful. The following program implements the Newton-Raphson
algorithm for finding square roots. The idea of approximating one's way to a solution
dates back to the Babylonians.
This program uses the behaviour of 2, square root of four, as a template. All true
square roots will eventually hit 0 on the condition.
The marvel is, the computer will also give intermediate results, on request. Awesome!!
algorithm for finding square roots. The idea of approximating one's way to a solution
dates back to the Babylonians.
This program uses the behaviour of 2, square root of four, as a template. All true
square roots will eventually hit 0 on the condition.
The marvel is, the computer will also give intermediate results, on request. Awesome!!
Monday, May 19, 2014
Thursday, May 15, 2014
Pyramid-Builder
Starting the outside loop at row two does the trick for generating a pyramid
with two stars at the top. (And things are shifted to the right because I am running
the spaces first Inside the loop).
As for aligning my stars to the left-most corner, keeping the count to 1 less than the number
of stars will do it.
with two stars at the top. (And things are shifted to the right because I am running
the spaces first Inside the loop).
As for aligning my stars to the left-most corner, keeping the count to 1 less than the number
of stars will do it.
For a visual representation, see:
Wednesday, May 14, 2014
Tricky
The Mario assignment for JHarvard is trickier than the straight pyramid below. Clearly,
the top step has two tiles, so one will need to start the row count at two and end up
with n + 1 numbered rows.
But there is worse. The standard code in such matters ends up defining two independent
squares that slide over one another. The total space is not a square at all but a rectangle.
To justify left - as per the assignment - one needs to make the spaces loop loose a column.
Tricky!!
Friday, May 9, 2014
Thursday, May 8, 2014
Monday, May 5, 2014
Saturday, May 3, 2014
Subscribe to:
Posts (Atom)