Created
November 30, 2011 03:51
-
-
Save danielmcgrath/1407930 to your computer and use it in GitHub Desktop.
Calculate a quarterback rating with clojure
This file contains 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
(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))) |
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
Haha, this is nice. What made you do it in Clojure?