# Evaluate a Dice 10,000 roll

## Introduction

Dice 10,000 is a dice game which can be played with 6 dice and something to write. Players roll the dice multiple times a turn and gain a score at the end of it. The player who reaches 10,000 point first wins the game. Calculating the score of one roll is your job in this challenge.
Look here for the full rules.
Please note that the rules (especically the scoring) change from region to region since the game is widely known. We use the rules descibed below.

## The Challenge

Given a list of six numbers from one to six representing a dice roll, output their score. The score is calculated in the follwing way:

• Ones counts 100 points
• Fives counts 50 points
• Triplets count their number times 100 points. Three twos for example give 200 points. An exception are three ones which count 1000 points.
• Six of the same number count like two triplets as described above. So six threes give 600 points. The same goes for the edge case with the ones: Six ones are 2,000 points.
• One die can't be used more than once. If a die is part of a triplet, it does not count for other scorings. The fives in a triplet do not count 50 points in addition to the 500 points they give.
• Triples are always counted first to maximize the score. So three fives are never counted as 150 points. Four fives are counted as one triplet and one ordinary five which then gives 550 points.

### Notes

• The input will always contain six numbers from one to six. You will not recieve invalid input.
• The numbers can be in any order. You may not assume any specific ordering.

# Rules

• Input format is up to you as long as it's not preprocessed.
• Function or full program allowed.
• Default rules for input/output.
• Standard loopholes apply.
• This is , so lowest byte-count wins. Tiebreaker is earlier submission.

# Test cases

[1, 2, 3, 4, 5, 6] -> 150
[1, 1, 1, 2, 3, 5] -> 1050
[1, 1, 1, 1, 1, 1] -> 2000
[2, 2, 2, 2, 2, 2] -> 400
[6, 6, 1, 5, 5, 6] -> 800
[2, 3, 4, 6, 2, 4] -> 0
[1, 5, 1, 5, 1, 5] -> 1500
[5, 5, 5, 5, 2, 3] -> 550
[1, 1, 1, 1, 1, 5] -> 1250
[3, 3, 4, 4, 3, 4] -> 700

• Also, die is the singular form of dice. – mbomb007 Aug 22 '16 at 17:40
• @ThreeFx "A dice" is still incorrect. See english.stackexchange.com/a/167107/125966 – mbomb007 Aug 22 '16 at 17:44
• @mbomb007 See this. – ThreeFx Aug 22 '16 at 17:46
• @mbomb007 In german its the same for singular and plural, why does english has to be so complicated? :P But thanks anyway, die sounds actually better :) – Denker Aug 22 '16 at 17:49
• @DenkerAffe ah but is it "Der dice", "Die dice" or "Das dice"? – Dave Aug 22 '16 at 19:15

# 05AB1E, 3431 30 bytes

7G¹N¢O3‰N*2LRN1Q+°*X5‚Nå_i¨}OO


Explanation

7G                                  # for N in 1..6
¹N¢O                              # count number of occurrences of N in input
3‰                            # divmod 3
N*                          # multiply by N
2LRN1Q+°*                 # multiply by 10, 100 or 1000
X5‚Nå_i¨}        # if N is not 1 or 5, scrap the singles
OO      # sum all triple and single scores so far
# implicitly display total sum


Try it online

# Python 2, 152148 125 bytes

Pretty simple solution. Can be golfed more. L.count is a bit long, but I couldn't remove the first call because L is updated.

def f(L):s=n=0;exec"n+=1\nwhile L.count(n)>2:s+=[n*100,1e3][n<2];exec'L.remove(n);'*3\n"*6;C=L.count;print s+100*C(1)+50*C(5)


Try it online - (all test cases)

Ungolfed:

def f(L,s=0):
L.sort()
for n in range(1,7):
while L.count(n)>2:
s+=n*100*((n<2)*9+1) # multiply by 10 if n==1
i=L.index(n)
L=L[:i]+L[i+3:]
s+=100*L.count(1)+50*L.count(5)
print s


Some golf credit to @Copper, using some tips from his code

## PowerShell v2+ v3+, 147144137 133 bytes

