Alle Herausforderungen
Mittel 0 gelöst 0% Erfolgsquote

Find Right-Triangle Triples

List all integer right triangles with a specified perimeter.

Find every triple of positive integers a < b < c for which a² + b² = c² and a + b + c = perimeter. Return each triple as [a, b, c], ordered by increasing a and then b. Do not include permutations of the same sides.

Implement pythagorean_triplets(perimeter).

Input

perimeter: The required sum of all three sides.

Output

Return a list of triples in the specified order.

Einschränkungen

3 ≤ perimeter ≤ 100,000. Return an empty list if no triangle qualifies.

Beispiele

Beispiel 1
Eingabe:
perimeter = 30

Erwartete Ausgabe:
expected = [
    [5, 12, 13]
]
Eingabe:
long long perimeter = 30;

Erwartete Ausgabe:
std::vector<std::vector<long long>> expected = {
    {5, 12, 13}
};
Eingabe:
long perimeter = 30;

Erwartete Ausgabe:
long[][] expected = new long[][] {
    new long[] {5, 12, 13}
};

Erläuterung

5 + 12 + 13 = 30 and 5² + 12² = 13². This is the only qualifying triple.

Beispiel 2
Eingabe:
perimeter = 11

Erwartete Ausgabe:
expected = []
Eingabe:
long long perimeter = 11;

Erwartete Ausgabe:
std::vector<std::vector<long long>> expected = {};
Eingabe:
long perimeter = 11;

Erwartete Ausgabe:
long[][] expected = new long[][] {};

Erläuterung

No increasing positive integer right-triangle triple sums to 11.

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.