Question: Even Up Solitaire please write in python we have a list of cards with values = [ 1, 4, 7, 3, 11, 12, 8, 4,

Even Up Solitaire please write in python

we have a list of cards with values = [ 1, 4, 7, 3, 11, 12, 8, 4, 1, 8], we want to get a code to determine the number of cards left using stack method in python. Basically we determine the sum of pairs and if even we remove those card from the deck then we go on to the next cards

Code so far: (PLEASE WRITE IN PYTHON)

import sys

class Stack(object): def __init__(self, l1 = []): self.l1 = l1 self.stack = self.l1

def push(self, item): return self.stack.append(item) def pop(self): return self.stack.pop()

def peek(self): return self.stack[len(self.stack) - 1]

def isEmpty (self): return (len(self.stack) == 0)

def size(self): return len(self.stack)

def st(self): return self.stack

seq = [ 1, 4, 7, 3, 11, 12, 8, 4, 1, 8]

a = [] #print(seq) for i in range (len(seq) - 1, -1, -1): a.append(seq[i]) #print(a) s = Stack(a) b = Stack() id_x = 0 for i in range(0, len(seq) - 1): print(i) count = s.peek() print("count orig = ", count) s.pop() print("orig", s.st()) if (count + s.peek()) % 2 == 0: b.push(seq[id_x]) b.push(seq[id_x + 1]) s.pop() count = s.peek() s.push(seq[id_x + 1]) id_x = id_x + 2 print("id_x = ", id_x) else: count = s.peek() id_x = id_x + 1 if id_x >= len(seq): break

print(len(seq) - b.size())

So basically it should look something like this

Even Up Solitaire please write in python we have a list of

l 5 2 3 20 A A 3 1 2 9 14 In 8 12.3 en lands left) l 5 2 3 20 A A 3 1 2 9 14 In 8 12.3 en lands left)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!