Last active
May 11, 2020 10:08
-
-
Save kolharsam/44abafe3e514cdf6df97ee979c7935b6 to your computer and use it in GitHub Desktop.
Cassidy's Interview Question - 10/5/20
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
;; Simple to implement I guess the real problem is of double/float precision | |
;; Will be updating once I learn more about those concepts within Clojure | |
(defn is-in-golden-ratio? | |
"Returns true if the pair of numbers are in the golden ratio" | |
[x y] | |
(let [x-y-ratio (quot x y) | |
greatest (max x y) | |
sum-ratio (quot (+ x y) greatest)] | |
(= x-y-ratio sum-ratio))) | |
(is-in-golden-ratio? 2 5) | |
;; => false | |
(is-in-golden-ratio? 1 0.618) | |
;; true | |
(is-in-golden-ratio? 61.77 38.22) | |
;; true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment