Who won a Game of Bar Dice?Non-transitive dice gameCompare two poker handsRole-Playing Game Dice-RollingThe game of Sevens! Who said what?Compute overall rankingFind the outcome of a game of WarMake this dice game fairBadugi, Who Wins?Who will win a Rock, Paper, Scissors, Lizard, Spock game?Frequency Distribution of Mixed Dice Rolls
Can I use trees and other climbable objects to get on Tenser's Floating Disk?
Heap allocation on microcontroller
English word for "product of tinkering"
Which languages would be most useful in Europe at the end of the 19th century?
How can I end combat quickly when the outcome is inevitable?
Live action TV show where High school Kids go into the virtual world and have to clear levels
Who are the Missing Members of this Noble Family?
Has there been a multiethnic Star Trek character?
Overlapping String-Blocks
How does the Around command at zero work?
Let M and N be single-digit integers. If the product 2M5 x 13N is divisible by 36, how many ordered pairs (M,N) are possible?
Fermat's statement about the ancients: How serious was he?
Is it legal for a bar bouncer to confiscate a fake ID
How can I get an unreasonable manager to approve time off?
Can I utilise a baking stone to make crepes?
Why does the Mishnah use the terms poor person and homeowner when discussing carrying on Shabbat?
Meaning of 'lose their grip on the groins of their followers'
Non-aqueous eyes?
貧しい【まずしい】 poor 貧乏【びんぼう】な poor What's the difference?
Traversing Oceania: A Cryptic Journey
What ways have you found to get edits from non-LaTeX users?
How come the nude protesters were not arrested?
Teaching a class likely meant to inflate the GPA of student athletes
bmatrix: how to align elements' subscripts?
Who won a Game of Bar Dice?
Non-transitive dice gameCompare two poker handsRole-Playing Game Dice-RollingThe game of Sevens! Who said what?Compute overall rankingFind the outcome of a game of WarMake this dice game fairBadugi, Who Wins?Who will win a Rock, Paper, Scissors, Lizard, Spock game?Frequency Distribution of Mixed Dice Rolls
$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 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 values 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
- 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 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 values 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
- 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 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 values 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
- 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 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 values 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
- 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 1 hour ago
Veskah
asked 9 hours ago
VeskahVeskah
1,333316
1,333316
add a comment |
add a comment |
13 Answers
13
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$
$begingroup$
You could replace theIṠwithMand output a list of the winner(s).
$endgroup$
– Jonathan Allan
4 hours ago
$begingroup$
@JonathanAllan Good point! Thanks
$endgroup$
– Nick Kennedy
4 hours ago
1
$begingroup$
15 bytes by making use of the register.
$endgroup$
– Jonathan Allan
4 hours ago
1
$begingroup$
I think theḌmay now be redundant too since the lists sort the same as the integers.
$endgroup$
– Jonathan Allan
3 hours ago
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
8 hours ago
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
8 hours ago
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
7 hours ago
$begingroup$
Wisn't actually needed,6L¢¬Ā*is the same byte-count asWΘ*6L¢.
$endgroup$
– Grimy
7 hours ago
$begingroup$
Hmm, good point. :) ThoughtWwithout 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
7 hours ago
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$
R, 115 102 bytes
-6 bytes thanks to Giuseppe.
-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+max.col(t(l),"l")
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)
max.col(t(l), "last") # most repeated integer (take largest in case of tie)
function(i, j)
sign(f(i) - f(j))
$endgroup$
$begingroup$
102 bytes usingtabulate;max.colis pretty sweet, too!
$endgroup$
– Giuseppe
1 hour ago
$begingroup$
(I also movedfoutside of the arguments, but it doesn't change the byte count)
$endgroup$
– Giuseppe
1 hour ago
$begingroup$
@Giuseppe Nice! I don't think I've ever usedtabulatebefore.
$endgroup$
– Robin Ryder
50 mins ago
add a comment |
$begingroup$
Python 2, 85 81 bytes
lambda p:cmp(*[max((h.count(i)+h.count(i>1),i)*(1 in h)for i in[6]+h)for h in p])
Try it online!
Returns 1 for P1, 0 for tie, and -1 for P2.
$endgroup$
$begingroup$
Whitespace between1andincan go
$endgroup$
– squid
6 hours ago
add a comment |
$begingroup$
PowerShell, 112 126 bytes
Takes input as (a)(b). Returns -1 for P1 win, 1 for P2 or 0 for a tie.
$args|%$d=(7*(($o=($_-eq1).Count)+($m=$_-ne1
[math]::Sign($d)
Try it online!
Unrolled:
$args|%select -Last 1 # element with the widest group and the maximum digit except 1
$score=7*($ones+$max.Count)+($max.Name,6)[!$max]
$diff=$score[!$ones]-$diff # score is 0 if the array does not contains 1
[math]::Sign($diff) # output the score difference
$endgroup$
add a comment |
$begingroup$
Perl 6, 60 bytes
&[cmp]o*.map:.1&&.1+max .kv.map:o&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
.1+ # Number of 1s plus
max # Maximum of
.kv.map: # Key-value pairs mapped to
2>$^k|| # If k==1, return 1
$^v+$k/6 # Otherwise v+k/6
&[cmp]o # Compare mapped values
$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$
Java 8, 244 240 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-->1;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=(int)Math.pow(9,c[p][i]+(i>1?c[p][1]:0))*(i<2?6:i)*(c[p][1]>0?1:0);return Long.compare(m[0],m[1]);
Sigh.. This byte-count.. >.> Ah well, Java I guess ¯_(ツ)_/¯
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-type
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-->1;) // Then loop `i` in the range (7, 1]:
for(p=2;p-->0 // Inner loop `p` over both players:
; // After every iteration:
m[p]=s>m[p]?s:m[p]) // Update the maximum score if the current score is higher
s= // Set the current score to:
(int)Math.pow(9, // 9 to the power:
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
*(i<2?6:i) // Multiply that by 6 if `i` is 1; or `i` otherwise
*(c[p][1]>0?1: // And if no 1s were rolled:
0); // Multiply it by 0 to make the score 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$
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$
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 1s. The count of 1s 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 1s to the counts for 6..2, but set all of the counts to zero if the count of 1s 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$
Wolfram Language (Mathematica), 78 75 bytes
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 -> 4,5
Order @@ (...) /@ #& Apply this function to both lists,
then find the ordering of the result.
$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 |
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
13 Answers
13
active
oldest
votes
13 Answers
13
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$
$begingroup$
You could replace theIṠwithMand output a list of the winner(s).
$endgroup$
– Jonathan Allan
4 hours ago
$begingroup$
@JonathanAllan Good point! Thanks
$endgroup$
– Nick Kennedy
4 hours ago
1
$begingroup$
15 bytes by making use of the register.
$endgroup$
– Jonathan Allan
4 hours ago
1
$begingroup$
I think theḌmay now be redundant too since the lists sort the same as the integers.
$endgroup$
– Jonathan Allan
3 hours ago
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$
$begingroup$
You could replace theIṠwithMand output a list of the winner(s).
$endgroup$
– Jonathan Allan
4 hours ago
$begingroup$
@JonathanAllan Good point! Thanks
$endgroup$
– Nick Kennedy
4 hours ago
1
$begingroup$
15 bytes by making use of the register.
$endgroup$
– Jonathan Allan
4 hours ago
1
$begingroup$
I think theḌmay now be redundant too since the lists sort the same as the integers.
$endgroup$
– Jonathan Allan
3 hours ago
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 3 hours ago
answered 4 hours ago
Nick KennedyNick Kennedy
2,74969
2,74969
$begingroup$
You could replace theIṠwithMand output a list of the winner(s).
$endgroup$
– Jonathan Allan
4 hours ago
$begingroup$
@JonathanAllan Good point! Thanks
$endgroup$
– Nick Kennedy
4 hours ago
1
$begingroup$
15 bytes by making use of the register.
$endgroup$
– Jonathan Allan
4 hours ago
1
$begingroup$
I think theḌmay now be redundant too since the lists sort the same as the integers.
$endgroup$
– Jonathan Allan
3 hours ago
add a comment |
$begingroup$
You could replace theIṠwithMand output a list of the winner(s).
$endgroup$
– Jonathan Allan
4 hours ago
$begingroup$
@JonathanAllan Good point! Thanks
$endgroup$
– Nick Kennedy
4 hours ago
1
$begingroup$
15 bytes by making use of the register.
$endgroup$
– Jonathan Allan
4 hours ago
1
$begingroup$
I think theḌmay now be redundant too since the lists sort the same as the integers.
$endgroup$
– Jonathan Allan
3 hours ago
$begingroup$
You could replace the
IṠ with M and output a list of the winner(s).$endgroup$
– Jonathan Allan
4 hours ago
$begingroup$
You could replace the
IṠ with M and output a list of the winner(s).$endgroup$
– Jonathan Allan
4 hours ago
$begingroup$
@JonathanAllan Good point! Thanks
$endgroup$
– Nick Kennedy
4 hours ago
$begingroup$
@JonathanAllan Good point! Thanks
$endgroup$
– Nick Kennedy
4 hours ago
1
1
$begingroup$
15 bytes by making use of the register.
$endgroup$
– Jonathan Allan
4 hours ago
$begingroup$
15 bytes by making use of the register.
$endgroup$
– Jonathan Allan
4 hours ago
1
1
$begingroup$
I think the
Ḍ may now be redundant too since the lists sort the same as the integers.$endgroup$
– Jonathan Allan
3 hours ago
$begingroup$
I think the
Ḍ may now be redundant too since the lists sort the same as the integers.$endgroup$
– Jonathan Allan
3 hours ago
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
8 hours ago
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
8 hours ago
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
7 hours ago
$begingroup$
Wisn't actually needed,6L¢¬Ā*is the same byte-count asWΘ*6L¢.
$endgroup$
– Grimy
7 hours ago
$begingroup$
Hmm, good point. :) ThoughtWwithout 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
7 hours ago
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
8 hours ago
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
8 hours ago
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
7 hours ago
$begingroup$
Wisn't actually needed,6L¢¬Ā*is the same byte-count asWΘ*6L¢.
$endgroup$
– Grimy
7 hours ago
$begingroup$
Hmm, good point. :) ThoughtWwithout 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
7 hours ago
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 49 mins ago
answered 8 hours ago
GrimyGrimy
3,5941021
3,5941021
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
8 hours ago
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
8 hours ago
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
7 hours ago
$begingroup$
Wisn't actually needed,6L¢¬Ā*is the same byte-count asWΘ*6L¢.
$endgroup$
– Grimy
7 hours ago
$begingroup$
Hmm, good point. :) ThoughtWwithout 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
7 hours ago
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
8 hours ago
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
8 hours ago
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
7 hours ago
$begingroup$
Wisn't actually needed,6L¢¬Ā*is the same byte-count asWΘ*6L¢.
$endgroup$
– Grimy
7 hours ago
$begingroup$
Hmm, good point. :) ThoughtWwithout 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
7 hours ago
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
8 hours ago
$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
8 hours ago
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
8 hours ago
$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
8 hours ago
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
7 hours ago
$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
7 hours ago
$begingroup$
W isn't actually needed, 6L¢¬Ā* is the same byte-count as WΘ*6L¢.$endgroup$
– Grimy
7 hours ago
$begingroup$
W isn't actually needed, 6L¢¬Ā* is the same byte-count as WΘ*6L¢.$endgroup$
– Grimy
7 hours ago
$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
7 hours ago
$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
7 hours ago
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 5 hours ago
answered 8 hours ago
ArnauldArnauld
85.4k7100349
85.4k7100349
add a comment |
add a comment |
$begingroup$
R, 115 102 bytes
-6 bytes thanks to Giuseppe.
-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+max.col(t(l),"l")
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)
max.col(t(l), "last") # most repeated integer (take largest in case of tie)
function(i, j)
sign(f(i) - f(j))
$endgroup$
$begingroup$
102 bytes usingtabulate;max.colis pretty sweet, too!
$endgroup$
– Giuseppe
1 hour ago
$begingroup$
(I also movedfoutside of the arguments, but it doesn't change the byte count)
$endgroup$
– Giuseppe
1 hour ago
$begingroup$
@Giuseppe Nice! I don't think I've ever usedtabulatebefore.
$endgroup$
– Robin Ryder
50 mins ago
add a comment |
$begingroup$
R, 115 102 bytes
-6 bytes thanks to Giuseppe.
-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+max.col(t(l),"l")
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)
max.col(t(l), "last") # most repeated integer (take largest in case of tie)
function(i, j)
sign(f(i) - f(j))
$endgroup$
$begingroup$
102 bytes usingtabulate;max.colis pretty sweet, too!
$endgroup$
– Giuseppe
1 hour ago
$begingroup$
(I also movedfoutside of the arguments, but it doesn't change the byte count)
$endgroup$
– Giuseppe
1 hour ago
$begingroup$
@Giuseppe Nice! I don't think I've ever usedtabulatebefore.
$endgroup$
– Robin Ryder
50 mins ago
add a comment |
$begingroup$
R, 115 102 bytes
-6 bytes thanks to Giuseppe.
-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+max.col(t(l),"l")
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)
max.col(t(l), "last") # most repeated integer (take largest in case of tie)
function(i, j)
sign(f(i) - f(j))
$endgroup$
R, 115 102 bytes
-6 bytes thanks to Giuseppe.
-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+max.col(t(l),"l")
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)
max.col(t(l), "last") # most repeated integer (take largest in case of tie)
function(i, j)
sign(f(i) - f(j))
edited 44 mins ago
answered 8 hours ago
Robin RyderRobin Ryder
1,488216
1,488216
$begingroup$
102 bytes usingtabulate;max.colis pretty sweet, too!
$endgroup$
– Giuseppe
1 hour ago
$begingroup$
(I also movedfoutside of the arguments, but it doesn't change the byte count)
$endgroup$
– Giuseppe
1 hour ago
$begingroup$
@Giuseppe Nice! I don't think I've ever usedtabulatebefore.
$endgroup$
– Robin Ryder
50 mins ago
add a comment |
$begingroup$
102 bytes usingtabulate;max.colis pretty sweet, too!
$endgroup$
– Giuseppe
1 hour ago
$begingroup$
(I also movedfoutside of the arguments, but it doesn't change the byte count)
$endgroup$
– Giuseppe
1 hour ago
$begingroup$
@Giuseppe Nice! I don't think I've ever usedtabulatebefore.
$endgroup$
– Robin Ryder
50 mins ago
$begingroup$
102 bytes using
tabulate; max.col is pretty sweet, too!$endgroup$
– Giuseppe
1 hour ago
$begingroup$
102 bytes using
tabulate; max.col is pretty sweet, too!$endgroup$
– Giuseppe
1 hour ago
$begingroup$
(I also moved
f outside of the arguments, but it doesn't change the byte count)$endgroup$
– Giuseppe
1 hour ago
$begingroup$
(I also moved
f outside of the arguments, but it doesn't change the byte count)$endgroup$
– Giuseppe
1 hour ago
$begingroup$
@Giuseppe Nice! I don't think I've ever used
tabulate before.$endgroup$
– Robin Ryder
50 mins ago
$begingroup$
@Giuseppe Nice! I don't think I've ever used
tabulate before.$endgroup$
– Robin Ryder
50 mins ago
add a comment |
$begingroup$
Python 2, 85 81 bytes
lambda p:cmp(*[max((h.count(i)+h.count(i>1),i)*(1 in h)for i in[6]+h)for h in p])
Try it online!
Returns 1 for P1, 0 for tie, and -1 for P2.
$endgroup$
$begingroup$
Whitespace between1andincan go
$endgroup$
– squid
6 hours ago
add a comment |
$begingroup$
Python 2, 85 81 bytes
lambda p:cmp(*[max((h.count(i)+h.count(i>1),i)*(1 in h)for i in[6]+h)for h in p])
Try it online!
Returns 1 for P1, 0 for tie, and -1 for P2.
$endgroup$
$begingroup$
Whitespace between1andincan go
$endgroup$
– squid
6 hours ago
add a comment |
$begingroup$
Python 2, 85 81 bytes
lambda p:cmp(*[max((h.count(i)+h.count(i>1),i)*(1 in h)for i in[6]+h)for h in p])
Try it online!
Returns 1 for P1, 0 for tie, and -1 for P2.
$endgroup$
Python 2, 85 81 bytes
lambda p:cmp(*[max((h.count(i)+h.count(i>1),i)*(1 in h)for i in[6]+h)for h in p])
Try it online!
Returns 1 for P1, 0 for tie, and -1 for P2.
edited 8 hours ago
answered 8 hours ago
TFeldTFeld
17k31452
17k31452
$begingroup$
Whitespace between1andincan go
$endgroup$
– squid
6 hours ago
add a comment |
$begingroup$
Whitespace between1andincan go
$endgroup$
– squid
6 hours ago
$begingroup$
Whitespace between
1 and in can go$endgroup$
– squid
6 hours ago
$begingroup$
Whitespace between
1 and in can go$endgroup$
– squid
6 hours ago
add a comment |
$begingroup$
PowerShell, 112 126 bytes
Takes input as (a)(b). Returns -1 for P1 win, 1 for P2 or 0 for a tie.
$args|%$d=(7*(($o=($_-eq1).Count)+($m=$_-ne1
[math]::Sign($d)
Try it online!
Unrolled:
$args|%select -Last 1 # element with the widest group and the maximum digit except 1
$score=7*($ones+$max.Count)+($max.Name,6)[!$max]
$diff=$score[!$ones]-$diff # score is 0 if the array does not contains 1
[math]::Sign($diff) # output the score difference
$endgroup$
add a comment |
$begingroup$
PowerShell, 112 126 bytes
Takes input as (a)(b). Returns -1 for P1 win, 1 for P2 or 0 for a tie.
$args|%$d=(7*(($o=($_-eq1).Count)+($m=$_-ne1
[math]::Sign($d)
Try it online!
Unrolled:
$args|%select -Last 1 # element with the widest group and the maximum digit except 1
$score=7*($ones+$max.Count)+($max.Name,6)[!$max]
$diff=$score[!$ones]-$diff # score is 0 if the array does not contains 1
[math]::Sign($diff) # output the score difference
$endgroup$
add a comment |
$begingroup$
PowerShell, 112 126 bytes
Takes input as (a)(b). Returns -1 for P1 win, 1 for P2 or 0 for a tie.
$args|%$d=(7*(($o=($_-eq1).Count)+($m=$_-ne1
[math]::Sign($d)
Try it online!
Unrolled:
$args|%select -Last 1 # element with the widest group and the maximum digit except 1
$score=7*($ones+$max.Count)+($max.Name,6)[!$max]
$diff=$score[!$ones]-$diff # score is 0 if the array does not contains 1
[math]::Sign($diff) # output the score difference
$endgroup$
PowerShell, 112 126 bytes
Takes input as (a)(b). Returns -1 for P1 win, 1 for P2 or 0 for a tie.
$args|%$d=(7*(($o=($_-eq1).Count)+($m=$_-ne1
[math]::Sign($d)
Try it online!
Unrolled:
$args|%select -Last 1 # element with the widest group and the maximum digit except 1
$score=7*($ones+$max.Count)+($max.Name,6)[!$max]
$diff=$score[!$ones]-$diff # score is 0 if the array does not contains 1
[math]::Sign($diff) # output the score difference
edited 2 hours ago
answered 2 hours ago
mazzymazzy
3,3001419
3,3001419
add a comment |
add a comment |
$begingroup$
Perl 6, 60 bytes
&[cmp]o*.map:.1&&.1+max .kv.map:o&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
.1+ # Number of 1s plus
max # Maximum of
.kv.map: # Key-value pairs mapped to
2>$^k|| # If k==1, return 1
$^v+$k/6 # Otherwise v+k/6
&[cmp]o # Compare mapped values
$endgroup$
add a comment |
$begingroup$
Perl 6, 60 bytes
&[cmp]o*.map:.1&&.1+max .kv.map:o&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
.1+ # Number of 1s plus
max # Maximum of
.kv.map: # Key-value pairs mapped to
2>$^k|| # If k==1, return 1
$^v+$k/6 # Otherwise v+k/6
&[cmp]o # Compare mapped values
$endgroup$
add a comment |
$begingroup$
Perl 6, 60 bytes
&[cmp]o*.map:.1&&.1+max .kv.map:o&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
.1+ # Number of 1s plus
max # Maximum of
.kv.map: # Key-value pairs mapped to
2>$^k|| # If k==1, return 1
$^v+$k/6 # Otherwise v+k/6
&[cmp]o # Compare mapped values
$endgroup$
Perl 6, 60 bytes
&[cmp]o*.map:.1&&.1+max .kv.map:o&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
.1+ # Number of 1s plus
max # Maximum of
.kv.map: # Key-value pairs mapped to
2>$^k|| # If k==1, return 1
$^v+$k/6 # Otherwise v+k/6
&[cmp]o # Compare mapped values
edited 1 hour ago
answered 2 hours ago
nwellnhofnwellnhof
7,79011129
7,79011129
add a comment |
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 5 hours ago
answered 7 hours ago
HyperNeutrinoHyperNeutrino
19.2k438148
19.2k438148
add a comment |
add a comment |
$begingroup$
Java 8, 244 240 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-->1;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=(int)Math.pow(9,c[p][i]+(i>1?c[p][1]:0))*(i<2?6:i)*(c[p][1]>0?1:0);return Long.compare(m[0],m[1]);
Sigh.. This byte-count.. >.> Ah well, Java I guess ¯_(ツ)_/¯
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-type
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-->1;) // Then loop `i` in the range (7, 1]:
for(p=2;p-->0 // Inner loop `p` over both players:
; // After every iteration:
m[p]=s>m[p]?s:m[p]) // Update the maximum score if the current score is higher
s= // Set the current score to:
(int)Math.pow(9, // 9 to the power:
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
*(i<2?6:i) // Multiply that by 6 if `i` is 1; or `i` otherwise
*(c[p][1]>0?1: // And if no 1s were rolled:
0); // Multiply it by 0 to make the score 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$
add a comment |
$begingroup$
Java 8, 244 240 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-->1;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=(int)Math.pow(9,c[p][i]+(i>1?c[p][1]:0))*(i<2?6:i)*(c[p][1]>0?1:0);return Long.compare(m[0],m[1]);
Sigh.. This byte-count.. >.> Ah well, Java I guess ¯_(ツ)_/¯
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-type
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-->1;) // Then loop `i` in the range (7, 1]:
for(p=2;p-->0 // Inner loop `p` over both players:
; // After every iteration:
m[p]=s>m[p]?s:m[p]) // Update the maximum score if the current score is higher
s= // Set the current score to:
(int)Math.pow(9, // 9 to the power:
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
*(i<2?6:i) // Multiply that by 6 if `i` is 1; or `i` otherwise
*(c[p][1]>0?1: // And if no 1s were rolled:
0); // Multiply it by 0 to make the score 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$
add a comment |
$begingroup$
Java 8, 244 240 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-->1;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=(int)Math.pow(9,c[p][i]+(i>1?c[p][1]:0))*(i<2?6:i)*(c[p][1]>0?1:0);return Long.compare(m[0],m[1]);
Sigh.. This byte-count.. >.> Ah well, Java I guess ¯_(ツ)_/¯
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-type
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-->1;) // Then loop `i` in the range (7, 1]:
for(p=2;p-->0 // Inner loop `p` over both players:
; // After every iteration:
m[p]=s>m[p]?s:m[p]) // Update the maximum score if the current score is higher
s= // Set the current score to:
(int)Math.pow(9, // 9 to the power:
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
*(i<2?6:i) // Multiply that by 6 if `i` is 1; or `i` otherwise
*(c[p][1]>0?1: // And if no 1s were rolled:
0); // Multiply it by 0 to make the score 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 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-->1;)for(p=2;p-->0;m[p]=s>m[p]?s:m[p])s=(int)Math.pow(9,c[p][i]+(i>1?c[p][1]:0))*(i<2?6:i)*(c[p][1]>0?1:0);return Long.compare(m[0],m[1]);
Sigh.. This byte-count.. >.> Ah well, Java I guess ¯_(ツ)_/¯
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-type
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-->1;) // Then loop `i` in the range (7, 1]:
for(p=2;p-->0 // Inner loop `p` over both players:
; // After every iteration:
m[p]=s>m[p]?s:m[p]) // Update the maximum score if the current score is higher
s= // Set the current score to:
(int)Math.pow(9, // 9 to the power:
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
*(i<2?6:i) // Multiply that by 6 if `i` is 1; or `i` otherwise
*(c[p][1]>0?1: // And if no 1s were rolled:
0); // Multiply it by 0 to make the score 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 4 hours ago
answered 6 hours ago
Kevin CruijssenKevin Cruijssen
45.5k576230
45.5k576230
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 4 hours ago
Jonathan AllanJonathan Allan
56.2k538178
56.2k538178
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 1s. The count of 1s 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 1s to the counts for 6..2, but set all of the counts to zero if the count of 1s 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 1s. The count of 1s 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 1s to the counts for 6..2, but set all of the counts to zero if the count of 1s 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 1s. The count of 1s 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 1s to the counts for 6..2, but set all of the counts to zero if the count of 1s 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 1s. The count of 1s 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 1s to the counts for 6..2, but set all of the counts to zero if the count of 1s 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 50 mins ago
answered 1 hour ago
NeilNeil
84.6k845183
84.6k845183
add a comment |
add a comment |
$begingroup$
Wolfram Language (Mathematica), 78 75 bytes
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 -> 4,5
Order @@ (...) /@ #& Apply this function to both lists,
then find the ordering of the result.
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 78 75 bytes
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 -> 4,5
Order @@ (...) /@ #& Apply this function to both lists,
then find the ordering of the result.
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 78 75 bytes
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 -> 4,5
Order @@ (...) /@ #& Apply this function to both lists,
then find the ordering of the result.
$endgroup$
Wolfram Language (Mathematica), 78 75 bytes
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 -> 4,5
Order @@ (...) /@ #& Apply this function to both lists,
then find the ordering of the result.
edited 39 mins ago
answered 49 mins ago
lirtosiastlirtosiast
18.6k440112
18.6k440112
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 5 mins ago
lirtosiastlirtosiast
18.6k440112
18.6k440112
add a comment |
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