diff --git a/d04/exemple1.txt b/d04/exemple1.txt new file mode 100644 index 0000000..71f208a --- /dev/null +++ b/d04/exemple1.txt @@ -0,0 +1,6 @@ +Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53 +Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19 +Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1 +Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83 +Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36 +Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11 \ No newline at end of file diff --git a/d04/run1.py b/d04/run1.py new file mode 100644 index 0000000..7c72404 --- /dev/null +++ b/d04/run1.py @@ -0,0 +1,28 @@ +import sys + +def main(myList, S = 0): + card=[c.split(": ")[1] for c in myList] + + win_str_one = [s.split(" | ")[0] for s in card] + sto_str_one = [s.split(" | ")[1] for s in card] + + win_str = [s.split(" ") for s in win_str_one] + sto_str = [s.split(" ") for s in sto_str_one] + + win = [ [int(i) for i in item if i != ''] for item in win_str] + sto = [ [int(i) for i in item if i != ''] for item in sto_str] + + #print(win) + #print(sto) + + for idx, p in enumerate(sto): + n = 0 + for j in p: + #print(j, win[idx]) + n += win[idx].count(j) + S+= 2 ** (n-1) if n > 0 else 0 + + return S + +if __name__ == '__main__': + print(main(sys.stdin.read().splitlines())) \ No newline at end of file