Skip to content

Instantly share code, notes, and snippets.

@kolharsam
Last active May 11, 2020 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolharsam/44abafe3e514cdf6df97ee979c7935b6 to your computer and use it in GitHub Desktop.
Save kolharsam/44abafe3e514cdf6df97ee979c7935b6 to your computer and use it in GitHub Desktop.
Cassidy's Interview Question - 10/5/20
;; 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