Created
September 4, 2017 00:20
-
-
Save jeyziel/840c8207e2cc6159ead118bd6b90a291 to your computer and use it in GitHub Desktop.
Teorema de pitagoras
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const inverse = ( x ) => x *- 1 | |
const add = ( y ) => ( x ) => x + y | |
const substract = ( y ) => ( x ) => add( inverse( y ) )( x ) | |
const root = ( y ) => ( x ) => Math.pow( x , 1/y) | |
const squareRoot = root( 2 ) | |
const multiply = ( y ) => ( x ) => { | |
let result = 0 | |
const addX = add( x ) | |
const decrement1 = substract( 1 ) | |
while ( y > 0 ) { | |
result = addX( result ) | |
y = decrement1( y ) | |
} | |
return result | |
} | |
const pow = ( y ) => ( x ) => { | |
let result = 1; | |
while ( y > 0 ) { | |
result = multiply( result )( x ) | |
y = substract(1)(y) | |
} | |
return result | |
} | |
const square = pow(2) | |
const teoremaDePitagoras = ( b, c ) => { | |
const a = add( pow(2)( b ) )( pow(2)( c ) ) | |
//const a = add( square( b ) )( square(c) ) | |
return squareRoot(a) | |
} | |
console.log( teoremaDePitagoras( 9, 12)); // 15 | |
console.log( square( 9 ) ) //81 | |
console.log( square( 2 ) ) // 1 ??? | |
//poderia me explicar pq isso está acontecendo? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment