Created
July 22, 2011 20:25
-
-
Save Lambdanaut/1100351 to your computer and use it in GitHub Desktop.
A snippet for calculating a Grade Point Average based on letter grades
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
;A list of your grades. Change this to reflect your grades and run the program. | |
( def grades '(\a \b \c \d \f \d \c \b \a) ) | |
;Function for mapping grades to numbers and then averaging them. | |
( def gpaList '{\a 4, \b 3, \c 2, \d 1, \f 0} ) | |
( defn gpa [grades] (double (/ ( reduce + (map (fn [x] (get gpaList x)) grades ) ) (count grades) ) ) ) | |
;Prints out your GPA | |
( println (gpa grades ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh boy I love this!