Signed-off-by: TuDatTr <tuan-dat.tran@tudattr.dev>
This commit is contained in:
TuDatTr
2023-10-09 01:45:03 +02:00
parent 7510bc2f59
commit 4e36ed6462
44 changed files with 1137 additions and 3 deletions

1
2022/day-2-alt/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/input.txt

34
2022/day-2-alt/main.py Normal file
View 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
View 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)
- ![notes](whiteboard_notes.jpeg)

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB