Mid-Autumn Festival gambling game
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Tomorrow is the Mid-Autumn festival, and in the spirit of that holiday, I will introduce a gambling game that we(people from Xiamen) play during the holiday!
Rules
The game is played with six 6-sided dice. Different combinations of numbers have different ranks, with a special emphasis on fours and ones. Your job is to write a program/function that will rank the hand, given a roll of 6 dice. Here are the ranks(I've modified/simplified the rules a bit):
I guess only Chinese people can do this challenge! Okay, fine, here are some English explanations.
- 0: 4 fours and 2 ones.
- 1: 6 fours.
- 2: 6 ones.
- 3: 6 of any kind except fours and ones.
- 4: 5 fours.
- 5: 5 of any kind except for fours.
- 6: 4 fours.
- 7: Straight. (1-6)
- 8: 3 fours.
- 9: 4 of any kind except 4.
- 11: 2 fours.
- 12: 1 four.
- 13: Nothing.
Input
6 numbers, an array of 6 numbers, or a string of 6 numbers that represent the values of the 6 dice rolls from 1-6
Output
Your program/function may return/output anything to indicate the rank, as long as each rank is indicated by one output and vice versa. Ex. Using the numbers 0-12, 1-13, etc. (Note that #10 is skipped in the picture)
Examples(Using 0-12 as the outputs)
[1,1,1,1,1,1]->2
[1,4,4,4,1,4]->0
[3,6,5,1,4,2]->7
[1,2,3,5,6,6]->12
[3,6,3,3,3,3]->5
[4,5,5,5,5,5]->5
This is code-golf, so shortest byte count wins!
code-golf
 |Â
show 1 more comment
up vote
1
down vote
favorite
Tomorrow is the Mid-Autumn festival, and in the spirit of that holiday, I will introduce a gambling game that we(people from Xiamen) play during the holiday!
Rules
The game is played with six 6-sided dice. Different combinations of numbers have different ranks, with a special emphasis on fours and ones. Your job is to write a program/function that will rank the hand, given a roll of 6 dice. Here are the ranks(I've modified/simplified the rules a bit):
I guess only Chinese people can do this challenge! Okay, fine, here are some English explanations.
- 0: 4 fours and 2 ones.
- 1: 6 fours.
- 2: 6 ones.
- 3: 6 of any kind except fours and ones.
- 4: 5 fours.
- 5: 5 of any kind except for fours.
- 6: 4 fours.
- 7: Straight. (1-6)
- 8: 3 fours.
- 9: 4 of any kind except 4.
- 11: 2 fours.
- 12: 1 four.
- 13: Nothing.
Input
6 numbers, an array of 6 numbers, or a string of 6 numbers that represent the values of the 6 dice rolls from 1-6
Output
Your program/function may return/output anything to indicate the rank, as long as each rank is indicated by one output and vice versa. Ex. Using the numbers 0-12, 1-13, etc. (Note that #10 is skipped in the picture)
Examples(Using 0-12 as the outputs)
[1,1,1,1,1,1]->2
[1,4,4,4,1,4]->0
[3,6,5,1,4,2]->7
[1,2,3,5,6,6]->12
[3,6,3,3,3,3]->5
[4,5,5,5,5,5]->5
This is code-golf, so shortest byte count wins!
code-golf
(I would've put this in the sandbox, but I wanted the timing to be right. I tried to be as thorough as possible, please let me know if there are any clarifications needed.)
â Quintec
2 hours ago
Why is 10 skipped? Doing so would seem to add an unnecessary complication to the challenge.
â Shaggy
2 hours ago
@Shaggy So the OP says that output 0-12 or 1-13 instead
â Shieru Asakoto
1 hour ago
@Shaggy As I stated in the question, the output does not necessarily have to correspond with the label number. The skipped number and random gaps in the image are to simplify the rules a bit - there really aren't definite rules for this tradition, this is just my interpretation.
â Quintec
1 hour ago
Suggested test case:4,5,5,5,5,5
.
â Arnauld
1 hour ago
 |Â
show 1 more comment
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Tomorrow is the Mid-Autumn festival, and in the spirit of that holiday, I will introduce a gambling game that we(people from Xiamen) play during the holiday!
Rules
The game is played with six 6-sided dice. Different combinations of numbers have different ranks, with a special emphasis on fours and ones. Your job is to write a program/function that will rank the hand, given a roll of 6 dice. Here are the ranks(I've modified/simplified the rules a bit):
I guess only Chinese people can do this challenge! Okay, fine, here are some English explanations.
- 0: 4 fours and 2 ones.
- 1: 6 fours.
- 2: 6 ones.
- 3: 6 of any kind except fours and ones.
- 4: 5 fours.
- 5: 5 of any kind except for fours.
- 6: 4 fours.
- 7: Straight. (1-6)
- 8: 3 fours.
- 9: 4 of any kind except 4.
- 11: 2 fours.
- 12: 1 four.
- 13: Nothing.
Input
6 numbers, an array of 6 numbers, or a string of 6 numbers that represent the values of the 6 dice rolls from 1-6
Output
Your program/function may return/output anything to indicate the rank, as long as each rank is indicated by one output and vice versa. Ex. Using the numbers 0-12, 1-13, etc. (Note that #10 is skipped in the picture)
Examples(Using 0-12 as the outputs)
[1,1,1,1,1,1]->2
[1,4,4,4,1,4]->0
[3,6,5,1,4,2]->7
[1,2,3,5,6,6]->12
[3,6,3,3,3,3]->5
[4,5,5,5,5,5]->5
This is code-golf, so shortest byte count wins!
code-golf
Tomorrow is the Mid-Autumn festival, and in the spirit of that holiday, I will introduce a gambling game that we(people from Xiamen) play during the holiday!
Rules
The game is played with six 6-sided dice. Different combinations of numbers have different ranks, with a special emphasis on fours and ones. Your job is to write a program/function that will rank the hand, given a roll of 6 dice. Here are the ranks(I've modified/simplified the rules a bit):
I guess only Chinese people can do this challenge! Okay, fine, here are some English explanations.
- 0: 4 fours and 2 ones.
- 1: 6 fours.
- 2: 6 ones.
- 3: 6 of any kind except fours and ones.
- 4: 5 fours.
- 5: 5 of any kind except for fours.
- 6: 4 fours.
- 7: Straight. (1-6)
- 8: 3 fours.
- 9: 4 of any kind except 4.
- 11: 2 fours.
- 12: 1 four.
- 13: Nothing.
Input
6 numbers, an array of 6 numbers, or a string of 6 numbers that represent the values of the 6 dice rolls from 1-6
Output
Your program/function may return/output anything to indicate the rank, as long as each rank is indicated by one output and vice versa. Ex. Using the numbers 0-12, 1-13, etc. (Note that #10 is skipped in the picture)
Examples(Using 0-12 as the outputs)
[1,1,1,1,1,1]->2
[1,4,4,4,1,4]->0
[3,6,5,1,4,2]->7
[1,2,3,5,6,6]->12
[3,6,3,3,3,3]->5
[4,5,5,5,5,5]->5
This is code-golf, so shortest byte count wins!
code-golf
code-golf
edited 59 mins ago
asked 2 hours ago
Quintec
516212
516212
(I would've put this in the sandbox, but I wanted the timing to be right. I tried to be as thorough as possible, please let me know if there are any clarifications needed.)
â Quintec
2 hours ago
Why is 10 skipped? Doing so would seem to add an unnecessary complication to the challenge.
â Shaggy
2 hours ago
@Shaggy So the OP says that output 0-12 or 1-13 instead
â Shieru Asakoto
1 hour ago
@Shaggy As I stated in the question, the output does not necessarily have to correspond with the label number. The skipped number and random gaps in the image are to simplify the rules a bit - there really aren't definite rules for this tradition, this is just my interpretation.
â Quintec
1 hour ago
Suggested test case:4,5,5,5,5,5
.
â Arnauld
1 hour ago
 |Â
show 1 more comment
(I would've put this in the sandbox, but I wanted the timing to be right. I tried to be as thorough as possible, please let me know if there are any clarifications needed.)
â Quintec
2 hours ago
Why is 10 skipped? Doing so would seem to add an unnecessary complication to the challenge.
â Shaggy
2 hours ago
@Shaggy So the OP says that output 0-12 or 1-13 instead
â Shieru Asakoto
1 hour ago
@Shaggy As I stated in the question, the output does not necessarily have to correspond with the label number. The skipped number and random gaps in the image are to simplify the rules a bit - there really aren't definite rules for this tradition, this is just my interpretation.
â Quintec
1 hour ago
Suggested test case:4,5,5,5,5,5
.
â Arnauld
1 hour ago
(I would've put this in the sandbox, but I wanted the timing to be right. I tried to be as thorough as possible, please let me know if there are any clarifications needed.)
â Quintec
2 hours ago
(I would've put this in the sandbox, but I wanted the timing to be right. I tried to be as thorough as possible, please let me know if there are any clarifications needed.)
â Quintec
2 hours ago
Why is 10 skipped? Doing so would seem to add an unnecessary complication to the challenge.
â Shaggy
2 hours ago
Why is 10 skipped? Doing so would seem to add an unnecessary complication to the challenge.
â Shaggy
2 hours ago
@Shaggy So the OP says that output 0-12 or 1-13 instead
â Shieru Asakoto
1 hour ago
@Shaggy So the OP says that output 0-12 or 1-13 instead
â Shieru Asakoto
1 hour ago
@Shaggy As I stated in the question, the output does not necessarily have to correspond with the label number. The skipped number and random gaps in the image are to simplify the rules a bit - there really aren't definite rules for this tradition, this is just my interpretation.
â Quintec
1 hour ago
@Shaggy As I stated in the question, the output does not necessarily have to correspond with the label number. The skipped number and random gaps in the image are to simplify the rules a bit - there really aren't definite rules for this tradition, this is just my interpretation.
â Quintec
1 hour ago
Suggested test case:
4,5,5,5,5,5
.â Arnauld
1 hour ago
Suggested test case:
4,5,5,5,5,5
.â Arnauld
1 hour ago
 |Â
show 1 more comment
2 Answers
2
active
oldest
votes
up vote
2
down vote
JavaScript (ES6), 115 bytes
Returns an integer between $0$ and $12$.
a=>a.map(m=o=n=>m=(x=o[n]=-~o[n])<m?m:x)|(a=[,m-1?11:7,10,8,o[1]^2&&6,4,1][o[4]])<(b=[9,5,3-(o[1]>5)][m-4]||12)?a:b
Try it online!
Commented
a => // a = input array
a.map( // iterate over a
m = // m = maximum number of occurrences of the same dice
o = // o = number of occurrences of each dice
n => // for each dice n in a:
m = // update m:
(x = o[n] = -~o[n]) // increment o[n] and save this value in x
< m ? // if x is less than m:
m // leave m unchanged
: // else:
x // update m to x
) | ( // end of map()
a = [ // compute a: the rank based on the number of 4's
, // no 4 -> undefined
m - 1 ? 11 : 7, // one 4 -> 7 if m = 1 (straight) or 11 otherwise
10, // two 4's -> 10
8, // three 4's -> 8
o[1] ^ 2 && 6, // four 4's -> 0 if we also have two 1's or 6 otherwise
4, // five 4's -> 4
1 // six 4's -> 1
][o[4]] //
) < ( //
b = [ // compute b: the rank based on the max. number of occurrences
9, // four-of-a-kind -> 9
5, // five-of-a-kind -> 5
3 - (o[1] > 5) // six-of-a-kind -> 2 if that's six 1's or 3 otherwise
][m - 4] //
|| 12 // fallback value: 12
) ? a : b // return min(a, b) (or b if a is undefined)
add a comment |Â
up vote
1
down vote
JavaScript (Node.js), 169 bytes
a=>-~"114444|123456".search(w=a.sort().join``,[l,t]=/(.)13,/.exec(w)||[0],l=l.length)||(l>5?3-"14".search(t):l>3?4+(5.5-l)*(t-4?4:2):[,13,12,11,9][w.split`4`.length])
Try it online!
Returns 1..13
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
JavaScript (ES6), 115 bytes
Returns an integer between $0$ and $12$.
a=>a.map(m=o=n=>m=(x=o[n]=-~o[n])<m?m:x)|(a=[,m-1?11:7,10,8,o[1]^2&&6,4,1][o[4]])<(b=[9,5,3-(o[1]>5)][m-4]||12)?a:b
Try it online!
Commented
a => // a = input array
a.map( // iterate over a
m = // m = maximum number of occurrences of the same dice
o = // o = number of occurrences of each dice
n => // for each dice n in a:
m = // update m:
(x = o[n] = -~o[n]) // increment o[n] and save this value in x
< m ? // if x is less than m:
m // leave m unchanged
: // else:
x // update m to x
) | ( // end of map()
a = [ // compute a: the rank based on the number of 4's
, // no 4 -> undefined
m - 1 ? 11 : 7, // one 4 -> 7 if m = 1 (straight) or 11 otherwise
10, // two 4's -> 10
8, // three 4's -> 8
o[1] ^ 2 && 6, // four 4's -> 0 if we also have two 1's or 6 otherwise
4, // five 4's -> 4
1 // six 4's -> 1
][o[4]] //
) < ( //
b = [ // compute b: the rank based on the max. number of occurrences
9, // four-of-a-kind -> 9
5, // five-of-a-kind -> 5
3 - (o[1] > 5) // six-of-a-kind -> 2 if that's six 1's or 3 otherwise
][m - 4] //
|| 12 // fallback value: 12
) ? a : b // return min(a, b) (or b if a is undefined)
add a comment |Â
up vote
2
down vote
JavaScript (ES6), 115 bytes
Returns an integer between $0$ and $12$.
a=>a.map(m=o=n=>m=(x=o[n]=-~o[n])<m?m:x)|(a=[,m-1?11:7,10,8,o[1]^2&&6,4,1][o[4]])<(b=[9,5,3-(o[1]>5)][m-4]||12)?a:b
Try it online!
Commented
a => // a = input array
a.map( // iterate over a
m = // m = maximum number of occurrences of the same dice
o = // o = number of occurrences of each dice
n => // for each dice n in a:
m = // update m:
(x = o[n] = -~o[n]) // increment o[n] and save this value in x
< m ? // if x is less than m:
m // leave m unchanged
: // else:
x // update m to x
) | ( // end of map()
a = [ // compute a: the rank based on the number of 4's
, // no 4 -> undefined
m - 1 ? 11 : 7, // one 4 -> 7 if m = 1 (straight) or 11 otherwise
10, // two 4's -> 10
8, // three 4's -> 8
o[1] ^ 2 && 6, // four 4's -> 0 if we also have two 1's or 6 otherwise
4, // five 4's -> 4
1 // six 4's -> 1
][o[4]] //
) < ( //
b = [ // compute b: the rank based on the max. number of occurrences
9, // four-of-a-kind -> 9
5, // five-of-a-kind -> 5
3 - (o[1] > 5) // six-of-a-kind -> 2 if that's six 1's or 3 otherwise
][m - 4] //
|| 12 // fallback value: 12
) ? a : b // return min(a, b) (or b if a is undefined)
add a comment |Â
up vote
2
down vote
up vote
2
down vote
JavaScript (ES6), 115 bytes
Returns an integer between $0$ and $12$.
a=>a.map(m=o=n=>m=(x=o[n]=-~o[n])<m?m:x)|(a=[,m-1?11:7,10,8,o[1]^2&&6,4,1][o[4]])<(b=[9,5,3-(o[1]>5)][m-4]||12)?a:b
Try it online!
Commented
a => // a = input array
a.map( // iterate over a
m = // m = maximum number of occurrences of the same dice
o = // o = number of occurrences of each dice
n => // for each dice n in a:
m = // update m:
(x = o[n] = -~o[n]) // increment o[n] and save this value in x
< m ? // if x is less than m:
m // leave m unchanged
: // else:
x // update m to x
) | ( // end of map()
a = [ // compute a: the rank based on the number of 4's
, // no 4 -> undefined
m - 1 ? 11 : 7, // one 4 -> 7 if m = 1 (straight) or 11 otherwise
10, // two 4's -> 10
8, // three 4's -> 8
o[1] ^ 2 && 6, // four 4's -> 0 if we also have two 1's or 6 otherwise
4, // five 4's -> 4
1 // six 4's -> 1
][o[4]] //
) < ( //
b = [ // compute b: the rank based on the max. number of occurrences
9, // four-of-a-kind -> 9
5, // five-of-a-kind -> 5
3 - (o[1] > 5) // six-of-a-kind -> 2 if that's six 1's or 3 otherwise
][m - 4] //
|| 12 // fallback value: 12
) ? a : b // return min(a, b) (or b if a is undefined)
JavaScript (ES6), 115 bytes
Returns an integer between $0$ and $12$.
a=>a.map(m=o=n=>m=(x=o[n]=-~o[n])<m?m:x)|(a=[,m-1?11:7,10,8,o[1]^2&&6,4,1][o[4]])<(b=[9,5,3-(o[1]>5)][m-4]||12)?a:b
Try it online!
Commented
a => // a = input array
a.map( // iterate over a
m = // m = maximum number of occurrences of the same dice
o = // o = number of occurrences of each dice
n => // for each dice n in a:
m = // update m:
(x = o[n] = -~o[n]) // increment o[n] and save this value in x
< m ? // if x is less than m:
m // leave m unchanged
: // else:
x // update m to x
) | ( // end of map()
a = [ // compute a: the rank based on the number of 4's
, // no 4 -> undefined
m - 1 ? 11 : 7, // one 4 -> 7 if m = 1 (straight) or 11 otherwise
10, // two 4's -> 10
8, // three 4's -> 8
o[1] ^ 2 && 6, // four 4's -> 0 if we also have two 1's or 6 otherwise
4, // five 4's -> 4
1 // six 4's -> 1
][o[4]] //
) < ( //
b = [ // compute b: the rank based on the max. number of occurrences
9, // four-of-a-kind -> 9
5, // five-of-a-kind -> 5
3 - (o[1] > 5) // six-of-a-kind -> 2 if that's six 1's or 3 otherwise
][m - 4] //
|| 12 // fallback value: 12
) ? a : b // return min(a, b) (or b if a is undefined)
edited 6 mins ago
answered 43 mins ago
Arnauld
64.7k581274
64.7k581274
add a comment |Â
add a comment |Â
up vote
1
down vote
JavaScript (Node.js), 169 bytes
a=>-~"114444|123456".search(w=a.sort().join``,[l,t]=/(.)13,/.exec(w)||[0],l=l.length)||(l>5?3-"14".search(t):l>3?4+(5.5-l)*(t-4?4:2):[,13,12,11,9][w.split`4`.length])
Try it online!
Returns 1..13
add a comment |Â
up vote
1
down vote
JavaScript (Node.js), 169 bytes
a=>-~"114444|123456".search(w=a.sort().join``,[l,t]=/(.)13,/.exec(w)||[0],l=l.length)||(l>5?3-"14".search(t):l>3?4+(5.5-l)*(t-4?4:2):[,13,12,11,9][w.split`4`.length])
Try it online!
Returns 1..13
add a comment |Â
up vote
1
down vote
up vote
1
down vote
JavaScript (Node.js), 169 bytes
a=>-~"114444|123456".search(w=a.sort().join``,[l,t]=/(.)13,/.exec(w)||[0],l=l.length)||(l>5?3-"14".search(t):l>3?4+(5.5-l)*(t-4?4:2):[,13,12,11,9][w.split`4`.length])
Try it online!
Returns 1..13
JavaScript (Node.js), 169 bytes
a=>-~"114444|123456".search(w=a.sort().join``,[l,t]=/(.)13,/.exec(w)||[0],l=l.length)||(l>5?3-"14".search(t):l>3?4+(5.5-l)*(t-4?4:2):[,13,12,11,9][w.split`4`.length])
Try it online!
Returns 1..13
answered 55 mins ago
Shieru Asakoto
1,620311
1,620311
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f172708%2fmid-autumn-festival-gambling-game%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
(I would've put this in the sandbox, but I wanted the timing to be right. I tried to be as thorough as possible, please let me know if there are any clarifications needed.)
â Quintec
2 hours ago
Why is 10 skipped? Doing so would seem to add an unnecessary complication to the challenge.
â Shaggy
2 hours ago
@Shaggy So the OP says that output 0-12 or 1-13 instead
â Shieru Asakoto
1 hour ago
@Shaggy As I stated in the question, the output does not necessarily have to correspond with the label number. The skipped number and random gaps in the image are to simplify the rules a bit - there really aren't definite rules for this tradition, this is just my interpretation.
â Quintec
1 hour ago
Suggested test case:
4,5,5,5,5,5
.â Arnauld
1 hour ago