Questions tagged [pythagorean]

Refers to the famous Pythagorean theorem. It states that for a right angle, the square of the length of the two legs `a,b` is equal to the square of the length of the hypotenuse `c`. The equation is therefore `a*a + b*b = c*c` This tag is used for anything involving the Pythagorean theorem.

The Pythagorean Theorem is an important and commonly-occuring theorem in Euclidean geometry regarding right triangles. It states that given a right triangle, the square of the length of the two legs (which make a right angle) a,b is exactly equal to the square of the length of the hypotenuse (Longest side, opposite to the right angle)c.

The equation is therefore stated as:

  • c^2 = a^2 + b^2
  • c = sqrt(a^2 + b^2)
  • where ^ is exponentiation.

The Pythagorean Theorem has extremely broad applications in mathematics, engineering, and computer science. It can be used to calculate the distance between two points in Euclidean space. Notably, the Pythagorean trigonomic identity states that

  • sin^2(x) + cos^2(x) == 1 for all real x.

A Pythagorean Triple is a triple of integers (a, b, c) such a^2 + b^2 == c^2. The smallest pythagorean triple is (3, 4, 5) as 9 + 16 == 25.

Wikipedia page about the Pythagorean Theorem

128 questions
31
votes
17 answers

Find Pythagorean triplet for which a + b + c = 1000

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. Source:…
r18ul
  • 1,082
  • 2
  • 12
  • 30
12
votes
3 answers

Having trouble understanding list comprehensions

I've just started learning haskell(literally, tonight!) and I'm having a little trouble understanding the logic of list comprehensions, more specifically the <- operator. A little example on Learn You Some Haskell Finds all tuples that have a length…
Syntactic Fructose
  • 18,936
  • 23
  • 91
  • 177
8
votes
5 answers

Shortest path between raw geo coordinates and a node of a graph

I have implemented a simple Dijkstra's algorithm for finding the shortest path on an .osm map with Java. The pathfinding in a graph which is created from an .osm file works pretty well. But in case the user's current location and/or destination is…
Kirill
  • 867
  • 2
  • 11
  • 14
7
votes
5 answers

Efficiently calculating all pythagorean triples knowing the hypoteneuse

Given a hypoteneuse (c in the typical equation a*a + b*b = c*c), what is an efficient way to calculate all possible integer values of a and b, such that a < b? Note: I've seen c be greater than 1e12, thus c*c is greater than long.MaxValue, from what…
ckknight
  • 5,953
  • 4
  • 26
  • 23
6
votes
2 answers

Project Euler #9 (Pythagorean triplets) in Clojure

My answer to this problem feels too much like these solutions in C. Does anyone have any advice to make this more lispy? (use 'clojure.test) (:import 'java.lang.Math) (with-test (defn find-triplet-product ([target] (find-triplet-product 1 1…
dbyrne
  • 59,111
  • 13
  • 86
  • 103
5
votes
4 answers

Arrays vs. lists in Lisp: Why are lists so much faster in the code below?

I got an unexpected result while solving Problem 75 in Project Euler. My code does find the correct solution, but it behaves strangely. My solution consists of traversing a Pythagorean tree (Barning's matrices) until the perimeter limit is reached,…
Paulo Mendes
  • 697
  • 5
  • 16
4
votes
2 answers

Prolog: pythagorean triple

I have this code that uses an upper bound variable N that is supposed to terminate for X and Y of the pythagorean triple. However it only freezes when it reaches the upper bound. Wasn't sure how to use the cut to stop the backtracking. Code…
RandellK02
  • 167
  • 1
  • 4
  • 17
3
votes
2 answers

Can't use specific values to calculate with different variables

I am getting an error which tells me I can't multiply two variables of a specific value. TypeError: can't multiply sequence by non-int of type 'str' I am trying to make a Pythagorean theorem inside of python for school. I need to have it inside of…
3
votes
1 answer

How to print the pythagorean triple with the largest hypotenuse

I have to find all the pythagorean triples which have a value of "c" (where c is the hypotenuse) smaller than an integer number entered by the user. I was able to do this, however I also have to print which triple has the largest value of "c". #…
the1whoknocks
  • 89
  • 1
  • 2
  • 6
2
votes
4 answers

Is there a better way to find ‘highly composite’ pythagorean triples in Python?

I’m trying to find ‘highly composite’ pythagorean triples - numbers (c) that have more than one unique a,b (in the naturals) that satisfy a² + b² = c². I’ve written a short python script to find these - it cycles through c in the range (0,1000), and…
dangerscott
  • 61
  • 2
  • 9
2
votes
2 answers

Specific right-angled Triangles are not being recognized as right-angled in Cpp

I have to take the coordinates of the vertices of a triangle from the user and tell if it is a right-angled triangle or not. I'm using Pythagoras Theorem to Find out i.e. h * h = b * b + p * p But surprisingly this doesn't work for some specific…
DaniyalAhmadSE
  • 807
  • 11
  • 20
2
votes
2 answers

Finding all the Pythagorean quadruples faster when a, b or c <= 1000

I'm trying to get all the Pythagorean quadruples: a^2 + b^2 + c^2 = d^2 when a, b, c <= 1000, My code generates all of them (85490) but it takes around 10 minutes. I am trying to reduce the execution time. How can I improve the execution time?. Any…
abhimanyue
  • 196
  • 1
  • 12
2
votes
1 answer

Python Primitive Pythagorean triple code not working

Currently trying to find all primitve pytagorean triples up to some number n, using the formula a = m^2-n^2, b = 2mn, c = m^2 + n^2. Here is the code: def prim(k): primlist=[] for m in range(1,k): for n in…
2
votes
3 answers

Does Java have the Pythagoras Theorem?

I use Java Swing to create simple games such as Pong and Air Hockey, and I often find myself using Pythagoras Theorem to calculate the distance between two points. Although it's not a pain to write (it can be reduced to a single line), I was…
John S.
  • 626
  • 1
  • 4
  • 16
2
votes
3 answers

Pythagorean Triples Calculation for Java

So I need help calculating Pythagorean Triples, basically I want the output to look like this: 3 4 5 5 12 13 6 8 10 7 24 25 ETC. I need help with the calculation portion and to ensure that I do not have duplicates (i.e. 5 12 13 and 12 5…
user3859018
  • 379
  • 1
  • 5
  • 14
1
2 3
8 9