From 06a5771fbfceffeab6a9b279421d66086ec91235 Mon Sep 17 00:00:00 2001 From: Matthieu Bessat Date: Mon, 13 Dec 2021 10:08:40 +0100 Subject: [PATCH] day 11, 12 + folder refactoring --- {day_1 => 01_day}/code.py | 0 {day_1 => 01_day}/code2.py | 0 {day_1 => 01_day}/input1.txt | 0 {day_1 => 01_day}/input2.txt | 0 {day_2 => 02_day}/code.py | 0 {day_2 => 02_day}/input1.txt | 0 {day_2 => 02_day}/input2.txt | 0 {day_3 => 03_day}/code.py | 0 {day_3 => 03_day}/input1.txt | 0 {day_3 => 03_day}/input2.txt | 0 {day_3 => 03_day}/main | Bin {day_3 => 03_day}/main.c | 0 {day_3 => 03_day}/tobin.py | 0 {day_4 => 04_day}/code.py | 0 {day_4 => 04_day}/input1.txt | 0 {day_4 => 04_day}/input2.txt | 0 {day_4 => 04_day}/input3.txt | 0 {day_5 => 05_day}/CHANGELOG.md | 0 {day_5 => 05_day}/aocDay5.cabal | 0 {day_5 => 05_day}/app/Main.hs | 0 {day_5 => 05_day}/code | Bin {day_5 => 05_day}/code.hi | Bin {day_5 => 05_day}/code.hs | 0 {day_5 => 05_day}/code.o | Bin {day_5 => 05_day}/code.py | 0 .../build/aocDay5/autogen/Paths_aocDay5.hs | 0 .../build/aocDay5/autogen/cabal_macros.h | 0 .../aocDay5-0.1.0.0/x/aocDay5/cache/config | Bin .../package.conf.inplace/package.cache | Bin .../package.conf.inplace/package.cache.lock | 0 .../aocDay5-0.1.0.0/x/aocDay5/setup-config | Bin .../dist-newstyle/cache/compiler | Bin {day_5 => 05_day}/dist-newstyle/cache/config | Bin .../dist-newstyle/cache/elaborated-plan | Bin .../dist-newstyle/cache/improved-plan | Bin .../dist-newstyle/cache/plan.json | 0 .../dist-newstyle/cache/solver-plan | Bin .../dist-newstyle/cache/source-hashes | Bin .../dist-newstyle/cache/up-to-date | Bin .../packagedb/ghc-9.0.1/package.cache | Bin .../packagedb/ghc-9.0.1/package.cache.lock | 0 {day_5 => 05_day}/example.txt | 0 {day_5 => 05_day}/input.txt | 0 {day_6 => 06_day}/code.py | 0 {day_6 => 06_day}/example.txt | 0 {day_6 => 06_day}/input.txt | 0 {day_7 => 07_day}/code | Bin {day_7 => 07_day}/code.hi | Bin {day_7 => 07_day}/code.hs | 0 {day_7 => 07_day}/code.js | 0 {day_7 => 07_day}/code.o | Bin {day_7 => 07_day}/example.txt | 0 {day_7 => 07_day}/input.txt | 0 {day_8 => 08_day}/code.py | 0 {day_8 => 08_day}/example.txt | 0 {day_8 => 08_day}/example1.txt | 0 {day_8 => 08_day}/input.txt | 0 {day_9 => 09_day}/code.js | 0 {day_9 => 09_day}/example.txt | 0 {day_9 => 09_day}/input.txt | 0 {day_10 => 10_day}/code.py | 11 +- {day_10 => 10_day}/example.txt | 0 {day_10 => 10_day}/input.txt | 0 11_day/code.py | 67 ++ 11_day/example.txt | 5 + 11_day/example2.txt | 10 + 11_day/input.txt | 11 + 12_day/code.py | 74 ++ 12_day/code_part_1.py | 61 ++ 12_day/example1.txt | 7 + 12_day/example2.txt | 10 + 12_day/example3.txt | 18 + 12_day/input.txt | 24 + 12_day/wow1.py | 80 ++ 13_day/code.py | 109 +++ 13_day/example.txt | 21 + 13_day/input.txt | 729 ++++++++++++++++++ rename.sh | 13 + 78 files changed, 1242 insertions(+), 8 deletions(-) rename {day_1 => 01_day}/code.py (100%) rename {day_1 => 01_day}/code2.py (100%) rename {day_1 => 01_day}/input1.txt (100%) rename {day_1 => 01_day}/input2.txt (100%) rename {day_2 => 02_day}/code.py (100%) rename {day_2 => 02_day}/input1.txt (100%) rename {day_2 => 02_day}/input2.txt (100%) rename {day_3 => 03_day}/code.py (100%) rename {day_3 => 03_day}/input1.txt (100%) rename {day_3 => 03_day}/input2.txt (100%) rename {day_3 => 03_day}/main (100%) rename {day_3 => 03_day}/main.c (100%) rename {day_3 => 03_day}/tobin.py (100%) rename {day_4 => 04_day}/code.py (100%) rename {day_4 => 04_day}/input1.txt (100%) rename {day_4 => 04_day}/input2.txt (100%) rename {day_4 => 04_day}/input3.txt (100%) rename {day_5 => 05_day}/CHANGELOG.md (100%) rename {day_5 => 05_day}/aocDay5.cabal (100%) rename {day_5 => 05_day}/app/Main.hs (100%) rename {day_5 => 05_day}/code (100%) rename {day_5 => 05_day}/code.hi (100%) rename {day_5 => 05_day}/code.hs (100%) rename {day_5 => 05_day}/code.o (100%) rename {day_5 => 05_day}/code.py (100%) rename {day_5 => 05_day}/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/build/aocDay5/autogen/Paths_aocDay5.hs (100%) rename {day_5 => 05_day}/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/build/aocDay5/autogen/cabal_macros.h (100%) rename {day_5 => 05_day}/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/cache/config (100%) rename {day_5 => 05_day}/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/package.conf.inplace/package.cache (100%) rename {day_5 => 05_day}/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/package.conf.inplace/package.cache.lock (100%) rename {day_5 => 05_day}/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/setup-config (100%) rename {day_5 => 05_day}/dist-newstyle/cache/compiler (100%) rename {day_5 => 05_day}/dist-newstyle/cache/config (100%) rename {day_5 => 05_day}/dist-newstyle/cache/elaborated-plan (100%) rename {day_5 => 05_day}/dist-newstyle/cache/improved-plan (100%) rename {day_5 => 05_day}/dist-newstyle/cache/plan.json (100%) rename {day_5 => 05_day}/dist-newstyle/cache/solver-plan (100%) rename {day_5 => 05_day}/dist-newstyle/cache/source-hashes (100%) rename {day_5 => 05_day}/dist-newstyle/cache/up-to-date (100%) rename {day_5 => 05_day}/dist-newstyle/packagedb/ghc-9.0.1/package.cache (100%) rename {day_5 => 05_day}/dist-newstyle/packagedb/ghc-9.0.1/package.cache.lock (100%) rename {day_5 => 05_day}/example.txt (100%) rename {day_5 => 05_day}/input.txt (100%) rename {day_6 => 06_day}/code.py (100%) rename {day_6 => 06_day}/example.txt (100%) rename {day_6 => 06_day}/input.txt (100%) rename {day_7 => 07_day}/code (100%) rename {day_7 => 07_day}/code.hi (100%) rename {day_7 => 07_day}/code.hs (100%) rename {day_7 => 07_day}/code.js (100%) rename {day_7 => 07_day}/code.o (100%) rename {day_7 => 07_day}/example.txt (100%) rename {day_7 => 07_day}/input.txt (100%) rename {day_8 => 08_day}/code.py (100%) rename {day_8 => 08_day}/example.txt (100%) rename {day_8 => 08_day}/example1.txt (100%) rename {day_8 => 08_day}/input.txt (100%) rename {day_9 => 09_day}/code.js (100%) rename {day_9 => 09_day}/example.txt (100%) rename {day_9 => 09_day}/input.txt (100%) rename {day_10 => 10_day}/code.py (92%) rename {day_10 => 10_day}/example.txt (100%) rename {day_10 => 10_day}/input.txt (100%) create mode 100644 11_day/code.py create mode 100644 11_day/example.txt create mode 100644 11_day/example2.txt create mode 100644 11_day/input.txt create mode 100644 12_day/code.py create mode 100644 12_day/code_part_1.py create mode 100644 12_day/example1.txt create mode 100644 12_day/example2.txt create mode 100644 12_day/example3.txt create mode 100644 12_day/input.txt create mode 100644 12_day/wow1.py create mode 100644 13_day/code.py create mode 100644 13_day/example.txt create mode 100644 13_day/input.txt create mode 100644 rename.sh diff --git a/day_1/code.py b/01_day/code.py similarity index 100% rename from day_1/code.py rename to 01_day/code.py diff --git a/day_1/code2.py b/01_day/code2.py similarity index 100% rename from day_1/code2.py rename to 01_day/code2.py diff --git a/day_1/input1.txt b/01_day/input1.txt similarity index 100% rename from day_1/input1.txt rename to 01_day/input1.txt diff --git a/day_1/input2.txt b/01_day/input2.txt similarity index 100% rename from day_1/input2.txt rename to 01_day/input2.txt diff --git a/day_2/code.py b/02_day/code.py similarity index 100% rename from day_2/code.py rename to 02_day/code.py diff --git a/day_2/input1.txt b/02_day/input1.txt similarity index 100% rename from day_2/input1.txt rename to 02_day/input1.txt diff --git a/day_2/input2.txt b/02_day/input2.txt similarity index 100% rename from day_2/input2.txt rename to 02_day/input2.txt diff --git a/day_3/code.py b/03_day/code.py similarity index 100% rename from day_3/code.py rename to 03_day/code.py diff --git a/day_3/input1.txt b/03_day/input1.txt similarity index 100% rename from day_3/input1.txt rename to 03_day/input1.txt diff --git a/day_3/input2.txt b/03_day/input2.txt similarity index 100% rename from day_3/input2.txt rename to 03_day/input2.txt diff --git a/day_3/main b/03_day/main similarity index 100% rename from day_3/main rename to 03_day/main diff --git a/day_3/main.c b/03_day/main.c similarity index 100% rename from day_3/main.c rename to 03_day/main.c diff --git a/day_3/tobin.py b/03_day/tobin.py similarity index 100% rename from day_3/tobin.py rename to 03_day/tobin.py diff --git a/day_4/code.py b/04_day/code.py similarity index 100% rename from day_4/code.py rename to 04_day/code.py diff --git a/day_4/input1.txt b/04_day/input1.txt similarity index 100% rename from day_4/input1.txt rename to 04_day/input1.txt diff --git a/day_4/input2.txt b/04_day/input2.txt similarity index 100% rename from day_4/input2.txt rename to 04_day/input2.txt diff --git a/day_4/input3.txt b/04_day/input3.txt similarity index 100% rename from day_4/input3.txt rename to 04_day/input3.txt diff --git a/day_5/CHANGELOG.md b/05_day/CHANGELOG.md similarity index 100% rename from day_5/CHANGELOG.md rename to 05_day/CHANGELOG.md diff --git a/day_5/aocDay5.cabal b/05_day/aocDay5.cabal similarity index 100% rename from day_5/aocDay5.cabal rename to 05_day/aocDay5.cabal diff --git a/day_5/app/Main.hs b/05_day/app/Main.hs similarity index 100% rename from day_5/app/Main.hs rename to 05_day/app/Main.hs diff --git a/day_5/code b/05_day/code similarity index 100% rename from day_5/code rename to 05_day/code diff --git a/day_5/code.hi b/05_day/code.hi similarity index 100% rename from day_5/code.hi rename to 05_day/code.hi diff --git a/day_5/code.hs b/05_day/code.hs similarity index 100% rename from day_5/code.hs rename to 05_day/code.hs diff --git a/day_5/code.o b/05_day/code.o similarity index 100% rename from day_5/code.o rename to 05_day/code.o diff --git a/day_5/code.py b/05_day/code.py similarity index 100% rename from day_5/code.py rename to 05_day/code.py diff --git a/day_5/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/build/aocDay5/autogen/Paths_aocDay5.hs b/05_day/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/build/aocDay5/autogen/Paths_aocDay5.hs similarity index 100% rename from day_5/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/build/aocDay5/autogen/Paths_aocDay5.hs rename to 05_day/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/build/aocDay5/autogen/Paths_aocDay5.hs diff --git a/day_5/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/build/aocDay5/autogen/cabal_macros.h b/05_day/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/build/aocDay5/autogen/cabal_macros.h similarity index 100% rename from day_5/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/build/aocDay5/autogen/cabal_macros.h rename to 05_day/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/build/aocDay5/autogen/cabal_macros.h diff --git a/day_5/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/cache/config b/05_day/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/cache/config similarity index 100% rename from day_5/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/cache/config rename to 05_day/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/cache/config diff --git a/day_5/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/package.conf.inplace/package.cache b/05_day/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/package.conf.inplace/package.cache similarity index 100% rename from day_5/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/package.conf.inplace/package.cache rename to 05_day/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/package.conf.inplace/package.cache diff --git a/day_5/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/package.conf.inplace/package.cache.lock b/05_day/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/package.conf.inplace/package.cache.lock similarity index 100% rename from day_5/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/package.conf.inplace/package.cache.lock rename to 05_day/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/package.conf.inplace/package.cache.lock diff --git a/day_5/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/setup-config b/05_day/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/setup-config similarity index 100% rename from day_5/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/setup-config rename to 05_day/dist-newstyle/build/x86_64-linux/ghc-9.0.1/aocDay5-0.1.0.0/x/aocDay5/setup-config diff --git a/day_5/dist-newstyle/cache/compiler b/05_day/dist-newstyle/cache/compiler similarity index 100% rename from day_5/dist-newstyle/cache/compiler rename to 05_day/dist-newstyle/cache/compiler diff --git a/day_5/dist-newstyle/cache/config b/05_day/dist-newstyle/cache/config similarity index 100% rename from day_5/dist-newstyle/cache/config rename to 05_day/dist-newstyle/cache/config diff --git a/day_5/dist-newstyle/cache/elaborated-plan b/05_day/dist-newstyle/cache/elaborated-plan similarity index 100% rename from day_5/dist-newstyle/cache/elaborated-plan rename to 05_day/dist-newstyle/cache/elaborated-plan diff --git a/day_5/dist-newstyle/cache/improved-plan b/05_day/dist-newstyle/cache/improved-plan similarity index 100% rename from day_5/dist-newstyle/cache/improved-plan rename to 05_day/dist-newstyle/cache/improved-plan diff --git a/day_5/dist-newstyle/cache/plan.json b/05_day/dist-newstyle/cache/plan.json similarity index 100% rename from day_5/dist-newstyle/cache/plan.json rename to 05_day/dist-newstyle/cache/plan.json diff --git a/day_5/dist-newstyle/cache/solver-plan b/05_day/dist-newstyle/cache/solver-plan similarity index 100% rename from day_5/dist-newstyle/cache/solver-plan rename to 05_day/dist-newstyle/cache/solver-plan diff --git a/day_5/dist-newstyle/cache/source-hashes b/05_day/dist-newstyle/cache/source-hashes similarity index 100% rename from day_5/dist-newstyle/cache/source-hashes rename to 05_day/dist-newstyle/cache/source-hashes diff --git a/day_5/dist-newstyle/cache/up-to-date b/05_day/dist-newstyle/cache/up-to-date similarity index 100% rename from day_5/dist-newstyle/cache/up-to-date rename to 05_day/dist-newstyle/cache/up-to-date diff --git a/day_5/dist-newstyle/packagedb/ghc-9.0.1/package.cache b/05_day/dist-newstyle/packagedb/ghc-9.0.1/package.cache similarity index 100% rename from day_5/dist-newstyle/packagedb/ghc-9.0.1/package.cache rename to 05_day/dist-newstyle/packagedb/ghc-9.0.1/package.cache diff --git a/day_5/dist-newstyle/packagedb/ghc-9.0.1/package.cache.lock b/05_day/dist-newstyle/packagedb/ghc-9.0.1/package.cache.lock similarity index 100% rename from day_5/dist-newstyle/packagedb/ghc-9.0.1/package.cache.lock rename to 05_day/dist-newstyle/packagedb/ghc-9.0.1/package.cache.lock diff --git a/day_5/example.txt b/05_day/example.txt similarity index 100% rename from day_5/example.txt rename to 05_day/example.txt diff --git a/day_5/input.txt b/05_day/input.txt similarity index 100% rename from day_5/input.txt rename to 05_day/input.txt diff --git a/day_6/code.py b/06_day/code.py similarity index 100% rename from day_6/code.py rename to 06_day/code.py diff --git a/day_6/example.txt b/06_day/example.txt similarity index 100% rename from day_6/example.txt rename to 06_day/example.txt diff --git a/day_6/input.txt b/06_day/input.txt similarity index 100% rename from day_6/input.txt rename to 06_day/input.txt diff --git a/day_7/code b/07_day/code similarity index 100% rename from day_7/code rename to 07_day/code diff --git a/day_7/code.hi b/07_day/code.hi similarity index 100% rename from day_7/code.hi rename to 07_day/code.hi diff --git a/day_7/code.hs b/07_day/code.hs similarity index 100% rename from day_7/code.hs rename to 07_day/code.hs diff --git a/day_7/code.js b/07_day/code.js similarity index 100% rename from day_7/code.js rename to 07_day/code.js diff --git a/day_7/code.o b/07_day/code.o similarity index 100% rename from day_7/code.o rename to 07_day/code.o diff --git a/day_7/example.txt b/07_day/example.txt similarity index 100% rename from day_7/example.txt rename to 07_day/example.txt diff --git a/day_7/input.txt b/07_day/input.txt similarity index 100% rename from day_7/input.txt rename to 07_day/input.txt diff --git a/day_8/code.py b/08_day/code.py similarity index 100% rename from day_8/code.py rename to 08_day/code.py diff --git a/day_8/example.txt b/08_day/example.txt similarity index 100% rename from day_8/example.txt rename to 08_day/example.txt diff --git a/day_8/example1.txt b/08_day/example1.txt similarity index 100% rename from day_8/example1.txt rename to 08_day/example1.txt diff --git a/day_8/input.txt b/08_day/input.txt similarity index 100% rename from day_8/input.txt rename to 08_day/input.txt diff --git a/day_9/code.js b/09_day/code.js similarity index 100% rename from day_9/code.js rename to 09_day/code.js diff --git a/day_9/example.txt b/09_day/example.txt similarity index 100% rename from day_9/example.txt rename to 09_day/example.txt diff --git a/day_9/input.txt b/09_day/input.txt similarity index 100% rename from day_9/input.txt rename to 09_day/input.txt diff --git a/day_10/code.py b/10_day/code.py similarity index 92% rename from day_10/code.py rename to 10_day/code.py index c4e1ba6..9b5a98d 100644 --- a/day_10/code.py +++ b/10_day/code.py @@ -1,11 +1,6 @@ import fileinput -scores = [ - 3, - 57, - 1197, - 25137 -] +scores = [3, 57, 1197, 25137] opening_chars = ['(', '[', '{', '<'] closing_chars = [')', ']', '}', '>'] @@ -23,10 +18,10 @@ for line in lines: complete = True for column, c in enumerate(line): if c in opening_chars: - stack.append(c) + stack.append(opening_chars.index(c)) if c in closing_chars: i = closing_chars.index(c) - if stack[-1] != opening_chars[i]: + if stack[-1] != i: expected_i = opening_chars.index(stack[-1]) # print(line) diff --git a/day_10/example.txt b/10_day/example.txt similarity index 100% rename from day_10/example.txt rename to 10_day/example.txt diff --git a/day_10/input.txt b/10_day/input.txt similarity index 100% rename from day_10/input.txt rename to 10_day/input.txt diff --git a/11_day/code.py b/11_day/code.py new file mode 100644 index 0000000..44d2d25 --- /dev/null +++ b/11_day/code.py @@ -0,0 +1,67 @@ +import pprint +import fileinput + +rows = [] +for line in fileinput.input(): + l = line.strip() + if l == '': + continue + rows.append(list(map(int, list(l)))) + +pprint.pprint(rows) + +def print_table(rows): + for r in rows: + print(''.join(map(str, r))) + +def is_all_zeros(rows): + return list(map(lambda r: ''.join(map(str, r)), rows)) == 10*[10*'0'] + +print_table(rows) + +flashes = 0 +for step in range(10000): + print(f'step #{step}') + locked = [] + pops = 1 + while pops > 0: + pops = 0 + for i in range(10): + for j in range(10): + if rows[i][j] >= 9: + pops += 1 + flashes += 1 + diagonals = [ + (i-1, j-1), + (i-1, j), + (i-1, j+1), + (i, j-1), + (i, j+1), + (i+1, j-1), + (i+1, j), + (i+1, j+1) + ] + rows[i][j] = 0 + locked.append((i, j)) + for y,x in diagonals: + if not (0 <= y < 10 and 0 <= x < 10): continue + if (y, x) in locked: continue + rows[y][x] += 1 + + for i in range(10): + for j in range(10): + if (i, j) in locked: continue + rows[i][j] += 1 + + if is_all_zeros(rows): + print(rows) + print_table(rows) + print(step+1) + break + + print_table(rows) + +pprint.pprint(rows) +print(flashes) + + diff --git a/11_day/example.txt b/11_day/example.txt new file mode 100644 index 0000000..ae21dd2 --- /dev/null +++ b/11_day/example.txt @@ -0,0 +1,5 @@ +11111 +19991 +19191 +19991 +11111 diff --git a/11_day/example2.txt b/11_day/example2.txt new file mode 100644 index 0000000..03743f6 --- /dev/null +++ b/11_day/example2.txt @@ -0,0 +1,10 @@ +5483143223 +2745854711 +5264556173 +6141336146 +6357385478 +4167524645 +2176841721 +6882881134 +4846848554 +5283751526 diff --git a/11_day/input.txt b/11_day/input.txt new file mode 100644 index 0000000..cbbdd4f --- /dev/null +++ b/11_day/input.txt @@ -0,0 +1,11 @@ +4781623888 +1784156114 +3265645122 +4371551414 +3377154886 +7882314455 +6421348681 +7175424287 +5488242184 +2448568261 + diff --git a/12_day/code.py b/12_day/code.py new file mode 100644 index 0000000..c44de00 --- /dev/null +++ b/12_day/code.py @@ -0,0 +1,74 @@ +import pprint +import itertools +import fileinput + +nodes = [] +edges = [] +for raw in fileinput.input(): + line = raw.strip() + if line == '': continue + [a,b] = line.split('-') + nodes += [a, b] + edges.append((a, b)) + +nodes = list(set(nodes)) +nodes.sort() + +graph = [[0 for j in range(len(nodes))] for i in range(len(nodes))] + +#pprint.pprint(graph) + +for (a,b) in edges: + i, j = nodes.index(a), nodes.index(b) + graph[i][j] = 1 + graph[j][i] = 1 + +visit_only_once = [e for e in nodes if e.lower() == e and e != 'start' and e != 'end'] + +start_index = nodes.index('start') +end_index = nodes.index('end') + +nodes_d = [(i,e) for i,e in enumerate(nodes)] + +print(f'{nodes_d=}') +print(f'{visit_only_once=}') + +visit_only_once_index = [nodes.index(e) for e in visit_only_once]+[start_index, end_index] + +def explore_path(stack, level, locked, s, did_visit_twice): + edges = [i for i,e in enumerate(graph[s]) if e] + + if s == end_index: + return [s] + [stack] + + paths = [] + for edge in edges: + if edge == start_index: continue + + if edge in visit_only_once_index: + if edge in locked: + if not did_visit_twice and edge != start_index and edge != end_index: + did_visit_twice = True + else: + continue + locked.add(edge) + + #print(f'{level=} , {nodes[edge]=}, {new_locked=}, {at_most=} ') + paths += explore_path([s]+stack, level+1, locked.copy(), edge, did_visit_twice) + return paths + +print('start exploring...') + +paths = explore_path([], 0, set(), start_index, False) + +all_paths = [ ''.join(map(str, p)) for p in paths ] + +res = list(set(all_paths)) + +for p in res: + new_p = list(map(int, list(p))) + #print([ nodes[i] for i in list(reversed(new_p))]) + +#print(res) + +print(f'There are {len(res)} paths') diff --git a/12_day/code_part_1.py b/12_day/code_part_1.py new file mode 100644 index 0000000..758e74d --- /dev/null +++ b/12_day/code_part_1.py @@ -0,0 +1,61 @@ +import pprint +import itertools +import fileinput + +nodes = [] +edges = [] +for raw in fileinput.input(): + line = raw.strip() + if line == '': continue + [a,b] = line.split('-') + nodes += [a, b] + edges.append((a, b)) + +nodes = list(set(nodes)) +nodes.sort() + +graph = [[0 for j in range(len(nodes))] for i in range(len(nodes))] + +#pprint.pprint(graph) + +for (a,b) in edges: + i, j = nodes.index(a), nodes.index(b) + graph[i][j] = 1 + graph[j][i] = 1 + +visit_only_once = [e for e in nodes if e.lower() == e and e != 'start' and e != 'end'] + +start_index = nodes.index('start') +end_index = nodes.index('end') + +print(f'{visit_only_once=}') + +visit_only_once_index = [nodes.index(e) for e in visit_only_once] + +possibles = [] + +def explore_path(stack, level, locked, s): + edges = [i for i,e in enumerate(graph[s]) if e] + + if s == end_index: + possibles.append(stack) + return + + for edge in edges: + new_locked = locked.copy() + if edge in locked: continue + if edge == start_index: continue + if edge in visit_only_once_index: + new_locked += [edge] + + #print(f'{level=} , {nodes[edge]=}, {new_locked=}') + explore_path([s]+stack, level+1, new_locked, edge) + +print('start exploring...') + +explore_path([], 0, [], start_index) + +for p in possibles: + print([ nodes[i] for i in list(reversed(p))]) + +print(f'There are {len(possibles)} paths') diff --git a/12_day/example1.txt b/12_day/example1.txt new file mode 100644 index 0000000..898cd56 --- /dev/null +++ b/12_day/example1.txt @@ -0,0 +1,7 @@ +start-A +start-b +A-c +A-b +b-d +A-end +b-end \ No newline at end of file diff --git a/12_day/example2.txt b/12_day/example2.txt new file mode 100644 index 0000000..62cc714 --- /dev/null +++ b/12_day/example2.txt @@ -0,0 +1,10 @@ +dc-end +HN-start +start-kj +dc-start +dc-HN +LN-dc +HN-end +kj-sa +kj-HN +kj-dc diff --git a/12_day/example3.txt b/12_day/example3.txt new file mode 100644 index 0000000..65f3833 --- /dev/null +++ b/12_day/example3.txt @@ -0,0 +1,18 @@ +fs-end +he-DX +fs-he +start-DX +pj-DX +end-zg +zg-sl +zg-pj +pj-he +RW-he +fs-DX +pj-RW +zg-RW +start-pj +he-WI +zg-he +pj-fs +start-RW diff --git a/12_day/input.txt b/12_day/input.txt new file mode 100644 index 0000000..4067b56 --- /dev/null +++ b/12_day/input.txt @@ -0,0 +1,24 @@ +yb-pi +jg-ej +yb-KN +LD-start +end-UF +UF-yb +yb-xd +qx-yb +xd-end +jg-KN +start-qx +start-ej +qx-LD +jg-LD +xd-LD +ej-qx +end-KN +DM-xd +jg-yb +ej-LD +qx-UF +UF-jg +qx-jg +xd-UF diff --git a/12_day/wow1.py b/12_day/wow1.py new file mode 100644 index 0000000..42fedc8 --- /dev/null +++ b/12_day/wow1.py @@ -0,0 +1,80 @@ +import fileinput + +def read_file(): + return [line.strip() for line in fileinput.input()] + +def make_graph(lines): + graph = {} + small_caves = set() + for line in lines: + a, b = line.split('-') + add_path(graph, a, b) + add_path(graph, b, a) + if a.islower(): + small_caves.add(a) + if b.islower(): + small_caves.add(b) + return graph, small_caves + + +def add_path(graph, a, b): + nodes = graph.get(a) + if nodes == None: + graph[a] = [b] + else: + nodes.append(b) + + +def find_paths(graph, + small_caves, + can_visit_twice, + current, + end, + path, + small_visited, + did_visit_twice=False): + + if current in small_caves: + if current in small_visited: + if can_visit_twice and not did_visit_twice and current != 'start' and current != 'end': + did_visit_twice = True + else: + return None + small_visited.add(current) + + path.append(current) + + if current == end: + return [path] + + paths = [] + connected = graph[current] + for cave in connected: + subpaths = find_paths(graph, small_caves, can_visit_twice, cave, end, + path.copy(), small_visited.copy(), did_visit_twice) + if subpaths != None: + paths.extend(subpaths) + + return paths + + +def print_graph(graph): + for key, value in graph.items(): + for cave in value: + print(f"{key} -> {cave}") + + +def print_paths(paths): + for path in paths: + print(','.join(path)) + + +input = read_file() +graph, small_caves = make_graph(input) + +paths = find_paths(graph, small_caves, False, 'start', 'end', [], set()) +print(f"Part 1: {len(paths)}") + +paths = find_paths(graph, small_caves, True, 'start', 'end', [], set()) +print(f"Part 2: {len(paths)}") + diff --git a/13_day/code.py b/13_day/code.py new file mode 100644 index 0000000..7f83d40 --- /dev/null +++ b/13_day/code.py @@ -0,0 +1,109 @@ +import fileinput + +def make_matrix(rows, columns, default = False): + return [ + [default for c in range(columns)] for r in range(rows) + ] + +def parse_input(lines): + X = [] + Y = [] + folds = [] + for l in lines: + l = l.strip() + if l == '': + continue + if 'fold along' in l: + folds.append( + ('x' if 'x' in l else 'y', int(l.split('=')[1])) + ) + else: + c = list(map(int, l.split(','))) + X.append(c[0]) + Y.append(c[1]) + + maxX, maxY = max(X), max(Y) + + rows = make_matrix(maxY+1, maxX+1) + for x,y in zip(X, Y): + rows[y][x] = True + + return X, Y, folds, rows + +def draw_board(rows): + for r in rows: + line = '' + for c in r: + if not c: + line += '.' + else: + line += 'X' + print(line) + +def merge_in(a, b): + new = [] + for i in range(len(a)): + if a[i] or b[i]: + new.append(True) + else: + new.append(False) + return new + +def get_column(rows, index): + out = [] + for r in rows: + out.append(r[index]) + return out + +def set_column(rows, j, col): + out = rows.copy() + for i,c in enumerate(col): + out[i][j] = c + return out + + +def fold_along(rows, along, c): + print(f'fold {along=} {c=}') + new_rows = [] + h = len(rows) + w = len(rows[0]) + if along == 'y': + new_rows = make_matrix(c, w) + for i in range(0, c): + if i > 2*c-h: + new_rows[i] = ( + merge_in( + rows[i], + rows[h-i-1] + ) + ) + if along == 'x': + new_rows = make_matrix(len(rows), c) + for j in range(0, c): + if j > 2*c-w: + new_rows = ( + set_column(new_rows, j, merge_in( + get_column(rows, j), + get_column(rows, w-j-1) + )) + ) + return new_rows + +def count_dots(rows): + count = 0 + for r in rows: + for c in r: + if c: count += 1 + return count + +def main(): + X, Y, folds, rows = parse_input(fileinput.input()) + after_fold = rows.copy() + for along, c in folds: + after_fold = fold_along(after_fold, along, c) + count = count_dots(after_fold) + print(count) + + draw_board(after_fold) + +main() diff --git a/13_day/example.txt b/13_day/example.txt new file mode 100644 index 0000000..32a8563 --- /dev/null +++ b/13_day/example.txt @@ -0,0 +1,21 @@ +6,10 +0,14 +9,10 +0,3 +10,4 +4,11 +6,0 +6,12 +4,1 +0,13 +10,12 +3,4 +3,0 +8,4 +1,10 +2,14 +8,10 +9,0 + +fold along y=7 +fold along x=5 \ No newline at end of file diff --git a/13_day/input.txt b/13_day/input.txt new file mode 100644 index 0000000..13a2037 --- /dev/null +++ b/13_day/input.txt @@ -0,0 +1,729 @@ +1302,268 +872,390 +164,653 +1257,768 +649,367 +314,747 +239,246 +572,431 +610,427 +495,876 +321,8 +457,553 +1174,140 +470,728 +216,266 +142,502 +611,831 +475,630 +216,504 +845,23 +99,427 +1037,334 +381,112 +616,859 +982,876 +561,322 +249,99 +987,652 +793,729 +606,579 +1017,140 +679,81 +544,0 +1274,259 +1235,246 +1200,266 +903,588 +807,103 +17,455 +527,829 +512,144 +523,37 +976,140 +662,490 +570,180 +1159,791 +816,271 +740,266 +149,805 +570,266 +410,92 +1235,462 +363,45 +1004,362 +331,204 +724,462 +845,247 +395,138 +758,816 +939,511 +472,189 +184,750 +1295,134 +513,745 +735,140 +1179,37 +1009,135 +331,690 +704,355 +502,498 +274,614 +308,427 +216,180 +5,864 +1287,305 +1046,859 +807,327 +117,229 +326,18 +1093,840 +572,802 +1253,683 +262,721 +786,679 +987,764 +1061,99 +610,467 +473,775 +53,560 +1126,840 +267,885 +792,82 +631,253 +704,539 +0,360 +1216,14 +60,428 +552,485 +1295,312 +199,437 +206,91 +1262,355 +989,310 +1292,733 +982,18 +1044,416 +407,588 +1126,40 +556,609 +1208,814 +766,378 +1049,259 +23,589 +1101,480 +1223,44 +681,324 +1206,544 +306,114 +1146,653 +503,327 +1293,439 +853,553 +463,376 +959,529 +490,260 +783,491 +596,208 +750,880 +447,287 +15,299 +431,434 +131,37 +934,763 +947,334 +73,521 +8,178 +935,278 +136,562 +1009,725 +740,180 +648,490 +415,716 +311,376 +730,801 +115,392 +952,145 +1076,732 +1171,365 +1245,850 +792,562 +32,528 +465,247 +771,112 +353,583 +1235,866 +246,802 +922,245 +1250,390 +1140,728 +102,78 +422,14 +487,242 +1186,747 +597,659 +539,502 +596,462 +1250,652 +438,504 +689,306 +75,246 +699,831 +328,86 +184,502 +552,814 +703,40 +351,164 +977,397 +638,173 +808,498 +691,437 +0,260 +480,274 +725,829 +115,502 +393,655 +875,471 +967,749 +115,54 +1278,366 +704,864 +816,607 +435,378 +1217,572 +527,491 +592,35 +430,256 +1119,152 +1026,399 +1071,178 +196,782 +136,82 +1019,605 +103,885 +430,394 +713,235 +142,392 +274,448 +189,647 +346,285 +734,273 +468,504 +539,560 +991,728 +1243,532 +206,763 +455,894 +1231,588 +320,364 +363,114 +15,312 +1285,311 +815,876 +773,99 +448,383 +117,99 +488,523 +838,189 +103,457 +982,428 +1190,131 +552,816 +797,689 +388,245 +207,831 +1151,876 +1288,56 +1299,712 +246,702 +199,289 +420,162 +952,222 +1216,674 +758,500 +315,227 +494,175 +80,683 +261,259 +1124,56 +199,448 +189,23 +1164,273 +813,79 +1156,738 +552,500 +716,166 +151,791 +488,607 +127,558 +166,523 +982,466 +141,689 +1131,626 +868,366 +442,427 +167,169 +1094,448 +67,532 +662,404 +642,539 +1009,759 +1160,544 +924,583 +552,526 +909,712 +907,866 +147,268 +88,812 +380,714 +321,30 +93,322 +104,350 +311,33 +1143,690 +1174,82 +1248,859 +216,740 +25,324 +35,347 +964,161 +258,450 +435,277 +239,268 +487,169 +967,319 +606,864 +930,894 +534,691 +900,463 +1310,534 +646,626 +18,691 +223,605 +75,169 +1144,623 +749,322 +283,511 +1272,35 +1310,708 +196,231 +606,366 +492,241 +1128,705 +341,537 +176,450 +1310,260 +1144,355 +1203,337 +977,721 +321,702 +171,633 +154,604 +542,481 +306,810 +259,756 +222,798 +375,165 +718,467 +77,771 +1151,18 +1208,409 +130,231 +818,241 +959,753 +1093,56 +1248,203 +964,61 +773,638 +315,219 +631,753 +1144,523 +1143,242 +217,838 +1298,763 +405,771 +407,754 +1248,467 +979,204 +1290,207 +683,422 +1258,796 +1036,796 +590,497 +331,242 +119,595 +566,82 +1158,498 +759,12 +1255,535 +455,885 +1287,813 +346,609 +754,609 +813,169 +1302,716 +1169,689 +915,756 +1159,103 +1007,365 +885,149 +185,205 +483,709 +1146,634 +689,588 +1305,864 +997,537 +1061,795 +1009,583 +3,729 +688,560 +469,689 +979,242 +562,63 +49,54 +1111,894 +606,752 +303,365 +694,35 +480,620 +25,886 +94,462 +977,49 +217,86 +1052,674 +503,119 +1235,28 +813,290 +520,882 +649,30 +261,689 +213,168 +171,185 +497,815 +75,28 +949,677 +1049,595 +246,876 +8,268 +1141,277 +850,224 +411,735 +78,621 +27,248 +503,103 +1292,691 +371,511 +151,103 +1134,831 +177,253 +11,787 +1001,7 +458,231 +1119,742 +651,242 +157,613 +995,103 +124,147 +729,854 +731,648 +482,725 +348,431 +1076,511 +216,448 +403,14 +261,595 +12,819 +1279,821 +64,497 +638,721 +1144,47 +15,134 +259,585 +179,268 +964,285 +1086,534 +930,0 +480,572 +1067,735 +1104,355 +94,880 +181,567 +629,501 +257,124 +629,214 +560,880 +1017,588 +611,299 +730,129 +947,114 +266,478 +55,535 +753,575 +977,254 +147,299 +1305,31 +792,754 +594,166 +1275,224 +380,0 +700,467 +246,192 +146,621 +768,316 +12,399 +284,847 +147,595 +1287,641 +817,658 +99,467 +535,147 +1257,126 +947,45 +102,857 +691,65 +999,767 +518,562 +351,529 +642,75 +1275,347 +494,287 +872,628 +1203,221 +1295,299 +914,2 +386,0 +1133,253 +1163,299 +1032,416 +1195,112 +661,845 +658,770 +701,390 +997,810 +957,103 +323,652 +574,130 +750,220 +60,142 +689,712 +656,360 +749,236 +216,628 +753,149 +681,680 +371,75 +18,257 +333,456 +209,480 +333,886 +320,754 +1032,780 +534,651 +32,366 +1232,621 +775,63 +524,679 +758,409 +872,446 +358,145 +1285,324 +1066,431 +1066,463 +813,255 +924,311 +306,362 +683,24 +1125,205 +812,68 +681,886 +274,796 +542,126 +294,334 +1265,56 +907,880 +776,691 +560,462 +557,121 +691,457 +309,887 +410,687 +679,641 +311,518 +890,511 +152,498 +807,567 +1226,714 +156,68 +823,617 +438,154 +1053,829 +478,831 +181,327 +704,752 +408,18 +828,169 +388,30 +167,725 +547,337 +112,894 +104,96 +840,502 +798,502 +930,98 +498,168 +947,849 +893,432 +959,365 +375,726 +261,207 +651,725 +1295,760 +182,705 +336,738 +1261,54 +1223,850 +907,656 +1031,616 +246,18 +544,628 +736,683 +1310,360 +212,467 +1139,633 +1141,290 +186,56 +1226,180 +62,859 +191,742 +497,290 +991,166 +930,390 +169,277 +570,714 +194,224 +1285,772 +60,80 +607,40 +1104,383 +93,572 +305,381 +1044,142 +463,742 +1285,456 +113,705 +855,885 +709,544 +1198,0 +1212,609 +358,672 +905,123 +303,267 +734,852 +1004,738 +1146,260 +585,65 +855,894 +115,782 +251,609 +934,150 +962,431 +1088,96 +448,511 +1021,567 +537,638 +977,310 +455,157 +62,203 +1258,628 +184,816 +1009,169 +633,513 +537,99 +838,145 +1278,528 +442,19 +258,444 +800,413 +962,532 +542,768 +949,217 +999,376 +485,290 +469,205 +823,242 +1235,277 +725,65 +825,277 +735,306 +803,268 +79,306 +1001,887 +223,882 +823,277 +27,198 +381,782 +913,322 +1235,725 +376,416 +249,795 +643,623 +1125,653 +649,79 +1237,521 +840,392 +999,319 +62,427 +1032,478 +420,732 +962,362 +873,392 +341,84 +330,770 +217,392 +847,742 +674,637 +738,431 +852,112 +387,625 +518,332 +589,492 +480,322 +816,287 +1307,617 +841,689 +668,399 +840,78 +1036,0 +328,466 +319,728 +1005,381 +446,355 +328,876 +185,653 +1115,665 +278,780 +217,56 +664,626 +373,627 +848,854 +30,525 +244,431 +817,236 +498,826 +1043,45 +162,241 +229,297 + +fold along x=655 +fold along y=447 +fold along x=327 +fold along y=223 +fold along x=163 +fold along y=111 +fold along x=81 +fold along y=55 +fold along x=40 +fold along y=27 +fold along y=13 +fold along y=6 + diff --git a/rename.sh b/rename.sh new file mode 100644 index 0000000..8535cf4 --- /dev/null +++ b/rename.sh @@ -0,0 +1,13 @@ +for f in *_day +do + fullfile="$f" + filename=$(basename "$fullfile") + new=$(echo $filename | awk '{split($1,a,"_"); printf "%s",a[1]}') + len=$(echo -n "$new" | wc -c) + if [[ $len == 1 ]]; then + new="0"$filename + else + new=$filename + fi + mv $filename $new +done