Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6176119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:02:34+00:00 2026-05-24T00:02:34+00:00

Im trying to solve Euler’s Project 9 using PHP. Im pretty sure my logic

  • 0

Im trying to solve Euler’s Project 9 using PHP. Im pretty sure my logic is fine, but my double for-loop only goes through the first loop, completes the second loop and stops. Any1 knows what Im doing wrong? I want to do the first one 998 times and the second one 998 times. ( NB: I know that I can optimize the code because I $ will never be higher then 331 due to a

//
//A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
//a² + b² = c²
//
//For example, 3² + 4² = 9 + 16 = 25 = 5².
//
//There exists exactly one Pythagorean triplet for which a + b + c = 1000.
//Find the product abc.

$na = array();
$a=1;
$b=1;
$c=0;
$z=998;//upper bound
for($a;$a<$z;$a++){
    for($b;$b<$z;$b++){
        $c=(1000-$a)-$b;
        if(($a*$a)+($b*$b)==($c*$c))
            echo "played: $a + $b + $c = 1000<br />";
    }
}

Result is (When I comment the if out) :
played: 1 + 1 + 998 = 1000
to
played: 1 + 997 + 2 = 1000

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:02:35+00:00Added an answer on May 24, 2026 at 12:02 am

    Your variable $b is never reset so it will always be equal to $z after the first time in the inner loop.
    What you need is
    ...
    for($b = 1; $b < $z; $b++) {
    ...

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to solve Q10 from Project Euler. I am using JavaScript and
I am trying to solve Project Euler problem #12: The sequence of triangle numbers
I'm trying to solve questions from Project Euler in Ruby one-liners, and I'm curious
I'm trying to solve the 8th problem of the project Euler and I'm stuck
I've been trying to solve these problem for last two hours but seems like
I am trying to solve this problem in Haskell but getting time limit exceed.
I'm trying to solve the following problem: I'm analyzing an image and I obtain
I have been trying to solve this problem for hours (searched here as well
Overview: I am trying to implement the Johnson Trotter Algorithm in Java so that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.