From 2d5d8e10af746e71ba25fc028f260c0ae565b219 Mon Sep 17 00:00:00 2001 From: Dece Date: Sun, 22 Dec 2019 11:12:38 +0100 Subject: [PATCH] Day 22 --- 2019/day22.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 2019/day22.py diff --git a/2019/day22.py b/2019/day22.py new file mode 100644 index 0000000..75def3e --- /dev/null +++ b/2019/day22.py @@ -0,0 +1,37 @@ +EX1 = [ + "cut 6", + "deal with increment 7", + "deal into new stack", +] + + +def main(): + with open("day22.txt") as input_file: + lines = [l.rstrip() for l in input_file.readlines()] + + deck = list(range(10007)) + for line in lines: + # Deal into new stack. + if line.endswith("k"): + deck.reverse() + continue + + arg = int(line[line.rfind(" "):]) + + # Deal with increment. + if line[0] == "d": + new_deck = [None] * len(deck) + for i in range(len(deck)): + new_deck[(i * arg) % len(new_deck)] = deck[i] + deck = new_deck + + # Cut. + elif line[0] == "c": + cut, deck = deck[:arg], deck[arg:] + deck += cut + + print(f"Position of card 2019: {deck.index(2019)}.") + + +if __name__ == "__main__": + main()