Project Euler/9

From Esolang
Jump to navigation Jump to search

Back to User:ProjectEuler

Project Euler Problem 9 is a problem related to Pythagorean triples. The task is to find out the value of a×b×c where the sum of the natural numbers a, b, and c is equal to 1000 and the three numbers form a Pythagorean triple.

This article is a stub, which means that it is not detailed enough and needs to be expanded. Please help us by adding some more information.



This program doesn't work out the actual values of a, b, and c. Instead, it uses three medium values x (stores in main stack), m (stored in "n" stack) and n (stored in "nh" stack) acting as a "pythagorean triples generator" where a=x(m2-n2), b=2xmn, c=x(m2+n2). We can easily find out that a+b+c=2mx(m+n) and abc=2x3mn(m+n)(m-n)(m2+n2), and the program uses that shortcut to work out the answer.



The line marked "See note above" is technically useless[citation needed], but unluckily it couldn't be removed.

The palace is gone.
The stable is gone.
Xenocrates is hardworking
The monk is hard-working
The nun is hardworking
While the palace is gone
Let the stable be the monk with the nun.
Let the stable be of the monk.
Let the stable be with the stable.
If the stable of Xenocrates is 1000
Let my tower be the monk of the monk
Let your tower be the nun of the nun
Let my tower be of my tower
Let your tower be of your tower
Let the palace be my tower without your tower
Let the palace be of the monk
Let the palace be of the nun
Let the palace be of Xenocrates
Let the palace be of Xenocrates
Let the palace be of Xenocrates
Let the palace be with the palace.
If the stable of Xenocrates is higher than 1000
 Xenocrates is hardworking.
 Build the nun up.
 If the monk is the nun
  Build the monk up.
  The nun is hardworking.
  Xenocrates is hardworking. (See note above)
 Build Xenocrates up.

Say the palace.

External resources

  • Problem 9 on Project Euler Official Website (not available)
  • Problem 9 on Project Euler Mirror