1
2022/day-2-alt/.gitignore
vendored
Normal file
1
2022/day-2-alt/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/input.txt
|
||||
34
2022/day-2-alt/main.py
Normal file
34
2022/day-2-alt/main.py
Normal file
@@ -0,0 +1,34 @@
|
||||
def calc(u1, u2):
|
||||
if u1 == u2:
|
||||
print(f'{chr(u1+ord("A")-1)} {chr(u2+ord("X")-1)} draw')
|
||||
return u2 + 3
|
||||
elif u1 == (u2 % 3 - 1):
|
||||
print(f'{chr(u1+ord("A")-1)} {chr(u2+ord("X")-1)} win')
|
||||
return u2 + 6
|
||||
else:
|
||||
print(f'{chr(u1+ord("A")-1)} {chr(u2+ord("X")-1)} loss')
|
||||
return u2 + 0
|
||||
|
||||
def test_2a(file):
|
||||
res = []
|
||||
for l in open(file, 'r').read().split('\n'):
|
||||
if l:
|
||||
a, b = l.split()
|
||||
res.append(calc(*(ord(a) - ord("A") + 1, ord(b) - ord("X") + 1)))
|
||||
res = sum(res)
|
||||
print(res)
|
||||
apprehension = task_2a(file)
|
||||
assert res == apprehension
|
||||
|
||||
|
||||
def task_2a(file):
|
||||
numify = lambda a_b: (ord(a_b[0]) - ord("A") + 1, ord(a_b[1]) - ord("X") + 1)
|
||||
return sum([calc(*numify(l.split())) for l in open(file, 'r').read().split('\n') if l])
|
||||
|
||||
def task_2b(file):
|
||||
raise NotImplementedError
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(task_2a('input.txt'))
|
||||
# print(task_2b('input.txt'))
|
||||
|
||||
5
2022/day-2-alt/todo.md
Normal file
5
2022/day-2-alt/todo.md
Normal file
@@ -0,0 +1,5 @@
|
||||
Gave up for now, tried to solve the task more or less functionally/mathematically, but it didn't work out.
|
||||
|
||||
Related:
|
||||
- [Calculus on finite weighted graphs](https://en.wikipedia.org/wiki/Calculus_on_finite_weighted_graphs)
|
||||
- 
|
||||
BIN
2022/day-2-alt/whiteboard_notes.jpeg
Normal file
BIN
2022/day-2-alt/whiteboard_notes.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 181 KiB |
Reference in New Issue
Block a user