Who won a Game of Bar Dice?Non-transitive dice gameCompare two poker handsRole-Playing Game Dice-RollingScore a game of Load, Defend and ShootFind the outcome of a game of WarMake this dice game fairWho won the game?Golf an unbeatable chopsticks botBadugi, Who Wins?Who will win a Rock, Paper, Scissors, Lizard, Spock game?
Find the C-factor of a vote
Set multicolumn to a exact width
C-152 carb heat on before landing in hot weather?
Are all instances of trolls turning to stone ultimately references back to Tolkien?
Should developer taking test phones home or put in office?
Computing a trigonometric integral
Is adding a new player (or players) a DM decision, or a group decision?
Iterate MapThread with matrices
Where can I find a database of galactic spectra?
How do I turn off a repeating trade?
Does squid ink pasta bleed?
Does Marvel have an equivalent of the Green Lantern?
Impossible darts scores
How would modern naval warfare have to have developed differently for battleships to still be relevant in the 21st century?
What are the penalties for overstaying in USA?
First-year PhD giving a talk among well-established researchers in the field
Interaction between Leyline of Anticipation and Teferi, Time Raveler
What does "play with your toy’s toys" mean?
How dangerous are set-size assumptions?
How much will studying magic in an academy cost?
Is it damaging to turn off a small fridge for two days every week?
Using sed to replace "A" with a "B" or "C"
Cascading Repair Costs following Blown Head Gasket on a 2004 Subaru Outback
Intuition for capacitors in series
Who won a Game of Bar Dice?
Non-transitive dice gameCompare two poker handsRole-Playing Game Dice-RollingScore a game of Load, Defend and ShootFind the outcome of a game of WarMake this dice game fairWho won the game?Golf an unbeatable chopsticks botBadugi, Who Wins?Who will win a Rock, Paper, Scissors, Lizard, Spock game?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
Challenge
Bar Dice is a simple game played in a Bar with Dice (hence the name). You roll 5 six-sided dice and attempt to make the best hand.
Scoring is based on amassing the largest number of dice with the same digits. Each hand must include at least a single "Ace", or one, in order to be a valid hand; Aces act as "wilds", and can be paired with any other digit. The strength of a player's hand depends first on the number of digits and then value of those digits. As an example, a hand (counting wilds) with four 3's is better than a hand with three 5's, but not better than a hand with five 2's.
Taken from the Wikipedia article
This means the highest ranked hand is made entirely of 6's and 1's, and the lowest ranked is any hand without a 1.
Your challenge is to take two hands and return which player won, or if they tied.
Input
Two unsorted lists of 5 numbers, ranging from 1 to 6. Each list represents a player's hand. The input format is flexible.
Output
Any three distinct but consistent, static values (ranges are not allowed) signifying whether player 1 or player 2 won, or if it was a tie. Please state in your answer what values you are using for what. For example, you can return -1
if P1 wins, 0
if it's a tie, and 1
if P2 wins.
Rules
- Input will always be valid
- Only the best possible score of each hand is used to determine a winner. There are no tie-breakers. E.g.,
[1,4,4,3,3]
will tie[1,4,4,2,2]
instead of using the 3's and 2's as a tie-breaker. - Output must be one of the 3 chosen values every time. Simply mapping all negative numbers to
P1 Wins
is not allowed and must be normalized. - Invalid hands, i.e. those with no 1's, lose to all valid hands but tie with all other invalid hands. E.g.,
[2,2,2,2,2]
ties[3,3,3,3,3]
. - A hand of
[1,1,1,1,1]
counts as a valid set of 6's for ranking purposes. - This is code-golf so shortest byte count wins.
Examples
#You guys are pretty good at finding edge-cases that break things. Good job!
Input: [2,1,5,6,6], [6,2,6,6,6]
Output: P1 Wins
Input: [2,4,5,6,6], [6,2,6,6,6]
Output: Tie
Input: [1,2,3,4,5], [5,4,3,2,1]
Output: Tie
Input: [1,5,5,3,2], [5,4,1,6,6]
Output: P2 Wins
Input: [3,2,2,2,1], [4,1,3,6,6]
Output: P1 Wins
Input: [1,1,1,1,1], [6,1,1,6,6]
Output: Tie
Input: [1,3,3,4,4], [1,2,2,5,5]
Output: P2 Wins
Input: [1,3,3,5,5], [1,3,3,2,2]
Output: P1 Wins
Input: [1,3,3,3,4], [1,1,3,3,3]
Output: P2 Wins
Input: [2,2,2,6,1], [5,3,3,1,2]
Output: P1 Wins
Input: [5,5,5,1,5], [1,1,1,1,1]
Output: P2 Wins
Input: [1,1,1,1,1], [1,1,5,1,1]
Output: P1 Wins
code-golf decision-problem game
$endgroup$
add a comment |
$begingroup$
Challenge
Bar Dice is a simple game played in a Bar with Dice (hence the name). You roll 5 six-sided dice and attempt to make the best hand.
Scoring is based on amassing the largest number of dice with the same digits. Each hand must include at least a single "Ace", or one, in order to be a valid hand; Aces act as "wilds", and can be paired with any other digit. The strength of a player's hand depends first on the number of digits and then value of those digits. As an example, a hand (counting wilds) with four 3's is better than a hand with three 5's, but not better than a hand with five 2's.
Taken from the Wikipedia article
This means the highest ranked hand is made entirely of 6's and 1's, and the lowest ranked is any hand without a 1.
Your challenge is to take two hands and return which player won, or if they tied.
Input
Two unsorted lists of 5 numbers, ranging from 1 to 6. Each list represents a player's hand. The input format is flexible.
Output
Any three distinct but consistent, static values (ranges are not allowed) signifying whether player 1 or player 2 won, or if it was a tie. Please state in your answer what values you are using for what. For example, you can return -1
if P1 wins, 0
if it's a tie, and 1
if P2 wins.
Rules
- Input will always be valid
- Only the best possible score of each hand is used to determine a winner. There are no tie-breakers. E.g.,
[1,4,4,3,3]
will tie[1,4,4,2,2]
instead of using the 3's and 2's as a tie-breaker. - Output must be one of the 3 chosen values every time. Simply mapping all negative numbers to
P1 Wins
is not allowed and must be normalized. - Invalid hands, i.e. those with no 1's, lose to all valid hands but tie with all other invalid hands. E.g.,
[2,2,2,2,2]
ties[3,3,3,3,3]
. - A hand of
[1,1,1,1,1]
counts as a valid set of 6's for ranking purposes. - This is code-golf so shortest byte count wins.
Examples
#You guys are pretty good at finding edge-cases that break things. Good job!
Input: [2,1,5,6,6], [6,2,6,6,6]
Output: P1 Wins
Input: [2,4,5,6,6], [6,2,6,6,6]
Output: Tie
Input: [1,2,3,4,5], [5,4,3,2,1]
Output: Tie
Input: [1,5,5,3,2], [5,4,1,6,6]
Output: P2 Wins
Input: [3,2,2,2,1], [4,1,3,6,6]
Output: P1 Wins
Input: [1,1,1,1,1], [6,1,1,6,6]
Output: Tie
Input: [1,3,3,4,4], [1,2,2,5,5]
Output: P2 Wins
Input: [1,3,3,5,5], [1,3,3,2,2]
Output: P1 Wins
Input: [1,3,3,3,4], [1,1,3,3,3]
Output: P2 Wins
Input: [2,2,2,6,1], [5,3,3,1,2]
Output: P1 Wins
Input: [5,5,5,1,5], [1,1,1,1,1]
Output: P2 Wins
Input: [1,1,1,1,1], [1,1,5,1,1]
Output: P1 Wins
code-golf decision-problem game
$endgroup$
add a comment |
$begingroup$
Challenge
Bar Dice is a simple game played in a Bar with Dice (hence the name). You roll 5 six-sided dice and attempt to make the best hand.
Scoring is based on amassing the largest number of dice with the same digits. Each hand must include at least a single "Ace", or one, in order to be a valid hand; Aces act as "wilds", and can be paired with any other digit. The strength of a player's hand depends first on the number of digits and then value of those digits. As an example, a hand (counting wilds) with four 3's is better than a hand with three 5's, but not better than a hand with five 2's.
Taken from the Wikipedia article
This means the highest ranked hand is made entirely of 6's and 1's, and the lowest ranked is any hand without a 1.
Your challenge is to take two hands and return which player won, or if they tied.
Input
Two unsorted lists of 5 numbers, ranging from 1 to 6. Each list represents a player's hand. The input format is flexible.
Output
Any three distinct but consistent, static values (ranges are not allowed) signifying whether player 1 or player 2 won, or if it was a tie. Please state in your answer what values you are using for what. For example, you can return -1
if P1 wins, 0
if it's a tie, and 1
if P2 wins.
Rules
- Input will always be valid
- Only the best possible score of each hand is used to determine a winner. There are no tie-breakers. E.g.,
[1,4,4,3,3]
will tie[1,4,4,2,2]
instead of using the 3's and 2's as a tie-breaker. - Output must be one of the 3 chosen values every time. Simply mapping all negative numbers to
P1 Wins
is not allowed and must be normalized. - Invalid hands, i.e. those with no 1's, lose to all valid hands but tie with all other invalid hands. E.g.,
[2,2,2,2,2]
ties[3,3,3,3,3]
. - A hand of
[1,1,1,1,1]
counts as a valid set of 6's for ranking purposes. - This is code-golf so shortest byte count wins.
Examples
#You guys are pretty good at finding edge-cases that break things. Good job!
Input: [2,1,5,6,6], [6,2,6,6,6]
Output: P1 Wins
Input: [2,4,5,6,6], [6,2,6,6,6]
Output: Tie
Input: [1,2,3,4,5], [5,4,3,2,1]
Output: Tie
Input: [1,5,5,3,2], [5,4,1,6,6]
Output: P2 Wins
Input: [3,2,2,2,1], [4,1,3,6,6]
Output: P1 Wins
Input: [1,1,1,1,1], [6,1,1,6,6]
Output: Tie
Input: [1,3,3,4,4], [1,2,2,5,5]
Output: P2 Wins
Input: [1,3,3,5,5], [1,3,3,2,2]
Output: P1 Wins
Input: [1,3,3,3,4], [1,1,3,3,3]
Output: P2 Wins
Input: [2,2,2,6,1], [5,3,3,1,2]
Output: P1 Wins
Input: [5,5,5,1,5], [1,1,1,1,1]
Output: P2 Wins
Input: [1,1,1,1,1], [1,1,5,1,1]
Output: P1 Wins
code-golf decision-problem game
$endgroup$
Challenge
Bar Dice is a simple game played in a Bar with Dice (hence the name). You roll 5 six-sided dice and attempt to make the best hand.
Scoring is based on amassing the largest number of dice with the same digits. Each hand must include at least a single "Ace", or one, in order to be a valid hand; Aces act as "wilds", and can be paired with any other digit. The strength of a player's hand depends first on the number of digits and then value of those digits. As an example, a hand (counting wilds) with four 3's is better than a hand with three 5's, but not better than a hand with five 2's.
Taken from the Wikipedia article
This means the highest ranked hand is made entirely of 6's and 1's, and the lowest ranked is any hand without a 1.
Your challenge is to take two hands and return which player won, or if they tied.
Input
Two unsorted lists of 5 numbers, ranging from 1 to 6. Each list represents a player's hand. The input format is flexible.
Output
Any three distinct but consistent, static values (ranges are not allowed) signifying whether player 1 or player 2 won, or if it was a tie. Please state in your answer what values you are using for what. For example, you can return -1
if P1 wins, 0
if it's a tie, and 1
if P2 wins.
Rules
- Input will always be valid
- Only the best possible score of each hand is used to determine a winner. There are no tie-breakers. E.g.,
[1,4,4,3,3]
will tie[1,4,4,2,2]
instead of using the 3's and 2's as a tie-breaker. - Output must be one of the 3 chosen values every time. Simply mapping all negative numbers to
P1 Wins
is not allowed and must be normalized. - Invalid hands, i.e. those with no 1's, lose to all valid hands but tie with all other invalid hands. E.g.,
[2,2,2,2,2]
ties[3,3,3,3,3]
. - A hand of
[1,1,1,1,1]
counts as a valid set of 6's for ranking purposes. - This is code-golf so shortest byte count wins.
Examples
#You guys are pretty good at finding edge-cases that break things. Good job!
Input: [2,1,5,6,6], [6,2,6,6,6]
Output: P1 Wins
Input: [2,4,5,6,6], [6,2,6,6,6]
Output: Tie
Input: [1,2,3,4,5], [5,4,3,2,1]
Output: Tie
Input: [1,5,5,3,2], [5,4,1,6,6]
Output: P2 Wins
Input: [3,2,2,2,1], [4,1,3,6,6]
Output: P1 Wins
Input: [1,1,1,1,1], [6,1,1,6,6]
Output: Tie
Input: [1,3,3,4,4], [1,2,2,5,5]
Output: P2 Wins
Input: [1,3,3,5,5], [1,3,3,2,2]
Output: P1 Wins
Input: [1,3,3,3,4], [1,1,3,3,3]
Output: P2 Wins
Input: [2,2,2,6,1], [5,3,3,1,2]
Output: P1 Wins
Input: [5,5,5,1,5], [1,1,1,1,1]
Output: P2 Wins
Input: [1,1,1,1,1], [1,1,5,1,1]
Output: P1 Wins
code-golf decision-problem game
code-golf decision-problem game
edited Jun 13 at 14:47
Veskah
asked Jun 6 at 12:46
VeskahVeskah
1,5054 silver badges17 bronze badges
1,5054 silver badges17 bronze badges
add a comment |
add a comment |
17 Answers
17
active
oldest
votes
$begingroup$
Jelly, 17 14 bytes
ċⱮ6Ḣ©+$®aĖUṀ)M
Try it online!
A monadic link that takes a list of the two lists as its argument and returns [1]
for player 1 wins, [2]
for player 2 wins and [1, 2]
for a tie. TIO link tidies this up for display.
Thanks to @JonathanAllan for saving 3 bytes!
Explanation
) | For each input list (e.g. of one list 1,1,3,3,4)
ċⱮ6 | - Count each of 1..6 (e.g. 2,0,2,1,0,0)
$ | - Following as a monad:
Ḣ | - Head (number of 1s)
©︎ | - Copy to register
+ | - Add (e.g. 2,4,3,0,0)
®a | - Register logical and with this
Ė | - Enumerate (e.g. [1,2],[2,4],[3,3],[4,0],[5,0])
U | - Reverse each (e.g. [2,1],[4,2],[3,3],[0,4],[0,5])
Ṁ | - Max (e.g. 4,2)
M | Index/indices of maximal score
$endgroup$
1
$begingroup$
You could replace theIṠ
withM
and output a list of the winner(s).
$endgroup$
– Jonathan Allan
Jun 6 at 17:51
$begingroup$
@JonathanAllan Good point! Thanks
$endgroup$
– Nick Kennedy
Jun 6 at 17:54
1
$begingroup$
15 bytes by making use of the register.
$endgroup$
– Jonathan Allan
Jun 6 at 18:08
1
$begingroup$
I think theḌ
may now be redundant too since the lists sort the same as the integers.
$endgroup$
– Jonathan Allan
Jun 6 at 18:14
1
$begingroup$
This is a lovely approach. Well done.
$endgroup$
– Jonah
Jun 7 at 14:44
add a comment |
$begingroup$
R, 115 96 bytes
-6 bytes thanks to Giuseppe.
-6 bytes thanks to Aaron Hayman.
-2 bytes thanks to Arnauld, following the output format in his JavaScript answer.
function(i,j)(f(i)-f(j))/0
f=function(x,s=tabulate(x,6),l=s[1]+s[-1]*!!s[1])max(l)*6+order(l)[5]
Try it online!
Returns Inf
for P1, NaN
for a tie, -Inf
for P2.
Uses the helper function f
which computes a score for each hand. The score is defined as follows: let d
be the digit which is repeated the most, and n
the number of times it is repeated. Then the score is 6*n+d
if there is at least one ace, and 0
if there are no aces. We then just need to find the player with the highest score.
Ungolfed:
f = function(x)
s = tabulate(x, 6) # number of occurrences of each integer
l = s[1] + s[-1] * !!s[1] # add the number of wild aces to all values; set to 0 if s[1] == 0
max(l) * 6 + # highest number of repetitions (apart from aces)
order(l)[5] # most repeated integer (take largest in case of tie)
function(i, j)
sign(f(i) - f(j))
$endgroup$
$begingroup$
You can useorder(l)[5]
instead ofmax.col(t(l),"l")
to get a 96 byte solution: Try it online!
$endgroup$
– Aaron Hayman
Jun 7 at 14:25
$begingroup$
@AaronHayman Very nice, thanks!
$endgroup$
– Robin Ryder
Jun 7 at 14:33
add a comment |
$begingroup$
JavaScript (ES6), 97 90 bytes
Takes input as (a)(b)
. Returns +Infinity
for P1, -Infinity
for P2 or NaN
for a tie.
a=>b=>((g=(x,m)=>x>6?m*/1/.test(a):g(-~x,a.map(k=>n+=k<2|k==x,n=x/6)|m>n?m:n))()-g(a=b))/0
Try it online!
Commented
a => b => ( // a[] = dice of P1; b[] = dice of P2
( g = ( // g is a recursive function taking:
x, // x = dice value to test; initially, it is either undefined
// or set to a non-numeric value
m // m = maximum score so far, initially undefined
) => //
x > 6 ? // if x is greater than 6:
m * /1/.test(a) // return m, or 0 if a[] does not contain any 1
: // else:
g( // do a recursive call:
-~x, // increment x (or set it to 1 if it's non-numeric)
a.map(k => // for each dice value k in a[]:
n += // add 1 to n if:
k < 2 | // k is equal to 1
k == x, // or k is equal to x
n = x / 6 // start with n = x / 6
) | // end of map()
m > n ? // if m is defined and greater than n:
m // pass m unchanged
: // else:
n // update m to n
) // end of recursive call
)() // first call to g, using a[]
- g(a = b) // subtract the result of a 2nd call, using b[]
) / 0 // divide by 0 to force one of the 3 consistent output values
$endgroup$
add a comment |
$begingroup$
05AB1E, 16 15 bytes
-1 byte thanks to JonathanAllan
εWΘ*6L¢ć+°ƶà}ZQ
Try it online!
Returns [1, 0] for P1 wins, [1, 1] for ties, [0, 1] for P2 wins.
Rather than using lexicographic order on a 2-tuple (dice count, dice value), this computes the score as 10**dice count * dice value. Hands without a 1 score 5.
ε } # map each hand to its computed score
WΘ # minimum == 1 (1 if the hand contains a 1, 0 otherwise)
* # multiply (sets hands without 1 to [0, 0, 0, 0, 0])
6L # range [1..6]
¢ # count occurences of each in the hand
ć # head extract (stack is now [2-count, ..., 6-count], 1-count)
+ # add the 1-count to all the other counts
° # 10**x
ƶ # multiply each element by its 1-based index
à # take the maximum
Z # maximum
Q # equality test (vectorizes)
$endgroup$
1
$begingroup$
Ohhh.. I like theć+
(now that I see it I cannot believe I hadn't thought about it..)! That's so much better than what I was attempting.. I did had a similar idea with°
. :) Except that I was already at 20 bytes and still had to fix an issue for test case[[1,1,1,1,1],] [6,1,1,6,6]]
.. So thanks for saving me time so I can put my attempt in the garbage bin.. ;p
$endgroup$
– Kevin Cruijssen
Jun 6 at 13:55
1
$begingroup$
@KevinCruijssen Yeah it's amazing how wellć+
works. My initial idea started withæʒW}ʒ1KË
, but this gets killed by the[1,1,1,1,1]
issue.
$endgroup$
– Grimy
Jun 6 at 14:08
1
$begingroup$
Yeah, my approach was along the lines ofε1¢©Āyγéθ¬sg®+°P`.S
, but the[1,1,1,1,1]
screwed that over as well indeed. Your entire answer got a nice synergy with theWΘ*
,6L¢
,ć+
, and°ƶ
. Especially the builtinsWćƶ
really show their strength here.
$endgroup$
– Kevin Cruijssen
Jun 6 at 14:30
$begingroup$
W
isn't actually needed,6L¢¬Ā*
is the same byte-count asWΘ*6L¢
.
$endgroup$
– Grimy
Jun 6 at 14:38
$begingroup$
Hmm, good point. :) ThoughtW
without popping and then*
showed it's strength, but¬
without popping and then*
is basically the same. The fact that it doesn't pop is the strength I was implying to, saving a byte. But it's indeed mainlyćƶ
.
$endgroup$
– Kevin Cruijssen
Jun 6 at 14:40
add a comment |
$begingroup$
Python 2, 85 81 80 bytes
lambda p:cmp(*[max((h.count(i)+h.count(i>1),i)*(1in h)for i in[6]+h)for h in p])
Try it online!
Returns 1
for P1, 0
for tie, and -1
for P2.
-1 byte, thanks to squid
$endgroup$
1
$begingroup$
Whitespace between1
andin
can go
$endgroup$
– squid
Jun 6 at 15:25
$begingroup$
@squid Thanks, :)
$endgroup$
– TFeld
Jun 7 at 6:49
add a comment |
$begingroup$
Perl 6, 60 49 bytes
&[cmp]o*.map:.1&&max (.2..6X+.1)Z ^5o&bag
Try it online!
Returns More
, Same
, Less
for P1 Wins
, Tie
, P2 Wins
.
Explanation
*.map: # Map input lists
&bag # Convert to Bag
o # Pass to block
.1&& # Return 0 if no 1s
max # Maximum of
.2..6 # number of 2s,3s,4s,5s,6s
X+.1 # plus number of 1s
( )Z # zipped with
^5 # secondary key 0,1,2,3,4
&[cmp]o # Compare mapped values
$endgroup$
add a comment |
$begingroup$
T-SQL query, 148 bytes
Using table variable as input
p: player
v: value for roll
DECLARE @ table(p int,v int)
INSERT @ values(1,5),(1,5),(1,5),(1,5),(1,5)
INSERT @ values(2,4),(2,3),(2,3),(2,1),(2,4)
SELECT sign(min(u)+max(u))FROM(SELECT(p*2-3)*(s+sum(sign(s)-1/v))*(s/5*5+v+30)u
FROM(SELECT*,sum(1/v)over(partition by p)s FROM @)c GROUP BY v,s,p)x
Try it online
Player 1 wins returns -1
Tie returns 0
Player 2 wins returns 1
$endgroup$
add a comment |
$begingroup$
Jelly, 21 bytes
crushed before I even posted it by Nick Kennedy :)
’-oÆṃṀ$$Ạ?fÆṃ$L;$o5)M
A monadic Link accepting a list of players which outputs a list of (1-indexed) winners.
So P1 is [1]
, P2 is [2]
and a tie is [1,2]
.
Try it online!
$endgroup$
add a comment |
$begingroup$
Java 8, 244 240 236 215 bytes
a->b->int c[][]=new int[2][7],m[]=new int[2],s,p,i=5;for(;i-->0;c[1][b[i]]++)c[0][a[i]]++;for(i=7;i-->2;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=c[p][1]>0?i+9*(c[p][i]+(i>1?c[p][1]:0)):0;return Long.compare(m[0],m[1]);
-4 bytes thanks to @someone.
-21 bytes thanks to @Neil.
Returns 1
if P1 wins; -1
if P2 wins; 0
if it's a tie.
Try it online.
Explanation:
a->b-> // Method with 2 integer-array parameters & integer return
int c[][]=new int[2][7], // Create a count-array for each value of both players,
// initially filled with 0s
m[]=new int[2], // The maximum per player, initially 0
s,p, // Temp-values for the score and player
i=5;for(;i-->0; // Loop `i` in the range (5, 0]:
c[1] // For player 2:
[b[i] // Get the value of the `i`'th die,
]++) // and increase that score-count by 1
c[0][a[i]]++; // Do the same for player 1
for(i=7;i-->2;) // Then loop `i` in the range (7, 2]:
for(p=2;p-->0 // Inner loop `p` over both players:
; // After every iteration:
m[p]=s>m[p]?s:m[p]) // Update the max score if the current score is higher
s= // Set the current score to:
c[p][1]>0? // If at least one 1 is rolled:
i // Use the current value `i`
+9* // With 9 times the following added:
(c[p][i] // The amount of dice for value `i`
+(i>1? // And if the current die `i` is not 1:
c[p][1]:0))// Add the amount of dice for value 1
:0; // Else (no 1s were rolled): the score is 0
return Long.compare(m[0],m[1]);
// Finally compare the maximum scores of the players,
// resulting in -1 if a<b; 0 if a==b; 1 if a>b
$endgroup$
$begingroup$
In the for loop over p, you can replace...*(c[p][1]>0?1:0)
withc[p][1]>0?...:0
. I canot post a TIO link, as it's too long and I don't want to shorten it. The ungolfed version has unbalanced parentheses somewhere around there.
$endgroup$
– someone
Jun 7 at 0:33
$begingroup$
@someone Ah, of course, thanks. I added thec[p][1]>0?
check later on as bug-fix, but apparently without thinking a lot. Thanks for the -4. :)
$endgroup$
– Kevin Cruijssen
Jun 7 at 6:40
$begingroup$
Why the*(i<2?6:i)
? You're just duplicating effort fori=6
andi=1
. This can be just*i
(and stop looping when you get to 2).
$endgroup$
– Neil
Jun 7 at 8:31
$begingroup$
Also, the9
can be any magic number between5
and about32
, right? If you use8
then instead of(int)Math.pow(8,(...)*i)
you can usei<<3*(...)
.
$endgroup$
– Neil
Jun 7 at 8:34
1
$begingroup$
I ended up witha->b->int c[][]=new int[2][7],m[]=new int[2],s,p,i=5;for(;i-->0;c[1][b[i]]++)c[0][a[i]]++;for(i=7;i-->2;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=c[p][1]>0?i+9*(c[p][i]+(i>1?c[p][1]:0)):0;return Long.compare(m[0],m[1]);
which seems to pass all of your test cases...
$endgroup$
– Neil
Jun 7 at 8:52
|
show 3 more comments
$begingroup$
PowerShell, 112 126 123 121 bytes
Takes input as (a)(b)
. Returns -1
for P1 win, 1
for P2 or 0
for a tie.
$args|%%$m=$_;(7*(($o=($_-eq1).Count)+$m.Count)+$m.Name+6*!$m)[!$o])-$d
[math]::Sign($d)
Try it online!
Test case @( @(1,1,5,1,1), @(1,1,1,1,1), 1)
added.
Unrolled:
$args|%%$max=$_ # $max is an element with the widest group and the maximum digit except 1
$ones=($_-eq1).Count # number of 1s in a player's hand
$scoreRaw=7*($ones+$max.Count)+$max.Name+6*!$max # where $max.Name is digit of the widest group
$scoreRaw[!$ones] # output $scoreRaw if the array contains 1, otherwise output $null
) # powershell deletes all variables created inside the scope on exit
$diff=$score-$diff
[math]::Sign($diff) # output the score difference
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 78 75 74 bytes
-1 byte by Greg Martin
Order@@(#~FreeQ~1||Last@Sort[Reverse/@Tally@Flatten[#/. 1->Range@6]]&)/@#&
Try it online!
Outputs -1 when player 1 wins, 1 when player 2 wins, and 0 for a tie.
Helper function to score a list:
FreeQ[#,1] || If there are 0 1s, score is True
Last@Sort[ Otherwise, take the largest element of
Reverse/@Tally@ the frequency, number pairs in the flat list
Flatten[ #/. 1->Range@6] where each 1 is replaced by 1,2,3,4,5,6.
]& e.g. 1,3,3,5,5 -> 1,2,3,4,5,6,3,3,5,5 -> 3,5
Order @@ (...) /@ #& Apply this function to both lists,
then find the ordering of the result.
$endgroup$
$begingroup$
You can save one byte by replacingFreeQ[#,1]
with#~FreeQ~1
.
$endgroup$
– Greg Martin
Jun 8 at 19:38
add a comment |
$begingroup$
Jelly, 27 bytes
’o5Rṗ5¤ṢŒr$€UẎṀ1e⁸¤×µ€_/Ṡo/
Try it online!
1 for P1, -1 for P2, 0 for tie
Explanation
’o5Rṗ5¤ṢŒr$€UẎṀ1e⁸¤×µ€_/Ṡo/ Main link
µ€ For each list
’ Decrement each value (so 1s become falsy)
o Vectorized logical or (this replaces previous 1s (now 0s) with the test values)
5Rṗ5¤ 1..5 cartesian-power 5 (1,1,1,1,1; 1,1,1,1,2; 1,1,1,1,3; ...)
$€ For each test list
ṢŒr Sort and run-length encode (gives [digit, #digit])
U Reverse each list (gives [#digit, digit])
Ẏ Tighten by one (gives a list containing each possible hand for each possible wildcard)
Ṁ Take the maximum
1e⁸¤× Multiply the list values by (whether or not the original contained a 1) - becomes [0, 0] if not
_/Ṡ Take the sign of the difference between the #digits and the digits
o/ If the number of digits differs, then 1/-1 is returned; otherwise, check the value of the digit (could still be 0)
$endgroup$
add a comment |
$begingroup$
Sledgehammer 0.4, 27 bytes
⢱⢙⢂⠠⡾⢃⠐⢈⠸⣞⠴⠻⠎⡥⡳⡐⢒⠘⢛⣩⡓⣮⡕⡠⣢⣡⠿
Decompresses into this Wolfram Language function:
Order @@ (FreeQ[#1, 1] || Last[Sort[Reverse[Tally[Flatten[#1 /. 1 -> Range[6]]], 2]]] & ) /@ #1 &
which turns out to be exactly the same as my Mathematica answer.
$endgroup$
add a comment |
$begingroup$
Charcoal, 48 45 bytes
UMθ⮌E⁷№ι∨λ¹UMθ׬¬⊟ι⁺⊟ιιUMθ⟦⌈ι±⌕ι⌈ι⟧I⁻⌕θ⌈θ⌕θ⌊θ
Try it online! Link is to verbose version of code. Takes input as an array of arrays and outputs -1
if player 1 wins, 0
for a tie, and 1
if player 2 wins. Explanation:
UMθ⮌E⁷№ι∨λ¹
Replace each hand with the count of how many times the values 6..1
appear in the hand. The list is reversed because a) it makes it easier to find the highest value with the highest count and b) it makes it easier to remove the count of 1
s. The count of 1
s is doubled because it needs to be removed twice, once to check that it is nonzero and once to add it to the other counts.
UMθ׬¬⊟ι⁺⊟ιι
Add the count of 1
s to the counts for 6..2
, but set all of the counts to zero if the count of 1
s was zero.
UMθ⟦⌈ι±⌕ι⌈ι⟧
For each hand find the highest count and the highest value with that count. (Actually we find value minus 6
as that's golfier.)
I⁻⌕θ⌈θ⌕θ⌊θ
Determine which hand won by subtracting the positions of the winning and losing hands. (If the hands are tied then the first hand is both winning and losing so the result is 0
as desired.)
$endgroup$
add a comment |
$begingroup$
C (gcc) / 32 bit, 117 bytes
t;m;s(int*r)int c[6]=;for(m=0;t=*r++;m=t>m?t:m)c[--t]+=5,t=t?c[t]+t:5;t=*c?*c+m:0;f(a,b)t=s(a)-s(b);t=(t>0)-!t;
Try it online!
Takes two zero-terminated integer arrays. Returns 1
, 0
, -1
for P1 Wins
, P2 Wins
, Tie
.
$endgroup$
1
$begingroup$
@Veskah OK, fixed.
$endgroup$
– nwellnhof
Jun 7 at 18:12
add a comment |
$begingroup$
J, 47 44 bytes
*@-&([:(.([:>./#@]+9^*@[*+).)1#.i.@6=/<:)
Try it online!
Inspired by Nick Kennedy's idea.
ungolfed
*@-&([: (. ([: >./ #@] + 9 ^ *@[ * +) .) 1 #. i.@6 =/ <:)
$endgroup$
add a comment |
$begingroup$
Perl 5 -MList::Util=max -pl
, 80 bytes
sub t$_=t($_)<=>t<>
Try it online!
Input:
Each player on a separate line, no spaces
Output:
1
Line one wins
0
Tie
-1
Line two wins
$endgroup$
1
$begingroup$
Changed based on your clarification of the rules of the game
$endgroup$
– Xcali
Jun 10 at 0:52
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "200"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f186456%2fwho-won-a-game-of-bar-dice%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
17 Answers
17
active
oldest
votes
17 Answers
17
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Jelly, 17 14 bytes
ċⱮ6Ḣ©+$®aĖUṀ)M
Try it online!
A monadic link that takes a list of the two lists as its argument and returns [1]
for player 1 wins, [2]
for player 2 wins and [1, 2]
for a tie. TIO link tidies this up for display.
Thanks to @JonathanAllan for saving 3 bytes!
Explanation
) | For each input list (e.g. of one list 1,1,3,3,4)
ċⱮ6 | - Count each of 1..6 (e.g. 2,0,2,1,0,0)
$ | - Following as a monad:
Ḣ | - Head (number of 1s)
©︎ | - Copy to register
+ | - Add (e.g. 2,4,3,0,0)
®a | - Register logical and with this
Ė | - Enumerate (e.g. [1,2],[2,4],[3,3],[4,0],[5,0])
U | - Reverse each (e.g. [2,1],[4,2],[3,3],[0,4],[0,5])
Ṁ | - Max (e.g. 4,2)
M | Index/indices of maximal score
$endgroup$
1
$begingroup$
You could replace theIṠ
withM
and output a list of the winner(s).
$endgroup$
– Jonathan Allan
Jun 6 at 17:51
$begingroup$
@JonathanAllan Good point! Thanks
$endgroup$
– Nick Kennedy
Jun 6 at 17:54
1
$begingroup$
15 bytes by making use of the register.
$endgroup$
– Jonathan Allan
Jun 6 at 18:08
1
$begingroup$
I think theḌ
may now be redundant too since the lists sort the same as the integers.
$endgroup$
– Jonathan Allan
Jun 6 at 18:14
1
$begingroup$
This is a lovely approach. Well done.
$endgroup$
– Jonah
Jun 7 at 14:44
add a comment |
$begingroup$
Jelly, 17 14 bytes
ċⱮ6Ḣ©+$®aĖUṀ)M
Try it online!
A monadic link that takes a list of the two lists as its argument and returns [1]
for player 1 wins, [2]
for player 2 wins and [1, 2]
for a tie. TIO link tidies this up for display.
Thanks to @JonathanAllan for saving 3 bytes!
Explanation
) | For each input list (e.g. of one list 1,1,3,3,4)
ċⱮ6 | - Count each of 1..6 (e.g. 2,0,2,1,0,0)
$ | - Following as a monad:
Ḣ | - Head (number of 1s)
©︎ | - Copy to register
+ | - Add (e.g. 2,4,3,0,0)
®a | - Register logical and with this
Ė | - Enumerate (e.g. [1,2],[2,4],[3,3],[4,0],[5,0])
U | - Reverse each (e.g. [2,1],[4,2],[3,3],[0,4],[0,5])
Ṁ | - Max (e.g. 4,2)
M | Index/indices of maximal score
$endgroup$
1
$begingroup$
You could replace theIṠ
withM
and output a list of the winner(s).
$endgroup$
– Jonathan Allan
Jun 6 at 17:51
$begingroup$
@JonathanAllan Good point! Thanks
$endgroup$
– Nick Kennedy
Jun 6 at 17:54
1
$begingroup$
15 bytes by making use of the register.
$endgroup$
– Jonathan Allan
Jun 6 at 18:08
1
$begingroup$
I think theḌ
may now be redundant too since the lists sort the same as the integers.
$endgroup$
– Jonathan Allan
Jun 6 at 18:14
1
$begingroup$
This is a lovely approach. Well done.
$endgroup$
– Jonah
Jun 7 at 14:44
add a comment |
$begingroup$
Jelly, 17 14 bytes
ċⱮ6Ḣ©+$®aĖUṀ)M
Try it online!
A monadic link that takes a list of the two lists as its argument and returns [1]
for player 1 wins, [2]
for player 2 wins and [1, 2]
for a tie. TIO link tidies this up for display.
Thanks to @JonathanAllan for saving 3 bytes!
Explanation
) | For each input list (e.g. of one list 1,1,3,3,4)
ċⱮ6 | - Count each of 1..6 (e.g. 2,0,2,1,0,0)
$ | - Following as a monad:
Ḣ | - Head (number of 1s)
©︎ | - Copy to register
+ | - Add (e.g. 2,4,3,0,0)
®a | - Register logical and with this
Ė | - Enumerate (e.g. [1,2],[2,4],[3,3],[4,0],[5,0])
U | - Reverse each (e.g. [2,1],[4,2],[3,3],[0,4],[0,5])
Ṁ | - Max (e.g. 4,2)
M | Index/indices of maximal score
$endgroup$
Jelly, 17 14 bytes
ċⱮ6Ḣ©+$®aĖUṀ)M
Try it online!
A monadic link that takes a list of the two lists as its argument and returns [1]
for player 1 wins, [2]
for player 2 wins and [1, 2]
for a tie. TIO link tidies this up for display.
Thanks to @JonathanAllan for saving 3 bytes!
Explanation
) | For each input list (e.g. of one list 1,1,3,3,4)
ċⱮ6 | - Count each of 1..6 (e.g. 2,0,2,1,0,0)
$ | - Following as a monad:
Ḣ | - Head (number of 1s)
©︎ | - Copy to register
+ | - Add (e.g. 2,4,3,0,0)
®a | - Register logical and with this
Ė | - Enumerate (e.g. [1,2],[2,4],[3,3],[4,0],[5,0])
U | - Reverse each (e.g. [2,1],[4,2],[3,3],[0,4],[0,5])
Ṁ | - Max (e.g. 4,2)
M | Index/indices of maximal score
edited Jun 6 at 18:15
answered Jun 6 at 17:24
Nick KennedyNick Kennedy
3,3996 silver badges10 bronze badges
3,3996 silver badges10 bronze badges
1
$begingroup$
You could replace theIṠ
withM
and output a list of the winner(s).
$endgroup$
– Jonathan Allan
Jun 6 at 17:51
$begingroup$
@JonathanAllan Good point! Thanks
$endgroup$
– Nick Kennedy
Jun 6 at 17:54
1
$begingroup$
15 bytes by making use of the register.
$endgroup$
– Jonathan Allan
Jun 6 at 18:08
1
$begingroup$
I think theḌ
may now be redundant too since the lists sort the same as the integers.
$endgroup$
– Jonathan Allan
Jun 6 at 18:14
1
$begingroup$
This is a lovely approach. Well done.
$endgroup$
– Jonah
Jun 7 at 14:44
add a comment |
1
$begingroup$
You could replace theIṠ
withM
and output a list of the winner(s).
$endgroup$
– Jonathan Allan
Jun 6 at 17:51
$begingroup$
@JonathanAllan Good point! Thanks
$endgroup$
– Nick Kennedy
Jun 6 at 17:54
1
$begingroup$
15 bytes by making use of the register.
$endgroup$
– Jonathan Allan
Jun 6 at 18:08
1
$begingroup$
I think theḌ
may now be redundant too since the lists sort the same as the integers.
$endgroup$
– Jonathan Allan
Jun 6 at 18:14
1
$begingroup$
This is a lovely approach. Well done.
$endgroup$
– Jonah
Jun 7 at 14:44
1
1
$begingroup$
You could replace the
IṠ
with M
and output a list of the winner(s).$endgroup$
– Jonathan Allan
Jun 6 at 17:51
$begingroup$
You could replace the
IṠ
with M
and output a list of the winner(s).$endgroup$
– Jonathan Allan
Jun 6 at 17:51
$begingroup$
@JonathanAllan Good point! Thanks
$endgroup$
– Nick Kennedy
Jun 6 at 17:54
$begingroup$
@JonathanAllan Good point! Thanks
$endgroup$
– Nick Kennedy
Jun 6 at 17:54
1
1
$begingroup$
15 bytes by making use of the register.
$endgroup$
– Jonathan Allan
Jun 6 at 18:08
$begingroup$
15 bytes by making use of the register.
$endgroup$
– Jonathan Allan
Jun 6 at 18:08
1
1
$begingroup$
I think the
Ḍ
may now be redundant too since the lists sort the same as the integers.$endgroup$
– Jonathan Allan
Jun 6 at 18:14
$begingroup$
I think the
Ḍ
may now be redundant too since the lists sort the same as the integers.$endgroup$
– Jonathan Allan
Jun 6 at 18:14
1
1
$begingroup$
This is a lovely approach. Well done.
$endgroup$
– Jonah
Jun 7 at 14:44
$begingroup$
This is a lovely approach. Well done.
$endgroup$
– Jonah
Jun 7 at 14:44
add a comment |
$begingroup$
R, 115 96 bytes
-6 bytes thanks to Giuseppe.
-6 bytes thanks to Aaron Hayman.
-2 bytes thanks to Arnauld, following the output format in his JavaScript answer.
function(i,j)(f(i)-f(j))/0
f=function(x,s=tabulate(x,6),l=s[1]+s[-1]*!!s[1])max(l)*6+order(l)[5]
Try it online!
Returns Inf
for P1, NaN
for a tie, -Inf
for P2.
Uses the helper function f
which computes a score for each hand. The score is defined as follows: let d
be the digit which is repeated the most, and n
the number of times it is repeated. Then the score is 6*n+d
if there is at least one ace, and 0
if there are no aces. We then just need to find the player with the highest score.
Ungolfed:
f = function(x)
s = tabulate(x, 6) # number of occurrences of each integer
l = s[1] + s[-1] * !!s[1] # add the number of wild aces to all values; set to 0 if s[1] == 0
max(l) * 6 + # highest number of repetitions (apart from aces)
order(l)[5] # most repeated integer (take largest in case of tie)
function(i, j)
sign(f(i) - f(j))
$endgroup$
$begingroup$
You can useorder(l)[5]
instead ofmax.col(t(l),"l")
to get a 96 byte solution: Try it online!
$endgroup$
– Aaron Hayman
Jun 7 at 14:25
$begingroup$
@AaronHayman Very nice, thanks!
$endgroup$
– Robin Ryder
Jun 7 at 14:33
add a comment |
$begingroup$
R, 115 96 bytes
-6 bytes thanks to Giuseppe.
-6 bytes thanks to Aaron Hayman.
-2 bytes thanks to Arnauld, following the output format in his JavaScript answer.
function(i,j)(f(i)-f(j))/0
f=function(x,s=tabulate(x,6),l=s[1]+s[-1]*!!s[1])max(l)*6+order(l)[5]
Try it online!
Returns Inf
for P1, NaN
for a tie, -Inf
for P2.
Uses the helper function f
which computes a score for each hand. The score is defined as follows: let d
be the digit which is repeated the most, and n
the number of times it is repeated. Then the score is 6*n+d
if there is at least one ace, and 0
if there are no aces. We then just need to find the player with the highest score.
Ungolfed:
f = function(x)
s = tabulate(x, 6) # number of occurrences of each integer
l = s[1] + s[-1] * !!s[1] # add the number of wild aces to all values; set to 0 if s[1] == 0
max(l) * 6 + # highest number of repetitions (apart from aces)
order(l)[5] # most repeated integer (take largest in case of tie)
function(i, j)
sign(f(i) - f(j))
$endgroup$
$begingroup$
You can useorder(l)[5]
instead ofmax.col(t(l),"l")
to get a 96 byte solution: Try it online!
$endgroup$
– Aaron Hayman
Jun 7 at 14:25
$begingroup$
@AaronHayman Very nice, thanks!
$endgroup$
– Robin Ryder
Jun 7 at 14:33
add a comment |
$begingroup$
R, 115 96 bytes
-6 bytes thanks to Giuseppe.
-6 bytes thanks to Aaron Hayman.
-2 bytes thanks to Arnauld, following the output format in his JavaScript answer.
function(i,j)(f(i)-f(j))/0
f=function(x,s=tabulate(x,6),l=s[1]+s[-1]*!!s[1])max(l)*6+order(l)[5]
Try it online!
Returns Inf
for P1, NaN
for a tie, -Inf
for P2.
Uses the helper function f
which computes a score for each hand. The score is defined as follows: let d
be the digit which is repeated the most, and n
the number of times it is repeated. Then the score is 6*n+d
if there is at least one ace, and 0
if there are no aces. We then just need to find the player with the highest score.
Ungolfed:
f = function(x)
s = tabulate(x, 6) # number of occurrences of each integer
l = s[1] + s[-1] * !!s[1] # add the number of wild aces to all values; set to 0 if s[1] == 0
max(l) * 6 + # highest number of repetitions (apart from aces)
order(l)[5] # most repeated integer (take largest in case of tie)
function(i, j)
sign(f(i) - f(j))
$endgroup$
R, 115 96 bytes
-6 bytes thanks to Giuseppe.
-6 bytes thanks to Aaron Hayman.
-2 bytes thanks to Arnauld, following the output format in his JavaScript answer.
function(i,j)(f(i)-f(j))/0
f=function(x,s=tabulate(x,6),l=s[1]+s[-1]*!!s[1])max(l)*6+order(l)[5]
Try it online!
Returns Inf
for P1, NaN
for a tie, -Inf
for P2.
Uses the helper function f
which computes a score for each hand. The score is defined as follows: let d
be the digit which is repeated the most, and n
the number of times it is repeated. Then the score is 6*n+d
if there is at least one ace, and 0
if there are no aces. We then just need to find the player with the highest score.
Ungolfed:
f = function(x)
s = tabulate(x, 6) # number of occurrences of each integer
l = s[1] + s[-1] * !!s[1] # add the number of wild aces to all values; set to 0 if s[1] == 0
max(l) * 6 + # highest number of repetitions (apart from aces)
order(l)[5] # most repeated integer (take largest in case of tie)
function(i, j)
sign(f(i) - f(j))
edited Jun 7 at 14:33
answered Jun 6 at 13:30
Robin RyderRobin Ryder
1,7982 silver badges17 bronze badges
1,7982 silver badges17 bronze badges
$begingroup$
You can useorder(l)[5]
instead ofmax.col(t(l),"l")
to get a 96 byte solution: Try it online!
$endgroup$
– Aaron Hayman
Jun 7 at 14:25
$begingroup$
@AaronHayman Very nice, thanks!
$endgroup$
– Robin Ryder
Jun 7 at 14:33
add a comment |
$begingroup$
You can useorder(l)[5]
instead ofmax.col(t(l),"l")
to get a 96 byte solution: Try it online!
$endgroup$
– Aaron Hayman
Jun 7 at 14:25
$begingroup$
@AaronHayman Very nice, thanks!
$endgroup$
– Robin Ryder
Jun 7 at 14:33
$begingroup$
You can use
order(l)[5]
instead of max.col(t(l),"l")
to get a 96 byte solution: Try it online!$endgroup$
– Aaron Hayman
Jun 7 at 14:25
$begingroup$
You can use
order(l)[5]
instead of max.col(t(l),"l")
to get a 96 byte solution: Try it online!$endgroup$
– Aaron Hayman
Jun 7 at 14:25
$begingroup$
@AaronHayman Very nice, thanks!
$endgroup$
– Robin Ryder
Jun 7 at 14:33
$begingroup$
@AaronHayman Very nice, thanks!
$endgroup$
– Robin Ryder
Jun 7 at 14:33
add a comment |
$begingroup$
JavaScript (ES6), 97 90 bytes
Takes input as (a)(b)
. Returns +Infinity
for P1, -Infinity
for P2 or NaN
for a tie.
a=>b=>((g=(x,m)=>x>6?m*/1/.test(a):g(-~x,a.map(k=>n+=k<2|k==x,n=x/6)|m>n?m:n))()-g(a=b))/0
Try it online!
Commented
a => b => ( // a[] = dice of P1; b[] = dice of P2
( g = ( // g is a recursive function taking:
x, // x = dice value to test; initially, it is either undefined
// or set to a non-numeric value
m // m = maximum score so far, initially undefined
) => //
x > 6 ? // if x is greater than 6:
m * /1/.test(a) // return m, or 0 if a[] does not contain any 1
: // else:
g( // do a recursive call:
-~x, // increment x (or set it to 1 if it's non-numeric)
a.map(k => // for each dice value k in a[]:
n += // add 1 to n if:
k < 2 | // k is equal to 1
k == x, // or k is equal to x
n = x / 6 // start with n = x / 6
) | // end of map()
m > n ? // if m is defined and greater than n:
m // pass m unchanged
: // else:
n // update m to n
) // end of recursive call
)() // first call to g, using a[]
- g(a = b) // subtract the result of a 2nd call, using b[]
) / 0 // divide by 0 to force one of the 3 consistent output values
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 97 90 bytes
Takes input as (a)(b)
. Returns +Infinity
for P1, -Infinity
for P2 or NaN
for a tie.
a=>b=>((g=(x,m)=>x>6?m*/1/.test(a):g(-~x,a.map(k=>n+=k<2|k==x,n=x/6)|m>n?m:n))()-g(a=b))/0
Try it online!
Commented
a => b => ( // a[] = dice of P1; b[] = dice of P2
( g = ( // g is a recursive function taking:
x, // x = dice value to test; initially, it is either undefined
// or set to a non-numeric value
m // m = maximum score so far, initially undefined
) => //
x > 6 ? // if x is greater than 6:
m * /1/.test(a) // return m, or 0 if a[] does not contain any 1
: // else:
g( // do a recursive call:
-~x, // increment x (or set it to 1 if it's non-numeric)
a.map(k => // for each dice value k in a[]:
n += // add 1 to n if:
k < 2 | // k is equal to 1
k == x, // or k is equal to x
n = x / 6 // start with n = x / 6
) | // end of map()
m > n ? // if m is defined and greater than n:
m // pass m unchanged
: // else:
n // update m to n
) // end of recursive call
)() // first call to g, using a[]
- g(a = b) // subtract the result of a 2nd call, using b[]
) / 0 // divide by 0 to force one of the 3 consistent output values
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 97 90 bytes
Takes input as (a)(b)
. Returns +Infinity
for P1, -Infinity
for P2 or NaN
for a tie.
a=>b=>((g=(x,m)=>x>6?m*/1/.test(a):g(-~x,a.map(k=>n+=k<2|k==x,n=x/6)|m>n?m:n))()-g(a=b))/0
Try it online!
Commented
a => b => ( // a[] = dice of P1; b[] = dice of P2
( g = ( // g is a recursive function taking:
x, // x = dice value to test; initially, it is either undefined
// or set to a non-numeric value
m // m = maximum score so far, initially undefined
) => //
x > 6 ? // if x is greater than 6:
m * /1/.test(a) // return m, or 0 if a[] does not contain any 1
: // else:
g( // do a recursive call:
-~x, // increment x (or set it to 1 if it's non-numeric)
a.map(k => // for each dice value k in a[]:
n += // add 1 to n if:
k < 2 | // k is equal to 1
k == x, // or k is equal to x
n = x / 6 // start with n = x / 6
) | // end of map()
m > n ? // if m is defined and greater than n:
m // pass m unchanged
: // else:
n // update m to n
) // end of recursive call
)() // first call to g, using a[]
- g(a = b) // subtract the result of a 2nd call, using b[]
) / 0 // divide by 0 to force one of the 3 consistent output values
$endgroup$
JavaScript (ES6), 97 90 bytes
Takes input as (a)(b)
. Returns +Infinity
for P1, -Infinity
for P2 or NaN
for a tie.
a=>b=>((g=(x,m)=>x>6?m*/1/.test(a):g(-~x,a.map(k=>n+=k<2|k==x,n=x/6)|m>n?m:n))()-g(a=b))/0
Try it online!
Commented
a => b => ( // a[] = dice of P1; b[] = dice of P2
( g = ( // g is a recursive function taking:
x, // x = dice value to test; initially, it is either undefined
// or set to a non-numeric value
m // m = maximum score so far, initially undefined
) => //
x > 6 ? // if x is greater than 6:
m * /1/.test(a) // return m, or 0 if a[] does not contain any 1
: // else:
g( // do a recursive call:
-~x, // increment x (or set it to 1 if it's non-numeric)
a.map(k => // for each dice value k in a[]:
n += // add 1 to n if:
k < 2 | // k is equal to 1
k == x, // or k is equal to x
n = x / 6 // start with n = x / 6
) | // end of map()
m > n ? // if m is defined and greater than n:
m // pass m unchanged
: // else:
n // update m to n
) // end of recursive call
)() // first call to g, using a[]
- g(a = b) // subtract the result of a 2nd call, using b[]
) / 0 // divide by 0 to force one of the 3 consistent output values
edited Jun 6 at 16:32
answered Jun 6 at 14:03
ArnauldArnauld
86.4k7 gold badges102 silver badges353 bronze badges
86.4k7 gold badges102 silver badges353 bronze badges
add a comment |
add a comment |
$begingroup$
05AB1E, 16 15 bytes
-1 byte thanks to JonathanAllan
εWΘ*6L¢ć+°ƶà}ZQ
Try it online!
Returns [1, 0] for P1 wins, [1, 1] for ties, [0, 1] for P2 wins.
Rather than using lexicographic order on a 2-tuple (dice count, dice value), this computes the score as 10**dice count * dice value. Hands without a 1 score 5.
ε } # map each hand to its computed score
WΘ # minimum == 1 (1 if the hand contains a 1, 0 otherwise)
* # multiply (sets hands without 1 to [0, 0, 0, 0, 0])
6L # range [1..6]
¢ # count occurences of each in the hand
ć # head extract (stack is now [2-count, ..., 6-count], 1-count)
+ # add the 1-count to all the other counts
° # 10**x
ƶ # multiply each element by its 1-based index
à # take the maximum
Z # maximum
Q # equality test (vectorizes)
$endgroup$
1
$begingroup$
Ohhh.. I like theć+
(now that I see it I cannot believe I hadn't thought about it..)! That's so much better than what I was attempting.. I did had a similar idea with°
. :) Except that I was already at 20 bytes and still had to fix an issue for test case[[1,1,1,1,1],] [6,1,1,6,6]]
.. So thanks for saving me time so I can put my attempt in the garbage bin.. ;p
$endgroup$
– Kevin Cruijssen
Jun 6 at 13:55
1
$begingroup$
@KevinCruijssen Yeah it's amazing how wellć+
works. My initial idea started withæʒW}ʒ1KË
, but this gets killed by the[1,1,1,1,1]
issue.
$endgroup$
– Grimy
Jun 6 at 14:08
1
$begingroup$
Yeah, my approach was along the lines ofε1¢©Āyγéθ¬sg®+°P`.S
, but the[1,1,1,1,1]
screwed that over as well indeed. Your entire answer got a nice synergy with theWΘ*
,6L¢
,ć+
, and°ƶ
. Especially the builtinsWćƶ
really show their strength here.
$endgroup$
– Kevin Cruijssen
Jun 6 at 14:30
$begingroup$
W
isn't actually needed,6L¢¬Ā*
is the same byte-count asWΘ*6L¢
.
$endgroup$
– Grimy
Jun 6 at 14:38
$begingroup$
Hmm, good point. :) ThoughtW
without popping and then*
showed it's strength, but¬
without popping and then*
is basically the same. The fact that it doesn't pop is the strength I was implying to, saving a byte. But it's indeed mainlyćƶ
.
$endgroup$
– Kevin Cruijssen
Jun 6 at 14:40
add a comment |
$begingroup$
05AB1E, 16 15 bytes
-1 byte thanks to JonathanAllan
εWΘ*6L¢ć+°ƶà}ZQ
Try it online!
Returns [1, 0] for P1 wins, [1, 1] for ties, [0, 1] for P2 wins.
Rather than using lexicographic order on a 2-tuple (dice count, dice value), this computes the score as 10**dice count * dice value. Hands without a 1 score 5.
ε } # map each hand to its computed score
WΘ # minimum == 1 (1 if the hand contains a 1, 0 otherwise)
* # multiply (sets hands without 1 to [0, 0, 0, 0, 0])
6L # range [1..6]
¢ # count occurences of each in the hand
ć # head extract (stack is now [2-count, ..., 6-count], 1-count)
+ # add the 1-count to all the other counts
° # 10**x
ƶ # multiply each element by its 1-based index
à # take the maximum
Z # maximum
Q # equality test (vectorizes)
$endgroup$
1
$begingroup$
Ohhh.. I like theć+
(now that I see it I cannot believe I hadn't thought about it..)! That's so much better than what I was attempting.. I did had a similar idea with°
. :) Except that I was already at 20 bytes and still had to fix an issue for test case[[1,1,1,1,1],] [6,1,1,6,6]]
.. So thanks for saving me time so I can put my attempt in the garbage bin.. ;p
$endgroup$
– Kevin Cruijssen
Jun 6 at 13:55
1
$begingroup$
@KevinCruijssen Yeah it's amazing how wellć+
works. My initial idea started withæʒW}ʒ1KË
, but this gets killed by the[1,1,1,1,1]
issue.
$endgroup$
– Grimy
Jun 6 at 14:08
1
$begingroup$
Yeah, my approach was along the lines ofε1¢©Āyγéθ¬sg®+°P`.S
, but the[1,1,1,1,1]
screwed that over as well indeed. Your entire answer got a nice synergy with theWΘ*
,6L¢
,ć+
, and°ƶ
. Especially the builtinsWćƶ
really show their strength here.
$endgroup$
– Kevin Cruijssen
Jun 6 at 14:30
$begingroup$
W
isn't actually needed,6L¢¬Ā*
is the same byte-count asWΘ*6L¢
.
$endgroup$
– Grimy
Jun 6 at 14:38
$begingroup$
Hmm, good point. :) ThoughtW
without popping and then*
showed it's strength, but¬
without popping and then*
is basically the same. The fact that it doesn't pop is the strength I was implying to, saving a byte. But it's indeed mainlyćƶ
.
$endgroup$
– Kevin Cruijssen
Jun 6 at 14:40
add a comment |
$begingroup$
05AB1E, 16 15 bytes
-1 byte thanks to JonathanAllan
εWΘ*6L¢ć+°ƶà}ZQ
Try it online!
Returns [1, 0] for P1 wins, [1, 1] for ties, [0, 1] for P2 wins.
Rather than using lexicographic order on a 2-tuple (dice count, dice value), this computes the score as 10**dice count * dice value. Hands without a 1 score 5.
ε } # map each hand to its computed score
WΘ # minimum == 1 (1 if the hand contains a 1, 0 otherwise)
* # multiply (sets hands without 1 to [0, 0, 0, 0, 0])
6L # range [1..6]
¢ # count occurences of each in the hand
ć # head extract (stack is now [2-count, ..., 6-count], 1-count)
+ # add the 1-count to all the other counts
° # 10**x
ƶ # multiply each element by its 1-based index
à # take the maximum
Z # maximum
Q # equality test (vectorizes)
$endgroup$
05AB1E, 16 15 bytes
-1 byte thanks to JonathanAllan
εWΘ*6L¢ć+°ƶà}ZQ
Try it online!
Returns [1, 0] for P1 wins, [1, 1] for ties, [0, 1] for P2 wins.
Rather than using lexicographic order on a 2-tuple (dice count, dice value), this computes the score as 10**dice count * dice value. Hands without a 1 score 5.
ε } # map each hand to its computed score
WΘ # minimum == 1 (1 if the hand contains a 1, 0 otherwise)
* # multiply (sets hands without 1 to [0, 0, 0, 0, 0])
6L # range [1..6]
¢ # count occurences of each in the hand
ć # head extract (stack is now [2-count, ..., 6-count], 1-count)
+ # add the 1-count to all the other counts
° # 10**x
ƶ # multiply each element by its 1-based index
à # take the maximum
Z # maximum
Q # equality test (vectorizes)
edited Jun 6 at 21:20
answered Jun 6 at 13:48
GrimyGrimy
4,54112 silver badges26 bronze badges
4,54112 silver badges26 bronze badges
1
$begingroup$
Ohhh.. I like theć+
(now that I see it I cannot believe I hadn't thought about it..)! That's so much better than what I was attempting.. I did had a similar idea with°
. :) Except that I was already at 20 bytes and still had to fix an issue for test case[[1,1,1,1,1],] [6,1,1,6,6]]
.. So thanks for saving me time so I can put my attempt in the garbage bin.. ;p
$endgroup$
– Kevin Cruijssen
Jun 6 at 13:55
1
$begingroup$
@KevinCruijssen Yeah it's amazing how wellć+
works. My initial idea started withæʒW}ʒ1KË
, but this gets killed by the[1,1,1,1,1]
issue.
$endgroup$
– Grimy
Jun 6 at 14:08
1
$begingroup$
Yeah, my approach was along the lines ofε1¢©Āyγéθ¬sg®+°P`.S
, but the[1,1,1,1,1]
screwed that over as well indeed. Your entire answer got a nice synergy with theWΘ*
,6L¢
,ć+
, and°ƶ
. Especially the builtinsWćƶ
really show their strength here.
$endgroup$
– Kevin Cruijssen
Jun 6 at 14:30
$begingroup$
W
isn't actually needed,6L¢¬Ā*
is the same byte-count asWΘ*6L¢
.
$endgroup$
– Grimy
Jun 6 at 14:38
$begingroup$
Hmm, good point. :) ThoughtW
without popping and then*
showed it's strength, but¬
without popping and then*
is basically the same. The fact that it doesn't pop is the strength I was implying to, saving a byte. But it's indeed mainlyćƶ
.
$endgroup$
– Kevin Cruijssen
Jun 6 at 14:40
add a comment |
1
$begingroup$
Ohhh.. I like theć+
(now that I see it I cannot believe I hadn't thought about it..)! That's so much better than what I was attempting.. I did had a similar idea with°
. :) Except that I was already at 20 bytes and still had to fix an issue for test case[[1,1,1,1,1],] [6,1,1,6,6]]
.. So thanks for saving me time so I can put my attempt in the garbage bin.. ;p
$endgroup$
– Kevin Cruijssen
Jun 6 at 13:55
1
$begingroup$
@KevinCruijssen Yeah it's amazing how wellć+
works. My initial idea started withæʒW}ʒ1KË
, but this gets killed by the[1,1,1,1,1]
issue.
$endgroup$
– Grimy
Jun 6 at 14:08
1
$begingroup$
Yeah, my approach was along the lines ofε1¢©Āyγéθ¬sg®+°P`.S
, but the[1,1,1,1,1]
screwed that over as well indeed. Your entire answer got a nice synergy with theWΘ*
,6L¢
,ć+
, and°ƶ
. Especially the builtinsWćƶ
really show their strength here.
$endgroup$
– Kevin Cruijssen
Jun 6 at 14:30
$begingroup$
W
isn't actually needed,6L¢¬Ā*
is the same byte-count asWΘ*6L¢
.
$endgroup$
– Grimy
Jun 6 at 14:38
$begingroup$
Hmm, good point. :) ThoughtW
without popping and then*
showed it's strength, but¬
without popping and then*
is basically the same. The fact that it doesn't pop is the strength I was implying to, saving a byte. But it's indeed mainlyćƶ
.
$endgroup$
– Kevin Cruijssen
Jun 6 at 14:40
1
1
$begingroup$
Ohhh.. I like the
ć+
(now that I see it I cannot believe I hadn't thought about it..)! That's so much better than what I was attempting.. I did had a similar idea with °
. :) Except that I was already at 20 bytes and still had to fix an issue for test case [[1,1,1,1,1],] [6,1,1,6,6]]
.. So thanks for saving me time so I can put my attempt in the garbage bin.. ;p$endgroup$
– Kevin Cruijssen
Jun 6 at 13:55
$begingroup$
Ohhh.. I like the
ć+
(now that I see it I cannot believe I hadn't thought about it..)! That's so much better than what I was attempting.. I did had a similar idea with °
. :) Except that I was already at 20 bytes and still had to fix an issue for test case [[1,1,1,1,1],] [6,1,1,6,6]]
.. So thanks for saving me time so I can put my attempt in the garbage bin.. ;p$endgroup$
– Kevin Cruijssen
Jun 6 at 13:55
1
1
$begingroup$
@KevinCruijssen Yeah it's amazing how well
ć+
works. My initial idea started with æʒW}ʒ1KË
, but this gets killed by the [1,1,1,1,1]
issue.$endgroup$
– Grimy
Jun 6 at 14:08
$begingroup$
@KevinCruijssen Yeah it's amazing how well
ć+
works. My initial idea started with æʒW}ʒ1KË
, but this gets killed by the [1,1,1,1,1]
issue.$endgroup$
– Grimy
Jun 6 at 14:08
1
1
$begingroup$
Yeah, my approach was along the lines of
ε1¢©Āyγéθ¬sg®+°P`.S
, but the [1,1,1,1,1]
screwed that over as well indeed. Your entire answer got a nice synergy with the WΘ*
, 6L¢
, ć+
, and °ƶ
. Especially the builtins Wćƶ
really show their strength here.$endgroup$
– Kevin Cruijssen
Jun 6 at 14:30
$begingroup$
Yeah, my approach was along the lines of
ε1¢©Āyγéθ¬sg®+°P`.S
, but the [1,1,1,1,1]
screwed that over as well indeed. Your entire answer got a nice synergy with the WΘ*
, 6L¢
, ć+
, and °ƶ
. Especially the builtins Wćƶ
really show their strength here.$endgroup$
– Kevin Cruijssen
Jun 6 at 14:30
$begingroup$
W
isn't actually needed, 6L¢¬Ā*
is the same byte-count as WΘ*6L¢
.$endgroup$
– Grimy
Jun 6 at 14:38
$begingroup$
W
isn't actually needed, 6L¢¬Ā*
is the same byte-count as WΘ*6L¢
.$endgroup$
– Grimy
Jun 6 at 14:38
$begingroup$
Hmm, good point. :) Thought
W
without popping and then *
showed it's strength, but ¬
without popping and then *
is basically the same. The fact that it doesn't pop is the strength I was implying to, saving a byte. But it's indeed mainly ćƶ
.$endgroup$
– Kevin Cruijssen
Jun 6 at 14:40
$begingroup$
Hmm, good point. :) Thought
W
without popping and then *
showed it's strength, but ¬
without popping and then *
is basically the same. The fact that it doesn't pop is the strength I was implying to, saving a byte. But it's indeed mainly ćƶ
.$endgroup$
– Kevin Cruijssen
Jun 6 at 14:40
add a comment |
$begingroup$
Python 2, 85 81 80 bytes
lambda p:cmp(*[max((h.count(i)+h.count(i>1),i)*(1in h)for i in[6]+h)for h in p])
Try it online!
Returns 1
for P1, 0
for tie, and -1
for P2.
-1 byte, thanks to squid
$endgroup$
1
$begingroup$
Whitespace between1
andin
can go
$endgroup$
– squid
Jun 6 at 15:25
$begingroup$
@squid Thanks, :)
$endgroup$
– TFeld
Jun 7 at 6:49
add a comment |
$begingroup$
Python 2, 85 81 80 bytes
lambda p:cmp(*[max((h.count(i)+h.count(i>1),i)*(1in h)for i in[6]+h)for h in p])
Try it online!
Returns 1
for P1, 0
for tie, and -1
for P2.
-1 byte, thanks to squid
$endgroup$
1
$begingroup$
Whitespace between1
andin
can go
$endgroup$
– squid
Jun 6 at 15:25
$begingroup$
@squid Thanks, :)
$endgroup$
– TFeld
Jun 7 at 6:49
add a comment |
$begingroup$
Python 2, 85 81 80 bytes
lambda p:cmp(*[max((h.count(i)+h.count(i>1),i)*(1in h)for i in[6]+h)for h in p])
Try it online!
Returns 1
for P1, 0
for tie, and -1
for P2.
-1 byte, thanks to squid
$endgroup$
Python 2, 85 81 80 bytes
lambda p:cmp(*[max((h.count(i)+h.count(i>1),i)*(1in h)for i in[6]+h)for h in p])
Try it online!
Returns 1
for P1, 0
for tie, and -1
for P2.
-1 byte, thanks to squid
edited Jun 7 at 6:48
answered Jun 6 at 13:16
TFeldTFeld
17.3k3 gold badges14 silver badges53 bronze badges
17.3k3 gold badges14 silver badges53 bronze badges
1
$begingroup$
Whitespace between1
andin
can go
$endgroup$
– squid
Jun 6 at 15:25
$begingroup$
@squid Thanks, :)
$endgroup$
– TFeld
Jun 7 at 6:49
add a comment |
1
$begingroup$
Whitespace between1
andin
can go
$endgroup$
– squid
Jun 6 at 15:25
$begingroup$
@squid Thanks, :)
$endgroup$
– TFeld
Jun 7 at 6:49
1
1
$begingroup$
Whitespace between
1
and in
can go$endgroup$
– squid
Jun 6 at 15:25
$begingroup$
Whitespace between
1
and in
can go$endgroup$
– squid
Jun 6 at 15:25
$begingroup$
@squid Thanks, :)
$endgroup$
– TFeld
Jun 7 at 6:49
$begingroup$
@squid Thanks, :)
$endgroup$
– TFeld
Jun 7 at 6:49
add a comment |
$begingroup$
Perl 6, 60 49 bytes
&[cmp]o*.map:.1&&max (.2..6X+.1)Z ^5o&bag
Try it online!
Returns More
, Same
, Less
for P1 Wins
, Tie
, P2 Wins
.
Explanation
*.map: # Map input lists
&bag # Convert to Bag
o # Pass to block
.1&& # Return 0 if no 1s
max # Maximum of
.2..6 # number of 2s,3s,4s,5s,6s
X+.1 # plus number of 1s
( )Z # zipped with
^5 # secondary key 0,1,2,3,4
&[cmp]o # Compare mapped values
$endgroup$
add a comment |
$begingroup$
Perl 6, 60 49 bytes
&[cmp]o*.map:.1&&max (.2..6X+.1)Z ^5o&bag
Try it online!
Returns More
, Same
, Less
for P1 Wins
, Tie
, P2 Wins
.
Explanation
*.map: # Map input lists
&bag # Convert to Bag
o # Pass to block
.1&& # Return 0 if no 1s
max # Maximum of
.2..6 # number of 2s,3s,4s,5s,6s
X+.1 # plus number of 1s
( )Z # zipped with
^5 # secondary key 0,1,2,3,4
&[cmp]o # Compare mapped values
$endgroup$
add a comment |
$begingroup$
Perl 6, 60 49 bytes
&[cmp]o*.map:.1&&max (.2..6X+.1)Z ^5o&bag
Try it online!
Returns More
, Same
, Less
for P1 Wins
, Tie
, P2 Wins
.
Explanation
*.map: # Map input lists
&bag # Convert to Bag
o # Pass to block
.1&& # Return 0 if no 1s
max # Maximum of
.2..6 # number of 2s,3s,4s,5s,6s
X+.1 # plus number of 1s
( )Z # zipped with
^5 # secondary key 0,1,2,3,4
&[cmp]o # Compare mapped values
$endgroup$
Perl 6, 60 49 bytes
&[cmp]o*.map:.1&&max (.2..6X+.1)Z ^5o&bag
Try it online!
Returns More
, Same
, Less
for P1 Wins
, Tie
, P2 Wins
.
Explanation
*.map: # Map input lists
&bag # Convert to Bag
o # Pass to block
.1&& # Return 0 if no 1s
max # Maximum of
.2..6 # number of 2s,3s,4s,5s,6s
X+.1 # plus number of 1s
( )Z # zipped with
^5 # secondary key 0,1,2,3,4
&[cmp]o # Compare mapped values
edited Jun 6 at 23:36
answered Jun 6 at 20:01
nwellnhofnwellnhof
7,8201 gold badge12 silver badges29 bronze badges
7,8201 gold badge12 silver badges29 bronze badges
add a comment |
add a comment |
$begingroup$
T-SQL query, 148 bytes
Using table variable as input
p: player
v: value for roll
DECLARE @ table(p int,v int)
INSERT @ values(1,5),(1,5),(1,5),(1,5),(1,5)
INSERT @ values(2,4),(2,3),(2,3),(2,1),(2,4)
SELECT sign(min(u)+max(u))FROM(SELECT(p*2-3)*(s+sum(sign(s)-1/v))*(s/5*5+v+30)u
FROM(SELECT*,sum(1/v)over(partition by p)s FROM @)c GROUP BY v,s,p)x
Try it online
Player 1 wins returns -1
Tie returns 0
Player 2 wins returns 1
$endgroup$
add a comment |
$begingroup$
T-SQL query, 148 bytes
Using table variable as input
p: player
v: value for roll
DECLARE @ table(p int,v int)
INSERT @ values(1,5),(1,5),(1,5),(1,5),(1,5)
INSERT @ values(2,4),(2,3),(2,3),(2,1),(2,4)
SELECT sign(min(u)+max(u))FROM(SELECT(p*2-3)*(s+sum(sign(s)-1/v))*(s/5*5+v+30)u
FROM(SELECT*,sum(1/v)over(partition by p)s FROM @)c GROUP BY v,s,p)x
Try it online
Player 1 wins returns -1
Tie returns 0
Player 2 wins returns 1
$endgroup$
add a comment |
$begingroup$
T-SQL query, 148 bytes
Using table variable as input
p: player
v: value for roll
DECLARE @ table(p int,v int)
INSERT @ values(1,5),(1,5),(1,5),(1,5),(1,5)
INSERT @ values(2,4),(2,3),(2,3),(2,1),(2,4)
SELECT sign(min(u)+max(u))FROM(SELECT(p*2-3)*(s+sum(sign(s)-1/v))*(s/5*5+v+30)u
FROM(SELECT*,sum(1/v)over(partition by p)s FROM @)c GROUP BY v,s,p)x
Try it online
Player 1 wins returns -1
Tie returns 0
Player 2 wins returns 1
$endgroup$
T-SQL query, 148 bytes
Using table variable as input
p: player
v: value for roll
DECLARE @ table(p int,v int)
INSERT @ values(1,5),(1,5),(1,5),(1,5),(1,5)
INSERT @ values(2,4),(2,3),(2,3),(2,1),(2,4)
SELECT sign(min(u)+max(u))FROM(SELECT(p*2-3)*(s+sum(sign(s)-1/v))*(s/5*5+v+30)u
FROM(SELECT*,sum(1/v)over(partition by p)s FROM @)c GROUP BY v,s,p)x
Try it online
Player 1 wins returns -1
Tie returns 0
Player 2 wins returns 1
edited 2 days ago
answered Jun 7 at 12:16
t-clausen.dkt-clausen.dk
2,3445 silver badges14 bronze badges
2,3445 silver badges14 bronze badges
add a comment |
add a comment |
$begingroup$
Jelly, 21 bytes
crushed before I even posted it by Nick Kennedy :)
’-oÆṃṀ$$Ạ?fÆṃ$L;$o5)M
A monadic Link accepting a list of players which outputs a list of (1-indexed) winners.
So P1 is [1]
, P2 is [2]
and a tie is [1,2]
.
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 21 bytes
crushed before I even posted it by Nick Kennedy :)
’-oÆṃṀ$$Ạ?fÆṃ$L;$o5)M
A monadic Link accepting a list of players which outputs a list of (1-indexed) winners.
So P1 is [1]
, P2 is [2]
and a tie is [1,2]
.
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 21 bytes
crushed before I even posted it by Nick Kennedy :)
’-oÆṃṀ$$Ạ?fÆṃ$L;$o5)M
A monadic Link accepting a list of players which outputs a list of (1-indexed) winners.
So P1 is [1]
, P2 is [2]
and a tie is [1,2]
.
Try it online!
$endgroup$
Jelly, 21 bytes
crushed before I even posted it by Nick Kennedy :)
’-oÆṃṀ$$Ạ?fÆṃ$L;$o5)M
A monadic Link accepting a list of players which outputs a list of (1-indexed) winners.
So P1 is [1]
, P2 is [2]
and a tie is [1,2]
.
Try it online!
answered Jun 6 at 17:45
Jonathan AllanJonathan Allan
56.4k5 gold badges41 silver badges178 bronze badges
56.4k5 gold badges41 silver badges178 bronze badges
add a comment |
add a comment |
$begingroup$
Java 8, 244 240 236 215 bytes
a->b->int c[][]=new int[2][7],m[]=new int[2],s,p,i=5;for(;i-->0;c[1][b[i]]++)c[0][a[i]]++;for(i=7;i-->2;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=c[p][1]>0?i+9*(c[p][i]+(i>1?c[p][1]:0)):0;return Long.compare(m[0],m[1]);
-4 bytes thanks to @someone.
-21 bytes thanks to @Neil.
Returns 1
if P1 wins; -1
if P2 wins; 0
if it's a tie.
Try it online.
Explanation:
a->b-> // Method with 2 integer-array parameters & integer return
int c[][]=new int[2][7], // Create a count-array for each value of both players,
// initially filled with 0s
m[]=new int[2], // The maximum per player, initially 0
s,p, // Temp-values for the score and player
i=5;for(;i-->0; // Loop `i` in the range (5, 0]:
c[1] // For player 2:
[b[i] // Get the value of the `i`'th die,
]++) // and increase that score-count by 1
c[0][a[i]]++; // Do the same for player 1
for(i=7;i-->2;) // Then loop `i` in the range (7, 2]:
for(p=2;p-->0 // Inner loop `p` over both players:
; // After every iteration:
m[p]=s>m[p]?s:m[p]) // Update the max score if the current score is higher
s= // Set the current score to:
c[p][1]>0? // If at least one 1 is rolled:
i // Use the current value `i`
+9* // With 9 times the following added:
(c[p][i] // The amount of dice for value `i`
+(i>1? // And if the current die `i` is not 1:
c[p][1]:0))// Add the amount of dice for value 1
:0; // Else (no 1s were rolled): the score is 0
return Long.compare(m[0],m[1]);
// Finally compare the maximum scores of the players,
// resulting in -1 if a<b; 0 if a==b; 1 if a>b
$endgroup$
$begingroup$
In the for loop over p, you can replace...*(c[p][1]>0?1:0)
withc[p][1]>0?...:0
. I canot post a TIO link, as it's too long and I don't want to shorten it. The ungolfed version has unbalanced parentheses somewhere around there.
$endgroup$
– someone
Jun 7 at 0:33
$begingroup$
@someone Ah, of course, thanks. I added thec[p][1]>0?
check later on as bug-fix, but apparently without thinking a lot. Thanks for the -4. :)
$endgroup$
– Kevin Cruijssen
Jun 7 at 6:40
$begingroup$
Why the*(i<2?6:i)
? You're just duplicating effort fori=6
andi=1
. This can be just*i
(and stop looping when you get to 2).
$endgroup$
– Neil
Jun 7 at 8:31
$begingroup$
Also, the9
can be any magic number between5
and about32
, right? If you use8
then instead of(int)Math.pow(8,(...)*i)
you can usei<<3*(...)
.
$endgroup$
– Neil
Jun 7 at 8:34
1
$begingroup$
I ended up witha->b->int c[][]=new int[2][7],m[]=new int[2],s,p,i=5;for(;i-->0;c[1][b[i]]++)c[0][a[i]]++;for(i=7;i-->2;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=c[p][1]>0?i+9*(c[p][i]+(i>1?c[p][1]:0)):0;return Long.compare(m[0],m[1]);
which seems to pass all of your test cases...
$endgroup$
– Neil
Jun 7 at 8:52
|
show 3 more comments
$begingroup$
Java 8, 244 240 236 215 bytes
a->b->int c[][]=new int[2][7],m[]=new int[2],s,p,i=5;for(;i-->0;c[1][b[i]]++)c[0][a[i]]++;for(i=7;i-->2;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=c[p][1]>0?i+9*(c[p][i]+(i>1?c[p][1]:0)):0;return Long.compare(m[0],m[1]);
-4 bytes thanks to @someone.
-21 bytes thanks to @Neil.
Returns 1
if P1 wins; -1
if P2 wins; 0
if it's a tie.
Try it online.
Explanation:
a->b-> // Method with 2 integer-array parameters & integer return
int c[][]=new int[2][7], // Create a count-array for each value of both players,
// initially filled with 0s
m[]=new int[2], // The maximum per player, initially 0
s,p, // Temp-values for the score and player
i=5;for(;i-->0; // Loop `i` in the range (5, 0]:
c[1] // For player 2:
[b[i] // Get the value of the `i`'th die,
]++) // and increase that score-count by 1
c[0][a[i]]++; // Do the same for player 1
for(i=7;i-->2;) // Then loop `i` in the range (7, 2]:
for(p=2;p-->0 // Inner loop `p` over both players:
; // After every iteration:
m[p]=s>m[p]?s:m[p]) // Update the max score if the current score is higher
s= // Set the current score to:
c[p][1]>0? // If at least one 1 is rolled:
i // Use the current value `i`
+9* // With 9 times the following added:
(c[p][i] // The amount of dice for value `i`
+(i>1? // And if the current die `i` is not 1:
c[p][1]:0))// Add the amount of dice for value 1
:0; // Else (no 1s were rolled): the score is 0
return Long.compare(m[0],m[1]);
// Finally compare the maximum scores of the players,
// resulting in -1 if a<b; 0 if a==b; 1 if a>b
$endgroup$
$begingroup$
In the for loop over p, you can replace...*(c[p][1]>0?1:0)
withc[p][1]>0?...:0
. I canot post a TIO link, as it's too long and I don't want to shorten it. The ungolfed version has unbalanced parentheses somewhere around there.
$endgroup$
– someone
Jun 7 at 0:33
$begingroup$
@someone Ah, of course, thanks. I added thec[p][1]>0?
check later on as bug-fix, but apparently without thinking a lot. Thanks for the -4. :)
$endgroup$
– Kevin Cruijssen
Jun 7 at 6:40
$begingroup$
Why the*(i<2?6:i)
? You're just duplicating effort fori=6
andi=1
. This can be just*i
(and stop looping when you get to 2).
$endgroup$
– Neil
Jun 7 at 8:31
$begingroup$
Also, the9
can be any magic number between5
and about32
, right? If you use8
then instead of(int)Math.pow(8,(...)*i)
you can usei<<3*(...)
.
$endgroup$
– Neil
Jun 7 at 8:34
1
$begingroup$
I ended up witha->b->int c[][]=new int[2][7],m[]=new int[2],s,p,i=5;for(;i-->0;c[1][b[i]]++)c[0][a[i]]++;for(i=7;i-->2;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=c[p][1]>0?i+9*(c[p][i]+(i>1?c[p][1]:0)):0;return Long.compare(m[0],m[1]);
which seems to pass all of your test cases...
$endgroup$
– Neil
Jun 7 at 8:52
|
show 3 more comments
$begingroup$
Java 8, 244 240 236 215 bytes
a->b->int c[][]=new int[2][7],m[]=new int[2],s,p,i=5;for(;i-->0;c[1][b[i]]++)c[0][a[i]]++;for(i=7;i-->2;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=c[p][1]>0?i+9*(c[p][i]+(i>1?c[p][1]:0)):0;return Long.compare(m[0],m[1]);
-4 bytes thanks to @someone.
-21 bytes thanks to @Neil.
Returns 1
if P1 wins; -1
if P2 wins; 0
if it's a tie.
Try it online.
Explanation:
a->b-> // Method with 2 integer-array parameters & integer return
int c[][]=new int[2][7], // Create a count-array for each value of both players,
// initially filled with 0s
m[]=new int[2], // The maximum per player, initially 0
s,p, // Temp-values for the score and player
i=5;for(;i-->0; // Loop `i` in the range (5, 0]:
c[1] // For player 2:
[b[i] // Get the value of the `i`'th die,
]++) // and increase that score-count by 1
c[0][a[i]]++; // Do the same for player 1
for(i=7;i-->2;) // Then loop `i` in the range (7, 2]:
for(p=2;p-->0 // Inner loop `p` over both players:
; // After every iteration:
m[p]=s>m[p]?s:m[p]) // Update the max score if the current score is higher
s= // Set the current score to:
c[p][1]>0? // If at least one 1 is rolled:
i // Use the current value `i`
+9* // With 9 times the following added:
(c[p][i] // The amount of dice for value `i`
+(i>1? // And if the current die `i` is not 1:
c[p][1]:0))// Add the amount of dice for value 1
:0; // Else (no 1s were rolled): the score is 0
return Long.compare(m[0],m[1]);
// Finally compare the maximum scores of the players,
// resulting in -1 if a<b; 0 if a==b; 1 if a>b
$endgroup$
Java 8, 244 240 236 215 bytes
a->b->int c[][]=new int[2][7],m[]=new int[2],s,p,i=5;for(;i-->0;c[1][b[i]]++)c[0][a[i]]++;for(i=7;i-->2;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=c[p][1]>0?i+9*(c[p][i]+(i>1?c[p][1]:0)):0;return Long.compare(m[0],m[1]);
-4 bytes thanks to @someone.
-21 bytes thanks to @Neil.
Returns 1
if P1 wins; -1
if P2 wins; 0
if it's a tie.
Try it online.
Explanation:
a->b-> // Method with 2 integer-array parameters & integer return
int c[][]=new int[2][7], // Create a count-array for each value of both players,
// initially filled with 0s
m[]=new int[2], // The maximum per player, initially 0
s,p, // Temp-values for the score and player
i=5;for(;i-->0; // Loop `i` in the range (5, 0]:
c[1] // For player 2:
[b[i] // Get the value of the `i`'th die,
]++) // and increase that score-count by 1
c[0][a[i]]++; // Do the same for player 1
for(i=7;i-->2;) // Then loop `i` in the range (7, 2]:
for(p=2;p-->0 // Inner loop `p` over both players:
; // After every iteration:
m[p]=s>m[p]?s:m[p]) // Update the max score if the current score is higher
s= // Set the current score to:
c[p][1]>0? // If at least one 1 is rolled:
i // Use the current value `i`
+9* // With 9 times the following added:
(c[p][i] // The amount of dice for value `i`
+(i>1? // And if the current die `i` is not 1:
c[p][1]:0))// Add the amount of dice for value 1
:0; // Else (no 1s were rolled): the score is 0
return Long.compare(m[0],m[1]);
// Finally compare the maximum scores of the players,
// resulting in -1 if a<b; 0 if a==b; 1 if a>b
edited Jun 7 at 8:58
answered Jun 6 at 16:06
Kevin CruijssenKevin Cruijssen
46.4k5 gold badges79 silver badges233 bronze badges
46.4k5 gold badges79 silver badges233 bronze badges
$begingroup$
In the for loop over p, you can replace...*(c[p][1]>0?1:0)
withc[p][1]>0?...:0
. I canot post a TIO link, as it's too long and I don't want to shorten it. The ungolfed version has unbalanced parentheses somewhere around there.
$endgroup$
– someone
Jun 7 at 0:33
$begingroup$
@someone Ah, of course, thanks. I added thec[p][1]>0?
check later on as bug-fix, but apparently without thinking a lot. Thanks for the -4. :)
$endgroup$
– Kevin Cruijssen
Jun 7 at 6:40
$begingroup$
Why the*(i<2?6:i)
? You're just duplicating effort fori=6
andi=1
. This can be just*i
(and stop looping when you get to 2).
$endgroup$
– Neil
Jun 7 at 8:31
$begingroup$
Also, the9
can be any magic number between5
and about32
, right? If you use8
then instead of(int)Math.pow(8,(...)*i)
you can usei<<3*(...)
.
$endgroup$
– Neil
Jun 7 at 8:34
1
$begingroup$
I ended up witha->b->int c[][]=new int[2][7],m[]=new int[2],s,p,i=5;for(;i-->0;c[1][b[i]]++)c[0][a[i]]++;for(i=7;i-->2;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=c[p][1]>0?i+9*(c[p][i]+(i>1?c[p][1]:0)):0;return Long.compare(m[0],m[1]);
which seems to pass all of your test cases...
$endgroup$
– Neil
Jun 7 at 8:52
|
show 3 more comments
$begingroup$
In the for loop over p, you can replace...*(c[p][1]>0?1:0)
withc[p][1]>0?...:0
. I canot post a TIO link, as it's too long and I don't want to shorten it. The ungolfed version has unbalanced parentheses somewhere around there.
$endgroup$
– someone
Jun 7 at 0:33
$begingroup$
@someone Ah, of course, thanks. I added thec[p][1]>0?
check later on as bug-fix, but apparently without thinking a lot. Thanks for the -4. :)
$endgroup$
– Kevin Cruijssen
Jun 7 at 6:40
$begingroup$
Why the*(i<2?6:i)
? You're just duplicating effort fori=6
andi=1
. This can be just*i
(and stop looping when you get to 2).
$endgroup$
– Neil
Jun 7 at 8:31
$begingroup$
Also, the9
can be any magic number between5
and about32
, right? If you use8
then instead of(int)Math.pow(8,(...)*i)
you can usei<<3*(...)
.
$endgroup$
– Neil
Jun 7 at 8:34
1
$begingroup$
I ended up witha->b->int c[][]=new int[2][7],m[]=new int[2],s,p,i=5;for(;i-->0;c[1][b[i]]++)c[0][a[i]]++;for(i=7;i-->2;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=c[p][1]>0?i+9*(c[p][i]+(i>1?c[p][1]:0)):0;return Long.compare(m[0],m[1]);
which seems to pass all of your test cases...
$endgroup$
– Neil
Jun 7 at 8:52
$begingroup$
In the for loop over p, you can replace
...*(c[p][1]>0?1:0)
with c[p][1]>0?...:0
. I canot post a TIO link, as it's too long and I don't want to shorten it. The ungolfed version has unbalanced parentheses somewhere around there.$endgroup$
– someone
Jun 7 at 0:33
$begingroup$
In the for loop over p, you can replace
...*(c[p][1]>0?1:0)
with c[p][1]>0?...:0
. I canot post a TIO link, as it's too long and I don't want to shorten it. The ungolfed version has unbalanced parentheses somewhere around there.$endgroup$
– someone
Jun 7 at 0:33
$begingroup$
@someone Ah, of course, thanks. I added the
c[p][1]>0?
check later on as bug-fix, but apparently without thinking a lot. Thanks for the -4. :)$endgroup$
– Kevin Cruijssen
Jun 7 at 6:40
$begingroup$
@someone Ah, of course, thanks. I added the
c[p][1]>0?
check later on as bug-fix, but apparently without thinking a lot. Thanks for the -4. :)$endgroup$
– Kevin Cruijssen
Jun 7 at 6:40
$begingroup$
Why the
*(i<2?6:i)
? You're just duplicating effort for i=6
and i=1
. This can be just *i
(and stop looping when you get to 2).$endgroup$
– Neil
Jun 7 at 8:31
$begingroup$
Why the
*(i<2?6:i)
? You're just duplicating effort for i=6
and i=1
. This can be just *i
(and stop looping when you get to 2).$endgroup$
– Neil
Jun 7 at 8:31
$begingroup$
Also, the
9
can be any magic number between 5
and about 32
, right? If you use 8
then instead of (int)Math.pow(8,(...)*i)
you can use i<<3*(...)
.$endgroup$
– Neil
Jun 7 at 8:34
$begingroup$
Also, the
9
can be any magic number between 5
and about 32
, right? If you use 8
then instead of (int)Math.pow(8,(...)*i)
you can use i<<3*(...)
.$endgroup$
– Neil
Jun 7 at 8:34
1
1
$begingroup$
I ended up with
a->b->int c[][]=new int[2][7],m[]=new int[2],s,p,i=5;for(;i-->0;c[1][b[i]]++)c[0][a[i]]++;for(i=7;i-->2;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=c[p][1]>0?i+9*(c[p][i]+(i>1?c[p][1]:0)):0;return Long.compare(m[0],m[1]);
which seems to pass all of your test cases...$endgroup$
– Neil
Jun 7 at 8:52
$begingroup$
I ended up with
a->b->int c[][]=new int[2][7],m[]=new int[2],s,p,i=5;for(;i-->0;c[1][b[i]]++)c[0][a[i]]++;for(i=7;i-->2;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=c[p][1]>0?i+9*(c[p][i]+(i>1?c[p][1]:0)):0;return Long.compare(m[0],m[1]);
which seems to pass all of your test cases...$endgroup$
– Neil
Jun 7 at 8:52
|
show 3 more comments
$begingroup$
PowerShell, 112 126 123 121 bytes
Takes input as (a)(b)
. Returns -1
for P1 win, 1
for P2 or 0
for a tie.
$args|%%$m=$_;(7*(($o=($_-eq1).Count)+$m.Count)+$m.Name+6*!$m)[!$o])-$d
[math]::Sign($d)
Try it online!
Test case @( @(1,1,5,1,1), @(1,1,1,1,1), 1)
added.
Unrolled:
$args|%%$max=$_ # $max is an element with the widest group and the maximum digit except 1
$ones=($_-eq1).Count # number of 1s in a player's hand
$scoreRaw=7*($ones+$max.Count)+$max.Name+6*!$max # where $max.Name is digit of the widest group
$scoreRaw[!$ones] # output $scoreRaw if the array contains 1, otherwise output $null
) # powershell deletes all variables created inside the scope on exit
$diff=$score-$diff
[math]::Sign($diff) # output the score difference
$endgroup$
add a comment |
$begingroup$
PowerShell, 112 126 123 121 bytes
Takes input as (a)(b)
. Returns -1
for P1 win, 1
for P2 or 0
for a tie.
$args|%%$m=$_;(7*(($o=($_-eq1).Count)+$m.Count)+$m.Name+6*!$m)[!$o])-$d
[math]::Sign($d)
Try it online!
Test case @( @(1,1,5,1,1), @(1,1,1,1,1), 1)
added.
Unrolled:
$args|%%$max=$_ # $max is an element with the widest group and the maximum digit except 1
$ones=($_-eq1).Count # number of 1s in a player's hand
$scoreRaw=7*($ones+$max.Count)+$max.Name+6*!$max # where $max.Name is digit of the widest group
$scoreRaw[!$ones] # output $scoreRaw if the array contains 1, otherwise output $null
) # powershell deletes all variables created inside the scope on exit
$diff=$score-$diff
[math]::Sign($diff) # output the score difference
$endgroup$
add a comment |
$begingroup$
PowerShell, 112 126 123 121 bytes
Takes input as (a)(b)
. Returns -1
for P1 win, 1
for P2 or 0
for a tie.
$args|%%$m=$_;(7*(($o=($_-eq1).Count)+$m.Count)+$m.Name+6*!$m)[!$o])-$d
[math]::Sign($d)
Try it online!
Test case @( @(1,1,5,1,1), @(1,1,1,1,1), 1)
added.
Unrolled:
$args|%%$max=$_ # $max is an element with the widest group and the maximum digit except 1
$ones=($_-eq1).Count # number of 1s in a player's hand
$scoreRaw=7*($ones+$max.Count)+$max.Name+6*!$max # where $max.Name is digit of the widest group
$scoreRaw[!$ones] # output $scoreRaw if the array contains 1, otherwise output $null
) # powershell deletes all variables created inside the scope on exit
$diff=$score-$diff
[math]::Sign($diff) # output the score difference
$endgroup$
PowerShell, 112 126 123 121 bytes
Takes input as (a)(b)
. Returns -1
for P1 win, 1
for P2 or 0
for a tie.
$args|%%$m=$_;(7*(($o=($_-eq1).Count)+$m.Count)+$m.Name+6*!$m)[!$o])-$d
[math]::Sign($d)
Try it online!
Test case @( @(1,1,5,1,1), @(1,1,1,1,1), 1)
added.
Unrolled:
$args|%%$max=$_ # $max is an element with the widest group and the maximum digit except 1
$ones=($_-eq1).Count # number of 1s in a player's hand
$scoreRaw=7*($ones+$max.Count)+$max.Name+6*!$max # where $max.Name is digit of the widest group
$scoreRaw[!$ones] # output $scoreRaw if the array contains 1, otherwise output $null
) # powershell deletes all variables created inside the scope on exit
$diff=$score-$diff
[math]::Sign($diff) # output the score difference
edited Jun 7 at 9:07
answered Jun 6 at 19:54
mazzymazzy
3,4361 gold badge4 silver badges19 bronze badges
3,4361 gold badge4 silver badges19 bronze badges
add a comment |
add a comment |
$begingroup$
Wolfram Language (Mathematica), 78 75 74 bytes
-1 byte by Greg Martin
Order@@(#~FreeQ~1||Last@Sort[Reverse/@Tally@Flatten[#/. 1->Range@6]]&)/@#&
Try it online!
Outputs -1 when player 1 wins, 1 when player 2 wins, and 0 for a tie.
Helper function to score a list:
FreeQ[#,1] || If there are 0 1s, score is True
Last@Sort[ Otherwise, take the largest element of
Reverse/@Tally@ the frequency, number pairs in the flat list
Flatten[ #/. 1->Range@6] where each 1 is replaced by 1,2,3,4,5,6.
]& e.g. 1,3,3,5,5 -> 1,2,3,4,5,6,3,3,5,5 -> 3,5
Order @@ (...) /@ #& Apply this function to both lists,
then find the ordering of the result.
$endgroup$
$begingroup$
You can save one byte by replacingFreeQ[#,1]
with#~FreeQ~1
.
$endgroup$
– Greg Martin
Jun 8 at 19:38
add a comment |
$begingroup$
Wolfram Language (Mathematica), 78 75 74 bytes
-1 byte by Greg Martin
Order@@(#~FreeQ~1||Last@Sort[Reverse/@Tally@Flatten[#/. 1->Range@6]]&)/@#&
Try it online!
Outputs -1 when player 1 wins, 1 when player 2 wins, and 0 for a tie.
Helper function to score a list:
FreeQ[#,1] || If there are 0 1s, score is True
Last@Sort[ Otherwise, take the largest element of
Reverse/@Tally@ the frequency, number pairs in the flat list
Flatten[ #/. 1->Range@6] where each 1 is replaced by 1,2,3,4,5,6.
]& e.g. 1,3,3,5,5 -> 1,2,3,4,5,6,3,3,5,5 -> 3,5
Order @@ (...) /@ #& Apply this function to both lists,
then find the ordering of the result.
$endgroup$
$begingroup$
You can save one byte by replacingFreeQ[#,1]
with#~FreeQ~1
.
$endgroup$
– Greg Martin
Jun 8 at 19:38
add a comment |
$begingroup$
Wolfram Language (Mathematica), 78 75 74 bytes
-1 byte by Greg Martin
Order@@(#~FreeQ~1||Last@Sort[Reverse/@Tally@Flatten[#/. 1->Range@6]]&)/@#&
Try it online!
Outputs -1 when player 1 wins, 1 when player 2 wins, and 0 for a tie.
Helper function to score a list:
FreeQ[#,1] || If there are 0 1s, score is True
Last@Sort[ Otherwise, take the largest element of
Reverse/@Tally@ the frequency, number pairs in the flat list
Flatten[ #/. 1->Range@6] where each 1 is replaced by 1,2,3,4,5,6.
]& e.g. 1,3,3,5,5 -> 1,2,3,4,5,6,3,3,5,5 -> 3,5
Order @@ (...) /@ #& Apply this function to both lists,
then find the ordering of the result.
$endgroup$
Wolfram Language (Mathematica), 78 75 74 bytes
-1 byte by Greg Martin
Order@@(#~FreeQ~1||Last@Sort[Reverse/@Tally@Flatten[#/. 1->Range@6]]&)/@#&
Try it online!
Outputs -1 when player 1 wins, 1 when player 2 wins, and 0 for a tie.
Helper function to score a list:
FreeQ[#,1] || If there are 0 1s, score is True
Last@Sort[ Otherwise, take the largest element of
Reverse/@Tally@ the frequency, number pairs in the flat list
Flatten[ #/. 1->Range@6] where each 1 is replaced by 1,2,3,4,5,6.
]& e.g. 1,3,3,5,5 -> 1,2,3,4,5,6,3,3,5,5 -> 3,5
Order @@ (...) /@ #& Apply this function to both lists,
then find the ordering of the result.
edited Jun 8 at 20:27
answered Jun 6 at 21:20
lirtosiastlirtosiast
18.7k4 gold badges41 silver badges112 bronze badges
18.7k4 gold badges41 silver badges112 bronze badges
$begingroup$
You can save one byte by replacingFreeQ[#,1]
with#~FreeQ~1
.
$endgroup$
– Greg Martin
Jun 8 at 19:38
add a comment |
$begingroup$
You can save one byte by replacingFreeQ[#,1]
with#~FreeQ~1
.
$endgroup$
– Greg Martin
Jun 8 at 19:38
$begingroup$
You can save one byte by replacing
FreeQ[#,1]
with #~FreeQ~1
.$endgroup$
– Greg Martin
Jun 8 at 19:38
$begingroup$
You can save one byte by replacing
FreeQ[#,1]
with #~FreeQ~1
.$endgroup$
– Greg Martin
Jun 8 at 19:38
add a comment |
$begingroup$
Jelly, 27 bytes
’o5Rṗ5¤ṢŒr$€UẎṀ1e⁸¤×µ€_/Ṡo/
Try it online!
1 for P1, -1 for P2, 0 for tie
Explanation
’o5Rṗ5¤ṢŒr$€UẎṀ1e⁸¤×µ€_/Ṡo/ Main link
µ€ For each list
’ Decrement each value (so 1s become falsy)
o Vectorized logical or (this replaces previous 1s (now 0s) with the test values)
5Rṗ5¤ 1..5 cartesian-power 5 (1,1,1,1,1; 1,1,1,1,2; 1,1,1,1,3; ...)
$€ For each test list
ṢŒr Sort and run-length encode (gives [digit, #digit])
U Reverse each list (gives [#digit, digit])
Ẏ Tighten by one (gives a list containing each possible hand for each possible wildcard)
Ṁ Take the maximum
1e⁸¤× Multiply the list values by (whether or not the original contained a 1) - becomes [0, 0] if not
_/Ṡ Take the sign of the difference between the #digits and the digits
o/ If the number of digits differs, then 1/-1 is returned; otherwise, check the value of the digit (could still be 0)
$endgroup$
add a comment |
$begingroup$
Jelly, 27 bytes
’o5Rṗ5¤ṢŒr$€UẎṀ1e⁸¤×µ€_/Ṡo/
Try it online!
1 for P1, -1 for P2, 0 for tie
Explanation
’o5Rṗ5¤ṢŒr$€UẎṀ1e⁸¤×µ€_/Ṡo/ Main link
µ€ For each list
’ Decrement each value (so 1s become falsy)
o Vectorized logical or (this replaces previous 1s (now 0s) with the test values)
5Rṗ5¤ 1..5 cartesian-power 5 (1,1,1,1,1; 1,1,1,1,2; 1,1,1,1,3; ...)
$€ For each test list
ṢŒr Sort and run-length encode (gives [digit, #digit])
U Reverse each list (gives [#digit, digit])
Ẏ Tighten by one (gives a list containing each possible hand for each possible wildcard)
Ṁ Take the maximum
1e⁸¤× Multiply the list values by (whether or not the original contained a 1) - becomes [0, 0] if not
_/Ṡ Take the sign of the difference between the #digits and the digits
o/ If the number of digits differs, then 1/-1 is returned; otherwise, check the value of the digit (could still be 0)
$endgroup$
add a comment |
$begingroup$
Jelly, 27 bytes
’o5Rṗ5¤ṢŒr$€UẎṀ1e⁸¤×µ€_/Ṡo/
Try it online!
1 for P1, -1 for P2, 0 for tie
Explanation
’o5Rṗ5¤ṢŒr$€UẎṀ1e⁸¤×µ€_/Ṡo/ Main link
µ€ For each list
’ Decrement each value (so 1s become falsy)
o Vectorized logical or (this replaces previous 1s (now 0s) with the test values)
5Rṗ5¤ 1..5 cartesian-power 5 (1,1,1,1,1; 1,1,1,1,2; 1,1,1,1,3; ...)
$€ For each test list
ṢŒr Sort and run-length encode (gives [digit, #digit])
U Reverse each list (gives [#digit, digit])
Ẏ Tighten by one (gives a list containing each possible hand for each possible wildcard)
Ṁ Take the maximum
1e⁸¤× Multiply the list values by (whether or not the original contained a 1) - becomes [0, 0] if not
_/Ṡ Take the sign of the difference between the #digits and the digits
o/ If the number of digits differs, then 1/-1 is returned; otherwise, check the value of the digit (could still be 0)
$endgroup$
Jelly, 27 bytes
’o5Rṗ5¤ṢŒr$€UẎṀ1e⁸¤×µ€_/Ṡo/
Try it online!
1 for P1, -1 for P2, 0 for tie
Explanation
’o5Rṗ5¤ṢŒr$€UẎṀ1e⁸¤×µ€_/Ṡo/ Main link
µ€ For each list
’ Decrement each value (so 1s become falsy)
o Vectorized logical or (this replaces previous 1s (now 0s) with the test values)
5Rṗ5¤ 1..5 cartesian-power 5 (1,1,1,1,1; 1,1,1,1,2; 1,1,1,1,3; ...)
$€ For each test list
ṢŒr Sort and run-length encode (gives [digit, #digit])
U Reverse each list (gives [#digit, digit])
Ẏ Tighten by one (gives a list containing each possible hand for each possible wildcard)
Ṁ Take the maximum
1e⁸¤× Multiply the list values by (whether or not the original contained a 1) - becomes [0, 0] if not
_/Ṡ Take the sign of the difference between the #digits and the digits
o/ If the number of digits differs, then 1/-1 is returned; otherwise, check the value of the digit (could still be 0)
edited Jun 6 at 16:46
answered Jun 6 at 14:16
HyperNeutrinoHyperNeutrino
20.3k4 gold badges41 silver badges153 bronze badges
20.3k4 gold badges41 silver badges153 bronze badges
add a comment |
add a comment |
$begingroup$
Sledgehammer 0.4, 27 bytes
⢱⢙⢂⠠⡾⢃⠐⢈⠸⣞⠴⠻⠎⡥⡳⡐⢒⠘⢛⣩⡓⣮⡕⡠⣢⣡⠿
Decompresses into this Wolfram Language function:
Order @@ (FreeQ[#1, 1] || Last[Sort[Reverse[Tally[Flatten[#1 /. 1 -> Range[6]]], 2]]] & ) /@ #1 &
which turns out to be exactly the same as my Mathematica answer.
$endgroup$
add a comment |
$begingroup$
Sledgehammer 0.4, 27 bytes
⢱⢙⢂⠠⡾⢃⠐⢈⠸⣞⠴⠻⠎⡥⡳⡐⢒⠘⢛⣩⡓⣮⡕⡠⣢⣡⠿
Decompresses into this Wolfram Language function:
Order @@ (FreeQ[#1, 1] || Last[Sort[Reverse[Tally[Flatten[#1 /. 1 -> Range[6]]], 2]]] & ) /@ #1 &
which turns out to be exactly the same as my Mathematica answer.
$endgroup$
add a comment |
$begingroup$
Sledgehammer 0.4, 27 bytes
⢱⢙⢂⠠⡾⢃⠐⢈⠸⣞⠴⠻⠎⡥⡳⡐⢒⠘⢛⣩⡓⣮⡕⡠⣢⣡⠿
Decompresses into this Wolfram Language function:
Order @@ (FreeQ[#1, 1] || Last[Sort[Reverse[Tally[Flatten[#1 /. 1 -> Range[6]]], 2]]] & ) /@ #1 &
which turns out to be exactly the same as my Mathematica answer.
$endgroup$
Sledgehammer 0.4, 27 bytes
⢱⢙⢂⠠⡾⢃⠐⢈⠸⣞⠴⠻⠎⡥⡳⡐⢒⠘⢛⣩⡓⣮⡕⡠⣢⣡⠿
Decompresses into this Wolfram Language function:
Order @@ (FreeQ[#1, 1] || Last[Sort[Reverse[Tally[Flatten[#1 /. 1 -> Range[6]]], 2]]] & ) /@ #1 &
which turns out to be exactly the same as my Mathematica answer.
answered Jun 6 at 22:04
lirtosiastlirtosiast
18.7k4 gold badges41 silver badges112 bronze badges
18.7k4 gold badges41 silver badges112 bronze badges
add a comment |
add a comment |
$begingroup$
Charcoal, 48 45 bytes
UMθ⮌E⁷№ι∨λ¹UMθ׬¬⊟ι⁺⊟ιιUMθ⟦⌈ι±⌕ι⌈ι⟧I⁻⌕θ⌈θ⌕θ⌊θ
Try it online! Link is to verbose version of code. Takes input as an array of arrays and outputs -1
if player 1 wins, 0
for a tie, and 1
if player 2 wins. Explanation:
UMθ⮌E⁷№ι∨λ¹
Replace each hand with the count of how many times the values 6..1
appear in the hand. The list is reversed because a) it makes it easier to find the highest value with the highest count and b) it makes it easier to remove the count of 1
s. The count of 1
s is doubled because it needs to be removed twice, once to check that it is nonzero and once to add it to the other counts.
UMθ׬¬⊟ι⁺⊟ιι
Add the count of 1
s to the counts for 6..2
, but set all of the counts to zero if the count of 1
s was zero.
UMθ⟦⌈ι±⌕ι⌈ι⟧
For each hand find the highest count and the highest value with that count. (Actually we find value minus 6
as that's golfier.)
I⁻⌕θ⌈θ⌕θ⌊θ
Determine which hand won by subtracting the positions of the winning and losing hands. (If the hands are tied then the first hand is both winning and losing so the result is 0
as desired.)
$endgroup$
add a comment |
$begingroup$
Charcoal, 48 45 bytes
UMθ⮌E⁷№ι∨λ¹UMθ׬¬⊟ι⁺⊟ιιUMθ⟦⌈ι±⌕ι⌈ι⟧I⁻⌕θ⌈θ⌕θ⌊θ
Try it online! Link is to verbose version of code. Takes input as an array of arrays and outputs -1
if player 1 wins, 0
for a tie, and 1
if player 2 wins. Explanation:
UMθ⮌E⁷№ι∨λ¹
Replace each hand with the count of how many times the values 6..1
appear in the hand. The list is reversed because a) it makes it easier to find the highest value with the highest count and b) it makes it easier to remove the count of 1
s. The count of 1
s is doubled because it needs to be removed twice, once to check that it is nonzero and once to add it to the other counts.
UMθ׬¬⊟ι⁺⊟ιι
Add the count of 1
s to the counts for 6..2
, but set all of the counts to zero if the count of 1
s was zero.
UMθ⟦⌈ι±⌕ι⌈ι⟧
For each hand find the highest count and the highest value with that count. (Actually we find value minus 6
as that's golfier.)
I⁻⌕θ⌈θ⌕θ⌊θ
Determine which hand won by subtracting the positions of the winning and losing hands. (If the hands are tied then the first hand is both winning and losing so the result is 0
as desired.)
$endgroup$
add a comment |
$begingroup$
Charcoal, 48 45 bytes
UMθ⮌E⁷№ι∨λ¹UMθ׬¬⊟ι⁺⊟ιιUMθ⟦⌈ι±⌕ι⌈ι⟧I⁻⌕θ⌈θ⌕θ⌊θ
Try it online! Link is to verbose version of code. Takes input as an array of arrays and outputs -1
if player 1 wins, 0
for a tie, and 1
if player 2 wins. Explanation:
UMθ⮌E⁷№ι∨λ¹
Replace each hand with the count of how many times the values 6..1
appear in the hand. The list is reversed because a) it makes it easier to find the highest value with the highest count and b) it makes it easier to remove the count of 1
s. The count of 1
s is doubled because it needs to be removed twice, once to check that it is nonzero and once to add it to the other counts.
UMθ׬¬⊟ι⁺⊟ιι
Add the count of 1
s to the counts for 6..2
, but set all of the counts to zero if the count of 1
s was zero.
UMθ⟦⌈ι±⌕ι⌈ι⟧
For each hand find the highest count and the highest value with that count. (Actually we find value minus 6
as that's golfier.)
I⁻⌕θ⌈θ⌕θ⌊θ
Determine which hand won by subtracting the positions of the winning and losing hands. (If the hands are tied then the first hand is both winning and losing so the result is 0
as desired.)
$endgroup$
Charcoal, 48 45 bytes
UMθ⮌E⁷№ι∨λ¹UMθ׬¬⊟ι⁺⊟ιιUMθ⟦⌈ι±⌕ι⌈ι⟧I⁻⌕θ⌈θ⌕θ⌊θ
Try it online! Link is to verbose version of code. Takes input as an array of arrays and outputs -1
if player 1 wins, 0
for a tie, and 1
if player 2 wins. Explanation:
UMθ⮌E⁷№ι∨λ¹
Replace each hand with the count of how many times the values 6..1
appear in the hand. The list is reversed because a) it makes it easier to find the highest value with the highest count and b) it makes it easier to remove the count of 1
s. The count of 1
s is doubled because it needs to be removed twice, once to check that it is nonzero and once to add it to the other counts.
UMθ׬¬⊟ι⁺⊟ιι
Add the count of 1
s to the counts for 6..2
, but set all of the counts to zero if the count of 1
s was zero.
UMθ⟦⌈ι±⌕ι⌈ι⟧
For each hand find the highest count and the highest value with that count. (Actually we find value minus 6
as that's golfier.)
I⁻⌕θ⌈θ⌕θ⌊θ
Determine which hand won by subtracting the positions of the winning and losing hands. (If the hands are tied then the first hand is both winning and losing so the result is 0
as desired.)
edited Jun 7 at 8:23
answered Jun 6 at 21:04
NeilNeil
85.4k8 gold badges46 silver badges183 bronze badges
85.4k8 gold badges46 silver badges183 bronze badges
add a comment |
add a comment |
$begingroup$
C (gcc) / 32 bit, 117 bytes
t;m;s(int*r)int c[6]=;for(m=0;t=*r++;m=t>m?t:m)c[--t]+=5,t=t?c[t]+t:5;t=*c?*c+m:0;f(a,b)t=s(a)-s(b);t=(t>0)-!t;
Try it online!
Takes two zero-terminated integer arrays. Returns 1
, 0
, -1
for P1 Wins
, P2 Wins
, Tie
.
$endgroup$
1
$begingroup$
@Veskah OK, fixed.
$endgroup$
– nwellnhof
Jun 7 at 18:12
add a comment |
$begingroup$
C (gcc) / 32 bit, 117 bytes
t;m;s(int*r)int c[6]=;for(m=0;t=*r++;m=t>m?t:m)c[--t]+=5,t=t?c[t]+t:5;t=*c?*c+m:0;f(a,b)t=s(a)-s(b);t=(t>0)-!t;
Try it online!
Takes two zero-terminated integer arrays. Returns 1
, 0
, -1
for P1 Wins
, P2 Wins
, Tie
.
$endgroup$
1
$begingroup$
@Veskah OK, fixed.
$endgroup$
– nwellnhof
Jun 7 at 18:12
add a comment |
$begingroup$
C (gcc) / 32 bit, 117 bytes
t;m;s(int*r)int c[6]=;for(m=0;t=*r++;m=t>m?t:m)c[--t]+=5,t=t?c[t]+t:5;t=*c?*c+m:0;f(a,b)t=s(a)-s(b);t=(t>0)-!t;
Try it online!
Takes two zero-terminated integer arrays. Returns 1
, 0
, -1
for P1 Wins
, P2 Wins
, Tie
.
$endgroup$
C (gcc) / 32 bit, 117 bytes
t;m;s(int*r)int c[6]=;for(m=0;t=*r++;m=t>m?t:m)c[--t]+=5,t=t?c[t]+t:5;t=*c?*c+m:0;f(a,b)t=s(a)-s(b);t=(t>0)-!t;
Try it online!
Takes two zero-terminated integer arrays. Returns 1
, 0
, -1
for P1 Wins
, P2 Wins
, Tie
.
edited Jun 7 at 18:12
answered Jun 6 at 22:15
nwellnhofnwellnhof
7,8201 gold badge12 silver badges29 bronze badges
7,8201 gold badge12 silver badges29 bronze badges
1
$begingroup$
@Veskah OK, fixed.
$endgroup$
– nwellnhof
Jun 7 at 18:12
add a comment |
1
$begingroup$
@Veskah OK, fixed.
$endgroup$
– nwellnhof
Jun 7 at 18:12
1
1
$begingroup$
@Veskah OK, fixed.
$endgroup$
– nwellnhof
Jun 7 at 18:12
$begingroup$
@Veskah OK, fixed.
$endgroup$
– nwellnhof
Jun 7 at 18:12
add a comment |
$begingroup$
J, 47 44 bytes
*@-&([:(.([:>./#@]+9^*@[*+).)1#.i.@6=/<:)
Try it online!
Inspired by Nick Kennedy's idea.
ungolfed
*@-&([: (. ([: >./ #@] + 9 ^ *@[ * +) .) 1 #. i.@6 =/ <:)
$endgroup$
add a comment |
$begingroup$
J, 47 44 bytes
*@-&([:(.([:>./#@]+9^*@[*+).)1#.i.@6=/<:)
Try it online!
Inspired by Nick Kennedy's idea.
ungolfed
*@-&([: (. ([: >./ #@] + 9 ^ *@[ * +) .) 1 #. i.@6 =/ <:)
$endgroup$
add a comment |
$begingroup$
J, 47 44 bytes
*@-&([:(.([:>./#@]+9^*@[*+).)1#.i.@6=/<:)
Try it online!
Inspired by Nick Kennedy's idea.
ungolfed
*@-&([: (. ([: >./ #@] + 9 ^ *@[ * +) .) 1 #. i.@6 =/ <:)
$endgroup$
J, 47 44 bytes
*@-&([:(.([:>./#@]+9^*@[*+).)1#.i.@6=/<:)
Try it online!
Inspired by Nick Kennedy's idea.
ungolfed
*@-&([: (. ([: >./ #@] + 9 ^ *@[ * +) .) 1 #. i.@6 =/ <:)
edited Jun 7 at 18:59
answered Jun 7 at 18:08
JonahJonah
3,8931 gold badge12 silver badges21 bronze badges
3,8931 gold badge12 silver badges21 bronze badges
add a comment |
add a comment |
$begingroup$
Perl 5 -MList::Util=max -pl
, 80 bytes
sub t$_=t($_)<=>t<>
Try it online!
Input:
Each player on a separate line, no spaces
Output:
1
Line one wins
0
Tie
-1
Line two wins
$endgroup$
1
$begingroup$
Changed based on your clarification of the rules of the game
$endgroup$
– Xcali
Jun 10 at 0:52
add a comment |
$begingroup$
Perl 5 -MList::Util=max -pl
, 80 bytes
sub t$_=t($_)<=>t<>
Try it online!
Input:
Each player on a separate line, no spaces
Output:
1
Line one wins
0
Tie
-1
Line two wins
$endgroup$
1
$begingroup$
Changed based on your clarification of the rules of the game
$endgroup$
– Xcali
Jun 10 at 0:52
add a comment |
$begingroup$
Perl 5 -MList::Util=max -pl
, 80 bytes
sub t$_=t($_)<=>t<>
Try it online!
Input:
Each player on a separate line, no spaces
Output:
1
Line one wins
0
Tie
-1
Line two wins
$endgroup$
Perl 5 -MList::Util=max -pl
, 80 bytes
sub t$_=t($_)<=>t<>
Try it online!
Input:
Each player on a separate line, no spaces
Output:
1
Line one wins
0
Tie
-1
Line two wins
edited Jun 10 at 0:52
answered Jun 8 at 5:58
XcaliXcali
6,0985 silver badges23 bronze badges
6,0985 silver badges23 bronze badges
1
$begingroup$
Changed based on your clarification of the rules of the game
$endgroup$
– Xcali
Jun 10 at 0:52
add a comment |
1
$begingroup$
Changed based on your clarification of the rules of the game
$endgroup$
– Xcali
Jun 10 at 0:52
1
1
$begingroup$
Changed based on your clarification of the rules of the game
$endgroup$
– Xcali
Jun 10 at 0:52
$begingroup$
Changed based on your clarification of the rules of the game
$endgroup$
– Xcali
Jun 10 at 0:52
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f186456%2fwho-won-a-game-of-bar-dice%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown