473,698 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using a triple-nested for...next loop

I have to write a program to find all Pythagorean triples for a right
triangle. I know that the squares of two sides of the triangle must equal
the square of the third (longest) side. However, I am not sure how to use a
triple-nested for...next loop to try all possibilities.

For instance, take a look at these numbers:

a 3 5 7 8 9 11
b 4 12 24 15 40 60
c 5 13 25 17 41 61

Notice that in each case "a" squared plus "b" squared is equal to the sum of
c squared. My program has to compute such a table by iterating through
several combinations of numbers to locate ones that meet this criteria.

Any suggestions would be helpful.
Oct 18 '06 #1
5 5230
Is this a homework/school assignment?

Anyways, there are an infinite number of Pythagorean triples, so what
other information can you provide us? i.e. Are you given a value for
one of the sides? Any of the angles of the triangle (other than the 90
degree)? Or any other useful information?

Thanks,

Seth Rowe
Candace wrote:
I have to write a program to find all Pythagorean triples for a right
triangle. I know that the squares of two sides of the triangle must equal
the square of the third (longest) side. However, I am not sure how to use a
triple-nested for...next loop to try all possibilities.

For instance, take a look at these numbers:

a 3 5 7 8 9 11
b 4 12 24 15 40 60
c 5 13 25 17 41 61

Notice that in each case "a" squared plus "b" squared is equal to the sum of
c squared. My program has to compute such a table by iterating through
several combinations of numbers to locate ones that meet this criteria.

Any suggestions would be helpful.
Oct 18 '06 #2
This is for a class. I have to write the program to find all Pythagorean
triples for side1, side2 and hypotenuse, none larger than 30. And I have been
instructed to use a triple-nested For...Next loop that tries all
possibilities.

"rowe_newsgroup s" wrote:
Is this a homework/school assignment?

Anyways, there are an infinite number of Pythagorean triples, so what
other information can you provide us? i.e. Are you given a value for
one of the sides? Any of the angles of the triangle (other than the 90
degree)? Or any other useful information?

Thanks,

Seth Rowe
Candace wrote:
I have to write a program to find all Pythagorean triples for a right
triangle. I know that the squares of two sides of the triangle must equal
the square of the third (longest) side. However, I am not sure how to use a
triple-nested for...next loop to try all possibilities.

For instance, take a look at these numbers:

a 3 5 7 8 9 11
b 4 12 24 15 40 60
c 5 13 25 17 41 61

Notice that in each case "a" squared plus "b" squared is equal to the sum of
c squared. My program has to compute such a table by iterating through
several combinations of numbers to locate ones that meet this criteria.

Any suggestions would be helpful.

Oct 18 '06 #3
I suggest a strategy. Do not know if it's the best.

.Make a long list L (hashtable) of squared numbers.
For each choice of one squared number q in L ( 2,4,9, .. )

iterate all the squared numbers p less than sqrt(q),
and any time r = (q - p) is in the list L add the triple (q, p, r).

Let me know if makes sense...
-P

Candace ha scritto:
I have to write a program to find all Pythagorean triples for a right
triangle. I know that the squares of two sides of the triangle must equal
the square of the third (longest) side. However, I am not sure how to use a
triple-nested for...next loop to try all possibilities.

For instance, take a look at these numbers:

a 3 5 7 8 9 11
b 4 12 24 15 40 60
c 5 13 25 17 41 61

Notice that in each case "a" squared plus "b" squared is equal to the sum of
c squared. My program has to compute such a table by iterating through
several combinations of numbers to locate ones that meet this criteria.

