Last active
August 29, 2015 13:58
-
-
Save pbalduino/9955857 to your computer and use it in GitHub Desktop.
Equação quadrática do jeito verboso
This file contains hidden or 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
| ;; Uma equação de segundo grau segue a forma ax² + bx + c | |
| ;; Então, em x² - x - 2c = 0 teríamos | |
| ;; a = 1 | |
| ;; b = -1 | |
| ;; c = -2 | |
| ;; Então vamos invocar a função com (bhaskara 1 -1 2) | |
| ;; e vamos receber um array com os valores possiveis de x | |
| (defn bhaskara [a b c] | |
| [(/ (+ (- b) (Math/sqrt (- (* b b) (* 4 a c)))) (* 2 a)) | |
| (/ (- (- b) (Math/sqrt (- (* b b) (* 4 a c)))) (* 2 a))]) | |
| (bhaskara 1 -1 -2) | |
| ; [2.0, -1.0] | |
| ;; A ideia aqui é mostrar um código simples, mas com um visual intimidador, | |
| ;; para demonstrar como é possível melhorar o código sem esforço |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment