Created
April 3, 2014 21:37
-
-
Save pbalduino/9963401 to your computer and use it in GitHub Desktop.
bhaskara 3
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] | |
| (let [menos-b (- b) | |
| b-quadrado (* b b) | |
| delta (Math/sqrt (- b-quadrado (* 4 a c))) | |
| denominador (* 2 a) | |
| x1 (-> menos-b | |
| (+ delta) | |
| (/ denominador)) | |
| x2 (-> menos-b | |
| (- delta) | |
| (/ denominador))] | |
| [x1 x2])) | |
| (bhaskara 1 -1 -2) | |
| ; [2.0, -1.0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment