From 5012d9f4f6af8d4a3d4d417a83dfef0abc843397 Mon Sep 17 00:00:00 2001 From: Roman Hergenreder Date: Fri, 6 Dec 2019 14:52:09 +0100 Subject: [PATCH] Day 06 solved --- Day 06/decode.py | 34 ++++++++++++++++++++++++++++++++++ Day 06/input.html | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 Day 06/decode.py create mode 100644 Day 06/input.html diff --git a/Day 06/decode.py b/Day 06/decode.py new file mode 100644 index 0000000..149c2ba --- /dev/null +++ b/Day 06/decode.py @@ -0,0 +1,34 @@ +#!/usr/bin/python + +ciphertext = "" + +with open("input.html") as f: + data = f.read().strip() + for c in [",","."," ","\n"]: + data = data.replace(c, "") + while len(data) > 0: + i = data.find("") + if i == -1: # end + ciphertext += (5 - (len(ciphertext) % 5)) * "0" + break + elif i == 0: + j = data.find("") + ciphertext += (j - 4) * "1" + data = data[j+5:] + else: + ciphertext += i * "0" + data = data[i:] + +chunks = [] +chunks_decoded = [] + +for i in range(0, len(ciphertext), 5): + chunk = ciphertext[i:i+5] + num = int(chunk, 2) + chunks.append(num) + if num < 26: + chunks_decoded.append(chr(num + ord('A'))) + else: + chunks_decoded.append("?") + +print("".join(chunks_decoded)) diff --git a/Day 06/input.html b/Day 06/input.html new file mode 100644 index 0000000..28d1c8c --- /dev/null +++ b/Day 06/input.html @@ -0,0 +1,2 @@ +Francis Bacon was an English philosopher and statesman who served as Attorney General and as Lord Chancellor of England. His works are credited with developing the scientific method and remained influential through the scientific revolution. +Bacon has been called the father of empiricism. His works argued for the possibility of scientific knowledge based only upon inductive reasoning and careful observation of events in nature. Most importantly, he argued science could be achieved by use of a sceptical and methodical approach whereby scientists aim to avoid misleading themselves. Although his practical ideas about such a method, the Baconian method, did not have a long-lasting influence, the general idea of the importance and possibility of a sceptical methodology makes Bacon the father of the scientific method. This method was a new rhetorical and theoretical framework for science, the practical details of which are still central in debates about science and methodology.