$n=$args[0]|sort;while($n){if(($x=$n[0])-eq$n[2]){$s+=100*$x+900*($x-eq1);$a,$b,$n=$n}else{$s+=50*($x-in1,5)+50*($x-eq1)}$a,$n=$n};$s


Crossed out 144 looks kinda like 144?

Takes input $args[0] and sorts it, stores it into $n. Then, while there are still elements left, we evaluate an if/else.

If the first element (temp stored into $x to save some bytes) matches the third element, we have a triple. Add onto the $sum the result of some multiplication 100*$x plus a Boolean-based 900 only if $x is -equal to 1. This gets us the requisite 1000 for three ones. Then, peel off the first two elements into $a, and $b, and the remaining into $n -- removing the third element of the triple is handled later. Otherwise, we don't have a triple, so add on to $sum the result of another Boolean-based addition. We add 50 if $x is either 1 or 5, then add on another 50 if it's -equal to 1. This section now requires v3+ for the -in operator. In either case, we still have an element yet to remove, so peel off the first element into $a and leave the remaining in $n. Finally, once the loop is done, place $s on the pipeline. Output is an implicit Write-Output at the end of execution.

### Test cases

PS C:\Tools\Scripts\golfing> (1,2,3,4,5,6),(1,1,1,2,3,5),(1,1,1,1,1,1),(2,2,2,2,2,2),(6,6,1,5,5,6),(2,3,4,6,2,4),(1,5,1,5,1,5),(5,5,5,5,2,3),(1,1,1,1,1,5),(3,3,4,4,3,4)|%{($_-join',')+" -> "+(.\evaluate-dice-1000.ps1$_)}
1,2,3,4,5,6 -> 150
1,1,1,2,3,5 -> 1050
1,1,1,1,1,1 -> 2000
2,2,2,2,2,2 -> 400
6,6,1,5,5,6 -> 800
2,3,4,6,2,4 -> 0
1,5,1,5,1,5 -> 1500
5,5,5,5,2,3 -> 550
1,1,1,1,1,5 -> 1250
3,3,4,4,3,4 -> 700

• in re: 'crossed out 144': bold your strikethrough, it'll be more obvious. – Stackstuck Jun 12 at 23:46

## JavaScript (ES6), 87 86 bytes

a=>a.sort().join.replace(/(.)\1\1|1|5/g,s=>r+=s>>7?s/1.11:s>5?1e3:s>1?50:100,r=0)&&r


Sorts and stringifies the input so that scoring combinations can be identified by means of regexp. Edit: Saved 1 byte thanks to @Arnauld.

• s>>7 instead of s>111 saves one byte in the first version – Arnauld Aug 22 '16 at 22:11

# Python 2 or 3, 123 122 121 116 109 108 104 102 100 97 bytes

Python 2, 97 bytes

lambda r:100*sum(c/3*((v<2)*9+v)+c%3*(v<2or(v==5)/2.)for v,c in enumerate(map(r.count,range(7))))


Test cases are on ideone

Python 3, 97 bytes

