Skip to content

Instantly share code, notes, and snippets.

@Lambdanaut
Created July 22, 2011 20:25
Show Gist options
  • Save Lambdanaut/1100351 to your computer and use it in GitHub Desktop.
Save Lambdanaut/1100351 to your computer and use it in GitHub Desktop.
A snippet for calculating a Grade Point Average based on letter grades
;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 ) )
@johnlettman-old
Copy link

Oh boy I love this!

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