From 0a44354a52015755b6d21ef61ad7b61ef80b77bc Mon Sep 17 00:00:00 2001 From: Srinivas P G Date: Sun, 23 Dec 2018 15:31:30 -0800 Subject: [PATCH] Day 12 initial commit --- .../Programming/adventOfCode/121.example | 17 +++++++ .../Programming/adventOfCode/121.py | 47 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 captureTheFlag/Programming/adventOfCode/121.example create mode 100644 captureTheFlag/Programming/adventOfCode/121.py diff --git a/captureTheFlag/Programming/adventOfCode/121.example b/captureTheFlag/Programming/adventOfCode/121.example new file mode 100644 index 0000000..7da08a0 --- /dev/null +++ b/captureTheFlag/Programming/adventOfCode/121.example @@ -0,0 +1,17 @@ +initial state: #..#.#..##......###...### + +...## => # +..#.. => # +.#... => # +.#.#. => # +.#.## => # +.##.. => # +.#### => # +#.#.# => # +#.### => # +##.#. => # +##.## => # +###.. => # +###.# => # +####. => # + diff --git a/captureTheFlag/Programming/adventOfCode/121.py b/captureTheFlag/Programming/adventOfCode/121.py new file mode 100644 index 0000000..e7b3dd9 --- /dev/null +++ b/captureTheFlag/Programming/adventOfCode/121.py @@ -0,0 +1,47 @@ +def generation(initial_state, notes_): + initial_state = list("..."+initial_state+"...........") + n = len(initial_state) + for i in range(1): + j = 0 + new_state = [] + while j < n: + select = "".join(initial_state[j:j+5]) + #print initial_state, select + if select in notes_: + select = list(".."+notes_[select]+"..") + #print select + initial_state[j:j+5] = select + j += 2 + else: + j+= 1 + print "".join(initial_state) + + #initial_state[j:j+5] = list(select) + #new_state.extend(list(select)) + #print "".join(initial_state) + #initial_state = new_state + + return "".join(initial_state) + +def main(): + # Fetch input from url + import requests, sys + # Sent the cookie set through the environment variable to get this + #input = requests.get("https://adventofcode.com/2018/day/8/input") + + # Hard Coded inputs + input = open("121.example","r").read() + input = input.split("\n") + generation_one = input[0].strip("initial state:").strip() + notes = input[2:] + notes_ = {} + for note in notes: + if note: + note = note.split("=>") + notes_[note[0].strip()] = note[1].strip() + #print generation_one, notes_ + print generation(generation_one, notes_) + #print "Day 12: Part 1 answer is --> " + str(count) + #print "Day 12: Part 2 answer is --> " + id + +main()