36
2
A common visual explanation of the Pythagorean theorem is as such:
The squares are meant to represent the side length's squared, and the areas of a + b = c
, just like the Pythagorean theorem says.
This part is what you have to show.
Your task
- You will get two integers as input, meant to represent sides
a
andb
of a right triangle (ex.3, 4
). - You will then make squares out of the lengths
a
,b
, andc
out of the#
character. For example here is 3:
###
###
###
- You will then format these into a math equation that explains the particular Pythagorean triplet:
#####
#### #####
### #### #####
### #### #####
### + #### = #####
- Notice how the
=
and+
signs have spaces on both sides and how everything is on the bottom. - You will never get values for
a
andb
that makec
non-integral. - This is code-golf so shortest code in bytes wins!
Test Cases
(more coming once I have time, these are really hard to make by hand)
3, 4
#####
#### #####
### #### #####
### #### #####
### + #### = #####
6, 8
##########
##########
######## ##########
######## ##########
###### ######## ##########
###### ######## ##########
###### ######## ##########
###### ######## ##########
###### ######## ##########
###### + ######## = ##########
4, 3
#####
#### #####
#### ### #####
#### ### #####
#### + ### = #####
5, 12
#############
############ #############
############ #############
############ #############
############ #############
############ #############
############ #############
############ #############
##### ############ #############
##### ############ #############
##### ############ #############
##### ############ #############
##### + ############ = #############
What about inputs where the third number would not be an integer? For example, given inputs of 1 and 1, the third side would be sqrt(2). – bmarks – 2015-08-31T21:15:20.133
3@bmarks "You will never get values for a and b that make c non-integral." – Maltysen – 2015-08-31T21:15:40.443
Is
b
going to always be larger thana
? – Downgoat – 2015-08-31T22:30:18.247@vihan nope, adding that to the tests – Maltysen – 2015-08-31T22:38:19.897
a + b = c
? I don't think that was the result Pythagoras came up with... – Reto Koradi – 2015-08-31T22:57:15.3502@RetoKoradi well the areas of the squares
a+b=c
– Maltysen – 2015-08-31T22:58:38.9671If
a
,b
andc
are defined as the areas of the squares, then the examples are incorrect. – Reto Koradi – 2015-08-31T23:01:21.8332You should add another nice test case, like 5 + 12 = 13. – mbomb007 – 2015-09-01T00:33:28.453
@mbomb007 I will now that I have my reference solution, yayyy ^.^ – Maltysen – 2015-09-01T00:45:04.427
7Note: this is not "a visual explanation of the Pythagorean theorem". This is the Pythagorean theorem. It was originally formulated exactly this way: geometrically. They didn't even know about square roots, even more interesting, Pythagoras himself didn't believe in the existence of irrational numbers. This means Pythagoras thought that sqrt(2) can be exactly represented by the division of two finite integers. The original theorem is what we now call the "visual representation" – vsz – 2015-09-01T21:07:50.783
1@vsz Actually, based on my understanding - the Pythagoreans would have realized that there are no integers whose ratio is sqrt(2). From this, they would have concluded that sqrt(2) does not exist. In other words, they would have thought it is impossible to draw a line of length sqrt(2). The Pythagorean theorem apparently caused problems, because they knew how to construct a right triangle with sides 1,1,x. The Pythagorean theorem showed that x=sqrt(2) actually exists. Legend has it they drowned the person who discovered this and then swore everyone to secrecy. – Joel – 2015-09-02T04:23:14.100
Can we use a different character instead of
#
? What about leading/trailing whitespace? – Jo King – 2019-01-16T01:21:22.117