hobbit monitor
+ Reply to Thread
Results 1 to 2 of 2

Thread: Euler #6

  1. #1
    Join Date
    Sep 2006
    Posts
    1,649

    Euler #6

    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]<?php
    $sumsquare = 0;
    $squaresum = 0;
    for ($i=0; $i<=*00; $i++) {
    $sumsquare += ($i * $i);
    $squaresum += $i;
    }
    $new = ($squaresum * $squaresum);
    $cheese = $new - $sumsquare;
    echo $cheese;

    ?>[/PHP]
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

  2. #2
    Join Date
    Sep 2006
    Posts
    1,649
    Quote Originally Posted by DANIEL2488 View Post
    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:

    [PHP]
    $squaresum *= $squaresum;
    [/PHP]

    "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

    BTW, I'm thinking about going into computer sci. What's it like? What do you need to know to survive it?
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

+ Reply to Thread

Similar Threads

  1. [PHP] Solving Euler Project #2
    By Moonbat in forum Programming
    Replies: 1
    Last Post: 07-24-2008, 05:36 PM
  2. PHP - Euler #5 Problems :(
    By Moonbat in forum Programming
    Replies: 3
    Last Post: 07-18-2008, 02:06 PM
  3. [PHP] Solving Euler Project #*
    By Moonbat in forum Programming
    Replies: 1
    Last Post: 07-13-2008, 05:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts