mirror of
https://github.com/jlengrand/project_euler.git
synced 2026-03-10 08:41:20 +00:00
Starts working on problem 54.
Currently just loads the data in a way that can be used. Next step is to sort players cards
This commit is contained in:
52
e_54.py
Normal file
52
e_54.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
'''
|
||||||
|
Created on 11 sept. 2013
|
||||||
|
|
||||||
|
@author: Julien Lengrand-Lambert
|
||||||
|
|
||||||
|
DESCRIPTION: Solves problem 54 of Project Euler
|
||||||
|
The file, poker.txt, contains one-thousand random hands dealt to two players.
|
||||||
|
Each line of the file contains ten cards (separated by a single space):
|
||||||
|
the first five are Player 1's cards and the last five are Player 2's cards.
|
||||||
|
You can assume that all hands are valid (no invalid characters or repeated
|
||||||
|
cards), each player's hand is in no specific order, and in each hand there
|
||||||
|
is a clear winner.
|
||||||
|
|
||||||
|
How many hands does Player 1 win?
|
||||||
|
'''
|
||||||
|
|
||||||
|
def load_data(filename):
|
||||||
|
"""
|
||||||
|
Loads the given file according to the problem description.
|
||||||
|
Returns a list of two hands of poker players.
|
||||||
|
"""
|
||||||
|
cards_in_poker = 5
|
||||||
|
hands = []
|
||||||
|
file = open(filename, "r")
|
||||||
|
|
||||||
|
#for line in file :
|
||||||
|
for i in range(2):
|
||||||
|
res = file.readline().rstrip() # also removes eol
|
||||||
|
res_spl = res.split(" ")
|
||||||
|
|
||||||
|
# creating left and right player's hands
|
||||||
|
left = res_spl[:cards_in_poker]
|
||||||
|
right = res_spl[cards_in_poker:]
|
||||||
|
|
||||||
|
hands.append([left, right])
|
||||||
|
|
||||||
|
file.close()
|
||||||
|
return hands
|
||||||
|
|
||||||
|
def winning_hands(filename):
|
||||||
|
"""
|
||||||
|
Returns the first of the firs num consecutive primes.
|
||||||
|
"""
|
||||||
|
hands = load_data(filename)
|
||||||
|
for val in hands:
|
||||||
|
print val
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
winning_hands("./e_54_poker.txt")
|
||||||
|
#print 1
|
||||||
|
#print "Answer : %d " % (winning_hands("./e_54_poker.txt"))
|
||||||
1000
e_54_poker.txt
Normal file
1000
e_54_poker.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user