Skip to content

Instantly share code, notes, and snippets.

@danielmcgrath
Created November 30, 2011 03:51
Show Gist options
  • Save danielmcgrath/1407930 to your computer and use it in GitHub Desktop.
Save danielmcgrath/1407930 to your computer and use it in GitHub Desktop.
Calculate a quarterback rating with clojure
(defn force-range
"Forces a number into the allowed range. 0 - 2.375"
[i]
(cond
(< i 0) 0
(> i 2.375) 2.375
:else i))
(defn calculate-rating
"Returns the QB Rating based on the stats entered"
[att com yds tds picks]
(let [ a (force-range (* (- (* (/ com att) 100) 30) 0.05))
b (force-range (* (- (/ yds att) 3) 0.25))
c (force-range (* (/ tds att) 20))
d (force-range (- 2.375 (* (/ picks att) 25))) ]
(* (/ (+ a b c d) 6) 100)))
(println "Passes attempted: ")
(def att (Float/parseFloat(read-line)))
(println "Passes completed: ")
(def com (Float/parseFloat(read-line)))
(println "Passing yards: ")
(def yds (Float/parseFloat(read-line)))
(println "Touchdown passes: ")
(def tds (Float/parseFloat(read-line)))
(println "Interceptions: ")
(def picks (Float/parseFloat(read-line)))
(println (format "%.1f" (calculate-rating att com yds tds picks)))
@ryanmcgrath
Copy link

Haha, this is nice. What made you do it in Clojure?

@danielmcgrath
Copy link
Author

Doing a project or two in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment