0

# Card shark (python)

Link to the question : https://i.stack.imgur.com/zsA8v.png https://i.stack.imgur.com/Q7frr.png https://i.stack.imgur.com/nuFuM.png https://i.stack.imgur.com/4Bygj.png Can someone help me with this using Python? Any help will be appreciated

30th Oct 2022, 1:53 AM
Zoey
+ 3
A lot work to do! I begin with first challenge a player gets all odd or all even cards of a stack. reduce a stack to a triple (value odds, value even,n). in the best case he gets always the better part of a stack.
30th Oct 2022, 6:53 AM
Oma Falk
+ 2
https://code.sololearn.com/c2Ctbq4q06v5/?ref=app since cycling will change nothing but who gets first card, it is enough to permute stack 2 to n.
30th Oct 2022, 8:57 AM
Oma Falk
30th Oct 2022, 2:15 PM
Oma Falk
+ 1
It was a small change.
30th Oct 2022, 9:58 AM
Oma Falk
+ 1
Lets say 2 4,5,6 1,2 If p1 gets first stack, he is better by 2. But the next is 4+6 -5 = 5 for p2 (he gets first card). so -5 for p1 1,2 is -1 for p1 because first card goes to p1. Now in sum this sorting of stacks has worth of 2-5-1 =-4 for p1. m is to find out to whom the first card of stack[n] goes.
30th Oct 2022, 1:18 PM
Oma Falk
+ 1
Please understand that a player either gets all even or all odd cards of a stack. The difference sum( even)-sum(odds) is the value of a stack if player gets first card of it (index 0). Otherwise the value is to multiply by -1. On the other hand... it doesn't matter. Get all possible sortings of the stacks. Flatten the lists of stacks to one list l for each possible sorting. Result = sum( l[::2])-sum(l[1::2]) Choose best result A bit more to calculate but easier to understand.
30th Oct 2022, 2:05 PM
Oma Falk
0
Oma Falk Thanks for your trying. I'm still trying. But I have no idea how to arrange the stack of cards so that player 1 can get the highest score
30th Oct 2022, 6:58 AM
Zoey
0
Oma Falk But the stacks of cards (input) are provided by the system. So it does not always fulfill your requirements (all odd or all even).
30th Oct 2022, 8:10 AM
Zoey
0
Oma Falk But based on the question, player 1 gets the first card and player 2 gets the second card and so on
30th Oct 2022, 9:49 AM
Zoey
0
Oma Falk def evalOpp(opp): res = 0 m = 0 for element in opp: print(element) value, mnew = element[0], element[1] % 2 v = value * ((-1) ** m) m = (mnew + m) % 2 res += v return res What does this part of code do?
30th Oct 2022, 12:35 PM
Zoey
0
Oma Falk https://i.stack.imgur.com/4Bygj.png Have a look at this. Not player 1 get first stack and player 2 get second stack. What the question states is player 1 get first card and player 2 get second card from all of those stacks of cards.
30th Oct 2022, 1:32 PM
Zoey
0
Oma Falk Can you help to modify the code so that the code get user from input and output the answer just like the sample output in the question. # get input from user tests = int(input()) inputs = [] for _ in range(tests): li = int(input()) temp = [] for _ in range(li): temp.append(input()) inputs.append(temp) temp = [] Sample input 4 4 2 4 5 3 6 2 3 1 8 4 1 2 5 0 1 3 2 5 1 3 4 1 2 3 4 2 5 4 4 3 2 1 0 1 1 -100
30th Oct 2022, 1:43 PM
Zoey
30th Oct 2022, 4:05 PM
Bob_Li
0
How to make storytelling audio format
30th Oct 2022, 4:55 PM
David Gassama