lambda r:100*sum(c//3*((v<2)*9+v)+c%3*(v<2or(v==5)/2)for v,c in enumerate(map(r.count,range(7))))


# Ruby, 80 78 bytes

Try it online!

-2 byte from @ezrast.

->d{s=0;7.times{|i|c=d.count i;i<2&&i=10;s+=c>2?c/3*i*100:1>i%5?c%3*i*10:0};s}

• This gives me a SyntaxError. I think you need a space after the first colon. – Jordan Aug 23 '16 at 2:43
• @Jordan Even though it worked fine on repl.it it still breaks... it's OK, I rearranged the logic to not require it any more – Value Ink Aug 23 '16 at 6:17
• i<2&&i=10 saves you 2 bytes. – ezrast Aug 23 '16 at 19:47

This is not a challenge for Haskell. Also I am in golfing this.

Thanks to @nimi.

import Data.List
f=g.sort
g(x:a@(y:z:b))|x>z=j x+g a|0<1=100*h x+g b
g(x:y)=j x+g a
g _=0
h 1=10
h x=x
j 1=100
j 5=50
j _=0


## Javascript (ES6), 85 84 bytes

x=>x.map(v=>s+=v*(((z+=1<<v*3)>>v*3&7)%3?v-5?v-1?0:10:1:v-5?v-1?10:80:8),s=z=0)|10*s


Test cases:

let F =
x=>x.map(v=>s+=v*(((z+=1<<v*3)>>v*3&7)%3?v-5?v-1?0:10:1:v-5?v-1?10:80:8),s=z=0)|10*s

console.log(F([1, 2, 3, 4, 5, 6])); // 150
console.log(F([1, 1, 1, 2, 3, 5])); // 1050
console.log(F([1, 1, 1, 1, 1, 1])); // 2000
console.log(F([2, 2, 2, 2, 2, 2])); // 400
console.log(F([6, 6, 1, 5, 5, 6])); // 800
console.log(F([2, 3, 4, 6, 2, 4])); // 0
console.log(F([1, 5, 1, 5, 1, 5])); // 1500
console.log(F([5, 5, 5, 5, 2, 3])); // 550
console.log(F([1, 1, 1, 1, 1, 5])); // 1250
console.log(F([3, 3, 4, 4, 3, 4])); // 700

# Python 3, 131 bytes

lambda r,C=list.count:sum([x%7*100,1e3][x%7<2]*(C(r,x%7)>2and not exec('r.remove(x%7);'*3))for x in range(14))+50*C(r,5)+100*C(r,1)


This is a lambda expression; to use it, assign it by prepending f=.

We first check for triples twice (by using modulus), removing the triples as we go; then we simply add the counts of 5 and 1 to the score and return it.

Try it on Ideone! (with all test cases)

Here's my older Python 2 submission:

## Python 2, 176172171145136134 133 bytes

def e(r):s=x=0;exec'x+=1;a=x%7;\nif r.count(a)>2:exec"r.remove(a);"*3;s+=[a*100,1e3][a<2]\n'*14;C=r.count;s+=50*C(5)+100*C(1);print s


Saved a byte on the Python 2 solution thanks to @mbomb007!

• print s is shorter in Python 2. – mbomb007 Aug 22 '16 at 19:16
• @mbomb007 Thanks! I'll edit that in. – Copper Aug 22 '16 at 20:20

sed -re's/([1-6])(.*)\1(.*)\1/\100\2\3/g;s/([1-6])( .*)\1( .*)\1/\100\2\3/g;s/10/1/g; s/1/100/g;s/5( |$)/50 /g;s/[1-6][^0]//g;s/ +/+/g;s/(^\+|\+$)//g;s/^$/0/'|bc  I wanted to do it all in sed, but addition is really hard... Explanation: 1. Find a triplet, add 00 to the first number and remove the other e.g. 1 2 1 3 1 4 -> 100 2 3 4 2. Repeat step 1 incase there are two triples 3. Replace 10 with 1 then 1 with 100 e.g. 100 -> 10 -> 1000 or 1 -> 1 -> 100 4. Replace each 5 not followed by 0 with 50 5. Remove any number that doesn't end in 0 6. Replace groups of spaces with + 7. Remove leading and trailing +s 8. If the string is empty, add a 0 9. Lastly pipe to bc to add everything up. # Perl, 69 bytes Includes +2 for -ap Run with the input on STDIN: dice10000.pl <<< "5 1 1 1 1 1"  dice10000.pl: #!/usr/bin/perl -ap$_=join 0,sort@F,A;print;s%(10|\d)\1\1|10|5%$n+=$1.0||$&%eg;$_=$n.0  • This doesn't seem to work for an input like "2 2 2 2 2 2" – Xcali Jun 7 at 0:56 # C# (.NET Core), 228 227 bytes class A{static void Main(string[] a){int[] x=new int[7];int i=0,s=0;for(;i<6;i++)x[int.Parse(a[i])]++;while(i>0){while(x[i]>2){s+=i>1?10*i:100;x[i]-=3;}i--;}while(x[1]-->0)s+=10;while(x[5]-->0)s+=5;System.Console.Write(s*10);}}  Try it online! I feel like I'm missing many, many potential optimizations here, but I did save a byte by multiplying by 10 at the end. Input should be passed as separate command line args. # Perl 5-ap, 78 bytes $_=join'',sort@F;s|(\d)\1\1|!($\+=$1*($1-1?2:20))|ge;$\+=y/5//+2*y/1//}{\$\*=50


Try it online!