Tracks
/
MIPS Assembly
MIPS Assembly
/
Exercises
/
Pythagorean Triplet
Pythagorean Triplet

Pythagorean Triplet

Hard

Instructions

A Pythagorean triplet is a set of three natural numbers, {a, b, c}, for which,

a² + b² = c²

and such that,

a < b < c

For example,

3² + 4² = 5².

Given an input integer N, find all Pythagorean triplets for which a + b + c = N.

For example, with N = 1000, there is exactly one Pythagorean triplet for which a + b + c = 1000: {200, 375, 425}.

Registers

Register Usage Type Description
$a0 input integer N, sum of sides of triangle
$a1 input/output address a values
$a2 input/output address b values
$a3 input/output address c values
$v0 output integer number of triplets
$t0-9 temporary any for temporary storage
Edit via GitHub The link opens in a new window or tab
MIPS Assembly Exercism

Ready to start Pythagorean Triplet?

Sign up to Exercism to learn and master MIPS Assembly with 53 exercises, and real human mentoring, all for free.