From 92ff3757adc17cab23088b292bd4b970443f4dab Mon Sep 17 00:00:00 2001 From: Lucidiot <15960782+Lucidiot@users.noreply.github.com> Date: Mon, 4 Dec 2017 19:17:43 +0100 Subject: [PATCH] Premiers puzzles --- .gitignore | 94 ++------------------------------------------- 2017/1/captcha.py | 12 ++++++ 2017/1/captcha2.py | 11 ++++++ 2017/2/checksum.py | 7 ++++ 2017/2/divisible.py | 20 ++++++++++ 2017/4/password.py | 5 +++ 2017/4/password2.py | 7 ++++ 7 files changed, 65 insertions(+), 91 deletions(-) create mode 100644 2017/1/captcha.py create mode 100644 2017/1/captcha2.py create mode 100644 2017/2/checksum.py create mode 100644 2017/2/divisible.py create mode 100644 2017/4/password.py create mode 100644 2017/4/password2.py diff --git a/.gitignore b/.gitignore index 7bbc71c..8df69d7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,99 +3,11 @@ __pycache__/ *.py[cod] *$py.class -# C extensions -*.so - -# Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -*.egg-info/ -.installed.cfg -*.egg - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -.hypothesis/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed files -*.sage.py - -# dotenv -.env - # virtualenv .venv venv/ ENV/ -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ +# Advent of Code puzzle inputs +input.txt +input diff --git a/2017/1/captcha.py b/2017/1/captcha.py new file mode 100644 index 0000000..f8e73a2 --- /dev/null +++ b/2017/1/captcha.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +import sys + +digits = [int(c) for c in sys.stdin.readline().rstrip()] + +sum = 0 +for i in range(len(digits)): + if digits[i] == digits[(i+1)%len(digits)]: + sum = sum + digits[i] + +print(sum) diff --git a/2017/1/captcha2.py b/2017/1/captcha2.py new file mode 100644 index 0000000..3ad919e --- /dev/null +++ b/2017/1/captcha2.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 + +import sys +digits = [int(c) for c in sys.stdin.readline().rstrip()] + +sum, half = 0, int(len(digits)/2) +for i in range(len(digits)): + if digits[i] == digits[(i+half)%len(digits)]: + sum = sum + digits[i] + +print(sum) diff --git a/2017/2/checksum.py b/2017/2/checksum.py new file mode 100644 index 0000000..2ed36ce --- /dev/null +++ b/2017/2/checksum.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 +import sys +data = [[int(n.rstrip()) for n in l.split('\t')] for l in sys.stdin] + +maxnum, minnum = [max(l) for l in data], [min(l) for l in data] +diff = [maxnum[n] - minnum[n] for n in range(len(maxnum))] +print(sum(diff)) diff --git a/2017/2/divisible.py b/2017/2/divisible.py new file mode 100644 index 0000000..f59134a --- /dev/null +++ b/2017/2/divisible.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +import sys +from itertools import product + +data = [[int(n.rstrip()) for n in l.split('\t')] for l in sys.stdin] + +result = [] +for line in [list(product(l, l)) for l in data]: + for tup in line: + if tup[0] == tup[1]: + continue + if tup[0] % tup[1] == 0: + result.append(tup) + break + elif tup[1] % tup[0] == 0: + result.append((tup[1], tup[0])) + break + +print(sum(tup[0] / tup[1] for tup in result)) diff --git a/2017/4/password.py b/2017/4/password.py new file mode 100644 index 0000000..50047c8 --- /dev/null +++ b/2017/4/password.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +import sys + +lines = [line.rstrip().lower().split(" ") for line in sys.stdin.readlines()] +print(len([1 for line in lines if len(set(line)) == len(line)])) diff --git a/2017/4/password2.py b/2017/4/password2.py new file mode 100644 index 0000000..01901d1 --- /dev/null +++ b/2017/4/password2.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 +import sys + +lines = [l.strip().split(" ") for l in sys.stdin.readlines()] + +print(sum([len(l)==len(set("".join(sorted(s)) for s in l)) for l in lines])) +