Oct. 13th, 2009

demonicgerbil: (Default)
I just read the plot synopsis for the last two Dune books, which are sequels to the main series of books. It sounds like horrible fanfic. Not that the last real Dune books weren't horrible fanfic bordering on pornography... but... ... I don't remember what my point was.

I'm kind of glad I haven't read Sandworms of Dune and the other book... but now morbid curiosity is getting the better of me.
demonicgerbil: (Default)
Project Euler has neat problems to solve, and in the hopes of making myself a little better at programming and thinking about how to structure programs, I've decided to try wading into doing the problems. In FORTRAN, of course, because I'm a sick, sick person that enjoys hurting his brain.

Problem 1: http://projecteuler.net/index.php?section=problems&id=1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

My FORTRAN code is behind the cut.

Read more... )

The idea was "Let's add up all the multiples of 3, and all the multiples of 5." But of course then all the multiples of both get double counted. So the cycle command in the first If statement kicks the code back to the top of the loop, so we never check if a multiple of 3 is also a multiple of 5.

I knew the answer to this analytically because summing up a series is a well known mathematical formula, but I decided to write a little code to do it and see if I could avoid the double counting problem without simply subtracting a series consisting of the multiples of 15 from the final answer.

Good warm up problem. The only trouble I had was originally my loop went from 1 to 1000 instead of 1 to 999, because I misread the problem statement as including 1000. This led to some hair-pulling.
demonicgerbil: (Default)
http://projecteuler.net/index.php?section=problems&id=2

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Find the sum of all the even-valued terms in the sequence which do not exceed four million.

My solution is behind the cut. In FORTRAN, of course.

Read more... )

Not having an easy way in FORTRAN (that I know of, anyway) to see if one number cleanly divides another, I had to implement a kludge to solve this problem. First I have two temporary variables, one is a real and the other an integer. To test if something is even or not, I divide by 2. I do this once with the real, and once with the integer. Integer math in FORTRAN of course always returns a number without any decimals. So "tempint = FibTemp/2" always returns some nice round number. Doing real number math with "tempreal = FibTemp/2.0" will return either a round number with a lot of trailing .0000's or some number like 2.5. Fortunately the conditional doesn't care if it's comparing a REAL or an INT together, unlike more advanced languages where types are a big issue, so it says that "2" and "2.0000000000" are the same number. So therefore if these two temporary variables are equal, then our Fibonacci number is an even number.

I'm not going to go into the wonders of Fibonacci numbers here, but suffice it to say that they're pretty cool and actually sometimes important in Mathematics, Geometry, and Architecture. The Wikipedia page on Fibonacci numbers is a fairly nice introduction to the topic.
demonicgerbil: (Default)
http://www.gog.com/en/gamecard/might_and_magic_6_limited_edition

Tons of dungeon crawling gameplay. 10 bucks.

If I had the time for that, I'd be all over it.