diff options
Diffstat (limited to '2022/day5/asd.py')
| -rwxr-xr-x | 2022/day5/asd.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/2022/day5/asd.py b/2022/day5/asd.py new file mode 100755 index 0000000..8fc94fa --- /dev/null +++ b/2022/day5/asd.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 + +from functools import reduce + +# filename = "ref_mod.txt" +filename = "pzl_mod.txt" + +res1 = '' +res2 = '' +f = open(filename) + +stacks1 = [] +stacks2 = [] +for line in f: + line = line.strip() + + if line == '': + break + + stack = [] + for c in line: + stack.append(c) + stacks1.append(stack) + stacks2.append(stack) +# print(stacks1) + +for line in f: + line = line.strip() + line = line.replace('move', '').replace('from ', '').replace('to ', '').strip() + mcount, mfrom, mto = [int(i) for i in line.split(' ')] + + mfrom -= 1 + mto -= 1 + + to_move = stacks1[mfrom][-mcount:] + stacks1[mfrom] = stacks1[mfrom][:-mcount] + stacks1[mto] = stacks1[mto] + to_move[::-1] + # print(stacks1) + + to_move = stacks2[mfrom][-mcount:] + stacks2[mfrom] = stacks2[mfrom][:-mcount] + stacks2[mto] = stacks2[mto] + to_move + # print(stacks2) + +f.close() + +print(stacks1) +print(stacks2) + +for i in stacks1: + res1 = res1 + i[-1] +print('res1:', res1) + +for i in stacks2: + res2 = res2 + i[-1] +print('res2:', res2) + |
