CARVIEW |
Select Language
HTTP/2 200
last-modified: Tue, 25 May 2010 07:38:45 GMT
accept-ranges: bytes
vary: Accept-Encoding,User-Agent
content-encoding: gzip
content-length: 1371
content-type: text/plain
date: Sat, 11 Oct 2025 16:29:45 GMT
server: Apache
# !/usr/bin/python
import random
RAND_MAX = (2 ** 20)
PICK_SIZE = 5
MAX_READ = 128
LOTTO_GRID_SIZE = 299
SESSION_LIMIT_TIME = 30
MAX_PICK_CHANGES = 5
WINNER_CHECK_FUNCTION = 'self.checkWinners'
class Test:
def createWinners(self):
winners = set()
while (len(winners) < PICK_SIZE):
winners.update([random.randint(1, RAND_MAX)])
#print "Winners are: ", winners
return winners
def pickRandom(self):
picks = set()
llen = len(self.lotto_grid)
rand_base = (len(picks) - 1)
while (len(picks) < PICK_SIZE):
i = random.randint(rand_base, RAND_MAX)
if (i < 1):
++i
if ((i > llen) and ((i % llen) == 0)):
i += 1
i = (i % llen)
picks.update([i])
return picks
def genGrid(self):
grid = [WINNER_CHECK_FUNCTION]
while (len(grid) != LOTTO_GRID_SIZE):
grid.append(random.randint(0, RAND_MAX))
#counter = 0
#while counter < len(grid):
# print grid[counter]
# counter += 1
return grid
def checkWinners(self, element):
winner = True
for n in self.winners:
winner = (winner & (n in [ self.lotto_grid[p] for p in self.pick_list ]))
if winner:
print "ZOMG You won!!!\n'"
return True
else:
print "Sorry you aren't very lucky... Maybe you have better luck with women?\n"
return False
def playGame(self):
#self.request.send('Thanks for your choices, calculating if you won...')
eval(self.lotto_grid[0])(self.lotto_grid[1:])
def getLine(self, msg):
self.request.send(msg)
return self.connstream_fobj.readline(MAX_READ)
def handlePickChange(self):
for r in range(0, MAX_PICK_CHANGES):
# input = self.getLine('Input the number of the pick that you wish to change or newline to stop:\n')
# if (input.strip() == ''):
# break
# else:
# idx_to_edit = int(input)
# l = self.getLine('Input your new pick\n')
# self.lotto_grid[self.pick_list[idx_to_edit]] = l
for idx_to_edit in range(-PICK_SIZE,PICK_SIZE):
if self.lotto_grid[self.pick_list[idx_to_edit]]==self.lotto_grid[0]:
print "Ind: %d, %s" % (idx_to_edit,self.lotto_grid[0])
return True
return False
#gridcounter = 0
#found = False
#while gridcounter < len(self.lotto_grid):
# if self.lotto_grid[gridcounter] in self.winners:
# if gridcounter < PICK_SIZE:
# print "Gridctr: %d : %d" % (gridcounter,self.lotto_grid[gridcounter])
# found = True
# gridcounter += 1
#return found
#allfound = False
#instances = 0
#for x in self.winners:
# foundx = False
# gridctr = -LOTTO_GRID_SIZE
# while gridctr < LOTTO_GRID_SIZE:#len(self.lotto_grid):
# foundx = True
# print "gridctr: %d , val = %d " % (gridctr,x)
# #break
# gridctr += 1
# if foundx:
# allfound = True
# else:
# allfound = False
# return False
#return allfound
def handle(self,port):
random.seed(port)
self.lotto_grid = self.genGrid()
self.pick_list = list(self.pickRandom())
#print "picklist : ",self.pick_list
self.winners = self.createWinners()
#for pick_idx in range(0, PICK_SIZE):
# print(('%d. %s\n' % (pick_idx,
# self.lotto_grid[self.pick_list[pick_idx]])))
if self.handlePickChange():
return True
return False
#self.playGame()
#if self.checkWinners(self.lotto_grid[1:]):
# return True
#return False
test = Test()
portno = 0
while portno < 65536:
print "Trying...%d" % ( portno )
if test.handle(portno):
print "Success! on port %d" % (portno)
#break
portno += 1