Any suggestions would be helpful.
Oct 18 '06 #4
Well then, since this is for a class, I won't help you cheat yourself
out of a learning experience. Struggling through a problem now will
help you in the future, as you will learn good problem solving skills
(that don't include quering newsgroups) that apply to more than just
programming. Just try to simplify the problem and take it one step at a
time...

Thanks,

Seth Rowe
Candace wrote:
This is for a class. I have to write the program to find all Pythagorean
triples for side1, side2 and hypotenuse, none larger than 30. And I have been
instructed to use a triple-nested For...Next loop that tries all
possibilities.

"rowe_newsgroup s" wrote:
Is this a homework/school assignment?

Anyways, there are an infinite number of Pythagorean triples, so what
other information can you provide us? i.e. Are you given a value for
one of the sides? Any of the angles of the triangle (other than the 90
degree)? Or any other useful information?

Thanks,

Seth Rowe
Candace wrote:
I have to write a program to find all Pythagorean triples for a right
triangle. I know that the squares of two sides of the triangle must equal
the square of the third (longest) side. However, I am not sure how to use a
triple-nested for...next loop to try all possibilities.
>
For instance, take a look at these numbers:
>
a 3 5 7 8 9 11
b 4 12 24 15 40 60
c 5 13 25 17 41 61
>
Notice that in each case "a" squared plus "b" squared is equal to the sum of
c squared. My program has to compute such a table by iterating through
several combinations of numbers to locate ones that meet this criteria.
>
Any suggestions would be helpful.
Oct 18 '06 #5
I was not looking for the answers, just direction. Thanks to those of you who
responded to this message with direction.

"rowe_newsgroup s" wrote:
Well then, since this is for a class, I won't help you cheat yourself
out of a learning experience. Struggling through a problem now will
help you in the future, as you will learn good problem solving skills
(that don't include quering newsgroups) that apply to more than just
programming. Just try to simplify the problem and take it one step at a
time...

Thanks,

Seth Rowe
Candace wrote:
This is for a class. I have to write the program to find all Pythagorean
triples for side1, side2 and hypotenuse, none larger than 30. And I have been
instructed to use a triple-nested For...Next loop that tries all
possibilities.

"rowe_newsgroup s" wrote:
Is this a homework/school assignment?
>
Anyways, there are an infinite number of Pythagorean triples, so what
other information can you provide us? i.e. Are you given a value for
one of the sides? Any of the angles of the triangle (other than the 90
degree)? Or any other useful information?
>
Thanks,
>
Seth Rowe
>
>
Candace wrote:
I have to write a program to find all Pythagorean triples for a right
triangle. I know that the squares of two sides of the triangle must equal
the square of the third (longest) side. However, I am not sure how to use a
triple-nested for...next loop to try all possibilities.

For instance, take a look at these numbers:

a 3 5 7 8 9 11
b 4 12 24 15 40 60
c 5 13 25 17 41 61

Notice that in each case "a" squared plus "b" squared is equal to the sum of
c squared. My program has to compute such a table by iterating through
several combinations of numbers to locate ones that meet this criteria.

Any suggestions would be helpful.
>
>

Oct 18 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
95881
by: S Manohar | last post by:
I need to pass a 'reference' to a double value to a function which changes that value. Each time the function is called, it needs to change different sets of values. In C I'd simply pass references. void add(double *a1, double *a2, double *a3){ *a1 = *a2 + *a3; *a2 = *a1 + *a3; } In Java, one solution would be to create a class to represent a
3
1980
by: Anthony Roberts | last post by:
property = re.compile("""(?P<name>+)="(?P<value>.*?)""""re.I) This doesn't work because the closing quote in my regex forms the first quote of a triple quote to end the string... property = re.compile("""(?P<name>+)=("(?P<value>.*?)")""", re.I) This mucks up stuff I want to do later. I've thought about it for a while, and except for changing it to a
1
2390
by: Edward C. Jones | last post by:
On 2003-09-04, Rasmus Fogh said: > I need a way of writing strings or arbitrary Python code that will > > a) allow the strings to be read again unchanged (like repr) > b) write multiline strings as multiline strings instead of escaping > the \n's. > > A repr function that output triple-quoted strings with explicit > (non-escaped) linebreaks would be perfect.
8
3230
by: Christoph Zwerschke | last post by:
I sometimes use triple quotes in order to produce snippets of multiline code, like that: if output == html: snip = '''<html> <head><title>Hello, World</title></head> <body bgcolor="aqua"><h1>What's up?</h1> </html>''' else: snip = 'Hello!'
11
2055
by: bearophile | last post by:
Hello, here are a four more questions (or suggestions) for the language (probably people have already discussed some of/all such things: I've seen the contracts for Python: http://www.wayforward.net/pycontract/ http://www.python.org/peps/pep-0316.html They look interesting and nice, how Python developers feel about accepting something like this in the standard language? (Maybe they are a bit complex).
7
3974
by: Brian van den Broek | last post by:
Hi all, I'm posting partly so my problem and solution might be more easily found by google, and partly out of mere curiosity. I've just spent a frustrating bit of time figuring out why pydoc didn't extract a description from my module docstrings. Even though I had a well formed docstring (one line, followed by a blank line, followed by the rest of the docstring), when I ran Module docs, my modules showed up as having "no description"....
3
1247
by: jd | last post by:
The following code illustrates a problem I have been trying to get around in c++. Can anyone explain how I can get this to work. The code compiles fine if I leave out the lines with the comments after them. Tnaks in advance for any help. jd //file test.cpp: #include "pair.h" #include "triple.h"
14
6105
by: dmh2000 | last post by:
I recently complained elsewhere that Python doesn't have multiline comments. i was told to use triple quoted strings to make multiline comments. My question is that since a triple quoted string is actually a language construct, does it use cause a runtime construction of a string which is then discarded, or is the runtime smart enough to see that it isn't used and so it doesn't construct it? example def fun(self):
8
4271
by: Lawrence D'Oliveiro | last post by:
If triple-quoted strings had the Python-nature, then they would take indentation into account. Thus: """this is a multi-line string.""" would be equivalent to
2
2465
gchq
by: gchq | last post by:
Hi there There is no problem encypting and decrypting a credit card number, but whilst encrypting the expiry date seems to work it blows out on decryption with "Invalid length for a Base-64 char array" Any ideas? Here is the code - the keys are generated from a 40+ string held on another database (ReturnKey).... Private Function IV_192()
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9026
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4366
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2328
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.