Last active
August 3, 2017 09:06
-
-
Save gpittau/329122c8f65ab010a927f6657ebba668 to your computer and use it in GitHub Desktop.
10.000 dice Game
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
//take 1 | |
let faceValue = (face, count) => { | |
let simples = {1:100, 2:0, 3:0, 4:0, 5:50, 6:0} | |
let triples = {1:1000, 2:200, 3:300, 4:400, 5:500, 6:600} | |
let hasTriple = count >= 3 | |
let simplesCount = hasTriple ? count - 3 : count | |
let triplesCount = hasTriple ? 1 : 0 | |
return (triplesCount * triples[face]) + (simplesCount * simples[face]) | |
} | |
let countFaces = _.countBy(_.identity) | |
let aggregateScore = (result, [face, count]) => result + faceValue(face, count) | |
let score = roll => _.reduce(aggregateScore, 0)(_.toPairs(countFaces(roll))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment