Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dc61bc8

Browse files
author
mhamid
committed
day 2
1 parent e80d9f8 commit dc61bc8

File tree

3 files changed

+2574
-0
lines changed

3 files changed

+2574
-0
lines changed

‎day2/day2.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from types import SimpleNamespace
2+
3+
# access the points with dot notation
4+
points = {
5+
'ROCK': 1,
6+
'PAPER': 2,
7+
'SISSOR': 3,
8+
'LOST': 0,
9+
'DRAW': 3,
10+
'WIN': 6,
11+
}
12+
p = SimpleNamespace(**points)
13+
14+
# access the rules with dot notation
15+
rules = {
16+
'ROCK': 'ROCK',
17+
'PAPER': 'PAPER',
18+
'SISSOR': 'SISSOR',
19+
}
20+
r = SimpleNamespace(**rules)
21+
22+
# replace A,B,C and X,Y,Z with rock, paper, sissor
23+
def getValue(player):
24+
if (player == 'A' or player == 'X'):
25+
return r.ROCK
26+
if (player == 'B' or player == 'Y'):
27+
return r.PAPER
28+
if (player == 'C' or player == 'Z'):
29+
return r.SISSOR
30+
31+
# check win, loss, or draw
32+
def rockPaperSissor(foe, you):
33+
if (getValue(you) == r.ROCK):
34+
if (getValue(foe) == r.ROCK):
35+
return [p.ROCK + p.DRAW, p.ROCK + p.DRAW]
36+
elif (getValue(foe) == r.PAPER):
37+
return [p.PAPER + p.WIN, p.ROCK + p.LOST]
38+
elif (getValue(foe) == r.SISSOR):
39+
return [p.SISSOR + p.LOST, p.ROCK + p.WIN]
40+
elif (getValue(you) == r.PAPER):
41+
if (getValue(foe) == r.ROCK):
42+
return [p.ROCK + p.LOST, p.PAPER + p.WIN]
43+
elif (getValue(foe) == r.PAPER):
44+
return [p.PAPER + p.DRAW, p.PAPER + p.DRAW]
45+
elif (getValue(foe) == r.SISSOR):
46+
return [p.SISSOR + p.WIN, p.PAPER + p.LOST]
47+
elif (getValue(you) == r.SISSOR):
48+
if (getValue(foe) == r.ROCK):
49+
return [p.ROCK + p.WIN, p.SISSOR + p.LOST]
50+
elif (getValue(foe) == r.PAPER):
51+
return [p.PAPER + p.LOST, p.SISSOR + p.WIN]
52+
elif (getValue(foe) == r.SISSOR):
53+
return [p.SISSOR + p.DRAW, p.SISSOR + p.DRAW]
54+
55+
# read input
56+
input = open('input.txt', 'r')
57+
lines = input.readlines()
58+
opponentTotal = 0
59+
yourTotal = 0
60+
61+
for line in lines:
62+
s = line[:3].split(' ')
63+
result = rockPaperSissor(s[0], s[1])
64+
opponentTotal = opponentTotal + result[0]
65+
yourTotal = yourTotal + result[1]
66+
67+
# part one
68+
print('Opponent\'s total score: ', opponentTotal)
69+
print('Your total score: ', yourTotal)
70+
71+
# part two

‎day2/dummy.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
A Y
2+
B X
3+
C Z

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /