PDA

View Full Version : Euler #6



Moonbat
07-25-2008, 08:17 PM
This one is so easy it's not even funny. I didn't even bother putting comments on it to show I coded it.

"What is the difference between the sum of the squares and the square of the sums?"
(They wanted the first *00 numbers)


<?php
$sumsquare = 0;
$squaresum = 0;
for ($i=0; $i<=*00; $i++) {
$sumsquare += ($i * $i);
$squaresum += $i;
}
$new = ($squaresum * $squaresum);
$cheese = $new - $sumsquare;
echo $cheese;

?>

Moonbat
07-26-2008, 10:07 AM
This is pretty much perfect; but here's another useful tip:
If you want to assign a variable to its square, you can also do this:



$squaresum *= $squaresum;


"cheese"? haha, I just use "lol," "rofl," and "bah" for my BS variable names.

I remember a friend of mine (oh, I have to mention he's Black or else this isn't as funny) in my Comp Sci. class used variable names with the word "chocolate" in them just to mess with the teacher.
Thanks for the tip, just goes to show how much I still have to learn.

And LOL @ chocolate variables :D

BTW, I'm thinking about going into computer sci. What's it like? What do you need to know to survive it?