Greed is a dice game played with five six-sided dice. Using an array containing five six-sided dice values, write a function that will score a throw according to the following rules:
Three 1's => 1000 points
Three 6's => 600 points
Three 5's => 500 points
Three 4's => 400 points
Three 3's => 300 points
Three 2's => 200 points
One 1 => 100 points
One 5 => 50 point
A single die can only be counted once in each roll. For example, a "5" can only count as part of a triplet (contributing to the 500 points) or alone (as 50 points), but not both in the same roll.
Example Scoring
5 1 3 4 1 => 50 + 2 * 100 = 250
1 1 1 3 1 => 1000 + 100 = 1100
2 4 4 5 4 => 400 + 50 = 450
You can try to fill the array with random values. If you have extra time, you can also try to keep track of the player's score over several throws.
This challenge comes from user JulianNicholls. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (18)
its pretty? no... but it works
Very understandable and faster! 👍
Thanks Peter 😃
Perl
JS implementation keeping the rules as data
Keep the rules as data is the way to go. 🔥🔥🔥
ruby <3
Easy peasy, lemon squeezy
(language: Elixir)
A super gross unreadable solution but fun none the less 😂
Here is my simple solution with Python:
Python
JavaScript
Live demo on CodePen.
C#
Repl.it