Skip to content

Instantly share code, notes, and snippets.

@gpittau
Last active August 3, 2017 09:06
Show Gist options
  • Save gpittau/329122c8f65ab010a927f6657ebba668 to your computer and use it in GitHub Desktop.
Save gpittau/329122c8f65ab010a927f6657ebba668 to your computer and use it in GitHub Desktop.
10.000 dice Game
//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