From 6f916c29d1384d76481c9b14ea37e0af1c452dc2 Mon Sep 17 00:00:00 2001 From: Roland Thomas Date: Fri, 7 Jul 2023 00:47:08 -0400 Subject: [PATCH] Initial commit --- 2015/day1 | 1 + 2015/day1.py | 24 + 2015/day7 | 339 ++++++ 2015/day7.py | 36 + 2015/day7.sample | 8 + 2016/day1 | 1 + 2016/day1.py | 98 ++ 2017/day1 | 1 + 2017/day1.py | 25 + 2017/day4.py | 16 + 2017/day4.sample | 3 + 2020/day1 | 200 ++++ 2020/day1.py | 21 + 2020/day1.sample | 6 + 2021/day1 | 2000 ++++++++++++++++++++++++++++++++++++ 2021/day1.py | 27 + 2021/day13 | 963 +++++++++++++++++ 2021/day13.py | 86 ++ 2021/day13.sample | 21 + 2021/day14 | 102 ++ 2021/day14-2.py | 75 ++ 2021/day14.py | 63 ++ 2021/day2 | 1000 ++++++++++++++++++ 2021/day2.py | 32 + 2021/day2.sample | 6 + 2022/day1 | 2255 ++++++++++++++++++++++++++++++++++++++++ 2022/day1.py | 25 + 2022/day2 | 2500 +++++++++++++++++++++++++++++++++++++++++++++ 2022/day2.py | 88 ++ 2022/day3 | 300 ++++++ 2022/day3.py | 41 + 2022/day4 | 1000 ++++++++++++++++++ 2022/day4.py | 76 ++ 2022/day5 | 512 ++++++++++ 2022/day5.py | 88 ++ 2022/day6 | 1 + 2022/day6.py | 30 + 2022/day7 | 1063 +++++++++++++++++++ 2022/day7.py | 125 +++ 2022/day7.sample | 23 + 2022/day8 | 99 ++ 2022/day8.py | 32 + 2022/day8.sample | 5 + 43 files changed, 13417 insertions(+) create mode 100644 2015/day1 create mode 100755 2015/day1.py create mode 100644 2015/day7 create mode 100755 2015/day7.py create mode 100644 2015/day7.sample create mode 100644 2016/day1 create mode 100755 2016/day1.py create mode 100644 2017/day1 create mode 100755 2017/day1.py create mode 100755 2017/day4.py create mode 100644 2017/day4.sample create mode 100644 2020/day1 create mode 100755 2020/day1.py create mode 100644 2020/day1.sample create mode 100644 2021/day1 create mode 100755 2021/day1.py create mode 100644 2021/day13 create mode 100755 2021/day13.py create mode 100644 2021/day13.sample create mode 100644 2021/day14 create mode 100755 2021/day14-2.py create mode 100755 2021/day14.py create mode 100644 2021/day2 create mode 100755 2021/day2.py create mode 100644 2021/day2.sample create mode 100644 2022/day1 create mode 100755 2022/day1.py create mode 100644 2022/day2 create mode 100755 2022/day2.py create mode 100644 2022/day3 create mode 100755 2022/day3.py create mode 100644 2022/day4 create mode 100755 2022/day4.py create mode 100644 2022/day5 create mode 100755 2022/day5.py create mode 100644 2022/day6 create mode 100755 2022/day6.py create mode 100644 2022/day7 create mode 100755 2022/day7.py create mode 100644 2022/day7.sample create mode 100644 2022/day8 create mode 100755 2022/day8.py create mode 100644 2022/day8.sample diff --git a/2015/day1 b/2015/day1 new file mode 100644 index 0000000..2d4ad8f --- /dev/null +++ b/2015/day1 @@ -0,0 +1 @@ +()(((()))(()()()((((()(((())(()(()((((((()(()(((())))((()(((()))((())(()((()()()()(((())(((((((())))()()(()(()(())(((((()()()((())(((((()()))))()(())(((())(())((((((())())))(()())))()))))()())()())((()()((()()()()(()((((((((()()())((()()(((((()(((())((())(()))()((((()((((((((())()((()())(())((()))())((((()())(((((((((((()()(((((()(()))())(((()(()))())((()(()())())())(()(((())(())())()()(()(()((()))((()))))((((()(((()))))((((()(()(()())())()(((()((((())((((()(((()()(())()()()())((()((((((()((()()))()((()))()(()()((())))(((()(((()))((()((()(()))(((()()(()(()()()))))()()(((()(((())())))))((()(((())()(()(())((()())))((((())))(()(()(()())()((()())))(((()((()(())()()((()((())(()()((())(())()))()))((()(())()))())(((((((()(()()(()(())())))))))(()((((((())((((())((())())(()()))))()(())(()())()())((())(()))))(()))(()((()))()(()((((((()()()()((((((((()(()(())((()()(()()))(())()())()((())))()))()())(((()))(())()(())()))()((()((()(()()())(())()()()((())())))((()()(()()((()(())()()())(((()(()()))))(())))(()(()())()))()()))))))()))))((((((())))())))(()(())())(()())))))(()))()))))))()((()))))()))))(()(()((()())())(()()))))(((())()))())())())(((()(()()))(())()(())(())((((((()()))))((()(()))))))(()))())(((()()(()))()())()()()())))))))))))))(())(()))(()))((()(())(()())(())())(()())(())()()(()())))()()()))(())())()))())())(())((())))))))(())))(())))))()))))((())(()(((()))))(()))()((()(())))(()())(((((()))()())()()))))()))))()))())(()(()()()))()))))))((()))))))))))()((()))((()(())((())()()(()()))()(()))))()()(()))()))(((())))(())()((())(())(()())()())())))))))())))()((())))()))(()))()()))(((((((()))())(()()))(()()(()))()(()((()())()))))))(((()()()())))(())()))()())(()()))()()))))))))(())))()))()()))))))()))()())))()(())(())))))()(())()()(()()))))())((()))))()))))(()(((((()))))))))())))())()(())()()))))(())))())()()())()()())()(()))))()))()))))))))())))((()))()))()))())))()())()()())))())))(()((())()((()))())))))())()(())((())))))))))))())()())(())())())(()))(()))()))())(()(())())()())()()(()))))(()(())))))))(())))())(())))))))())()()(())())())))(())))))()))()(()())()(()))())())))))()()(()))()))))())))))))))()))))()))))))())()())()()))))()())))())))))))))))()()))))()()(((()))()()(())()))))((()))))(()))(())())))(())()))))))(()))()))))(())())))))()))(()())))))))))))))())))))))))()((()())(()())))))))((()))))(())(())))()(()())())))())())(()()()())))()))))))())))))())()()())))))))))))()()(()))))()())()))((()())(()))))()(()))))))))))()())())(((())(()))))())()))()))()))))))()))))))(()))))()))))()(())))(())))(()))())()()(()()))()))(()()))))))))()))(()))())(()()(()(()())()()))()))))))))(())))))((()()(()))())())))))()))())(()())()()))())))()(()()()()))((())())))())()(()()))()))))))))(()))(())))()))))(()(()())(()))))()())())()))()()))())))))))))))())()))))))()))))))))())))))()))))())(()())))(())()))())())))))()()(()()())(()())))()()))(((()))(()()()))))()))))()))))((())))()((((((()()))))))())))))))))))(((()))))))))))))(())())))))())(()))))))(()))((()))())))()(()((()))()))()))))))))))())()))()(()()))))())))())(())()(()))()))())(()))()))))(()()))()()(())))))()))(())(()(()()))(()()())))))(((()))))))()))))))))))))(())(()))))()())())()()((()()))())))))(()))))())))))))()()()))))))))())))()(((()()))(())))))(((())())))))((()))()(()))(()))))(()())))(()))())))))()))))(())(())))()((()))(())())))()()))()))))))))()))(()()()(()()()(()))())(())()())(((()))(())))))))))(((()())))()()))))))))()(())(()))()((((())(())(()())))()))(((())()()()))((()))(()))())())))())))(()))())()())())(()(())())()()()(())))())(())))(())))(())()))()))(()((()))))))))())(()))))))())(()()))()()))()(()(()())))()()(()((()((((((()))(())))()()()))())()))((()()(()))())((()(()(()))(()()))))()())))()))()())))))))()()((()())(())))()))(()))(())(()))())(()(())))()()))))))(((()(((()()))()(()(())())((()()))()))()))()))()(()()()(()))((()())()(())))()()))(((())()()())(())()((()()()()(()(())(()()))()(((((()())))((())))))(()()()))))(((()(())))()))((()((()(())()(()((())))((()())()(()))(((()())()()(()))(())(((()((()())()((())()())(((()()))((()((())(()))(()())(()()()))((()))(())(()((()()())((()))(())))(())(())(())))(()())))(((((()(()(((((()())((((()(()())(())(()()(((())((()(((()()(((()()((((((())))())(()((((((()(()))()))()()((()((()))))()(()()(()((()()))))))(((((()(((((())()()()(())())))))))()))((()()(())))(())(()()()())))))(()((((())))))))()()(((()(()(()(()(()())()()()(((((((((()()())()(()))((()()()()()(((((((()())()((())()))((((((()(()(()(()())(((()(((((((()(((())(((((((((())(())())()))((()(()))(((()()())(())(()(()()(((()(())()))())))(())((((((())(()()())()()(((()(((())(()(((())(((((((()(((((((((()))(())(()(()(()))))((()))()(())())())((()(()((()()))((()()((()(())(())(()((())(((())(((()()()((((((()()(())((((())()))))(())((()(()((())))(((((()(()()())())((())())))((())((()((()()((((((())(((()()(()())())(()(()))(()(()))())())()(((((((()(((()(())()()((())((()(()()((()(()()(((((((((((())((())((((((())((()((((()(()((((()(((((((())()((()))))())()((()((((()(()(((()((()())))(())())(((()(((())((((((()(((((((((()()(())))(()(((((()((((()())))((()((()((()(()()(((())((((((((((((()(((())(()(((((()))(()()(()()()()()()((())(((((((())(((((())))))())()(()()(()(()(((()()(((((())(()((()((()(((()()((()((((())()))()((((())(())))()())(((())(())(()()((()(((()()((((((((((()()(()())())(((((((((())((((()))()()((((())(()((((()(((())())(((((((((((()((((())))(())(()(((()(((()((())(((((()((()()(()(()()((((((()((((()((()(()((()(()((((((()))))()()(((((()((()(()(())()))(())(((((((()((((()())(()((()((()(()))())))(())((()))))(((((((()()()())(()))(()()((()())()((()((()()()(()(()()))(()())(())(((((()(((((((((((()((()(((()(((((((()()((((((()(((((()(()((()(((((())((((((()))((((())((()()((())(((())()(((((()()(((((()((()(()(((((((()(((((()((()((()((())(())((())(()))()()))(()()(()(()()(((((((()(((()(((())()(((((()((((((()())((((())()((()((()(()()())(()))((((()()((((((()((()(()(()((((()((()((())((((((()(()(())((((((()((((((((((()((())()))()(()(()(((((()()()))((())))()(()((((((((((((((()(((()((((()((())((()((()(((()()(()(((()((())(()()())))()(()(()(((((()()(()(()((((()(((((())()(()(()))(((((()()(((()()(())((((((((((((((())((())(((((((((((())()()()(())()(()(()(((((((((())(((()))(()()())(()((((()(())(((((()())(())((((((((())()((((()((((((())(()((()(())(((()((((()))(((((((((()()))((((()(())()()()(())(()((())((()()))()(((())(((((())((((((()()))(((((((((()((((((())))(((((((()((()(()(())))())(()(()))()(((((()())(()))()(()(())(((()))))())()())))(((((()))())()((()(()))))((()()()((((((()))()()((((((((())((()(()(((()(()((())((()())(()((((())(()(((()()()(()(()()))())())((((((((((())())((()))()((())(())(())))())()(()()(())))())(()))(((()(()()(((()(((())))()(((()(())()((((((())()))()))()((((((()(()(((((()())))()))))())()()(((()(((((())((()()(()((()((()(()(()(())))(()()()()((()(())(((()((()))((((()))())(())))())(()))()()()())()))(((()()())()((())))(())(()()()()(()())((()(()()((((())))((()((()(())((()(()((())()(()()(((()())()()())((()))((())(((()()(())))()()))(((()((())()(((((()())(())((())()())())((((((()(()(((((()))(()( diff --git a/2015/day1.py b/2015/day1.py new file mode 100755 index 0000000..0eb5163 --- /dev/null +++ b/2015/day1.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +def main(): + with open('day1', 'r') as file: + lines = file.readlines() + + floor = 0 + position = 0 + for line in lines: + for char in line: + if char == '(': + position += 1 + floor += 1 + elif char == ')': + position += 1 + floor -= 1 + if floor == -1: + print(f'{position = }') + + print(f'{floor = }') + + +if __name__ == '__main__': + main() diff --git a/2015/day7 b/2015/day7 new file mode 100644 index 0000000..0fd2859 --- /dev/null +++ b/2015/day7 @@ -0,0 +1,339 @@ +lf AND lq -> ls +iu RSHIFT 1 -> jn +bo OR bu -> bv +gj RSHIFT 1 -> hc +et RSHIFT 2 -> eu +bv AND bx -> by +is OR it -> iu +b OR n -> o +gf OR ge -> gg +NOT kt -> ku +ea AND eb -> ed +kl OR kr -> ks +hi AND hk -> hl +au AND av -> ax +lf RSHIFT 2 -> lg +dd RSHIFT 3 -> df +eu AND fa -> fc +df AND dg -> di +ip LSHIFT 15 -> it +NOT el -> em +et OR fe -> ff +fj LSHIFT 15 -> fn +t OR s -> u +ly OR lz -> ma +ko AND kq -> kr +NOT fx -> fy +et RSHIFT 1 -> fm +eu OR fa -> fb +dd RSHIFT 2 -> de +NOT go -> gp +kb AND kd -> ke +hg OR hh -> hi +jm LSHIFT 1 -> kg +NOT cn -> co +jp RSHIFT 2 -> jq +jp RSHIFT 5 -> js +1 AND io -> ip +eo LSHIFT 15 -> es +1 AND jj -> jk +g AND i -> j +ci RSHIFT 3 -> ck +gn AND gp -> gq +fs AND fu -> fv +lj AND ll -> lm +jk LSHIFT 15 -> jo +iu RSHIFT 3 -> iw +NOT ii -> ij +1 AND cc -> cd +bn RSHIFT 3 -> bp +NOT gw -> gx +NOT ft -> fu +jn OR jo -> jp +iv OR jb -> jc +hv OR hu -> hw +19138 -> b +gj RSHIFT 5 -> gm +hq AND hs -> ht +dy RSHIFT 1 -> er +ao OR an -> ap +ld OR le -> lf +bk LSHIFT 1 -> ce +bz AND cb -> cc +bi LSHIFT 15 -> bm +il AND in -> io +af AND ah -> ai +as RSHIFT 1 -> bl +lf RSHIFT 3 -> lh +er OR es -> et +NOT ax -> ay +ci RSHIFT 1 -> db +et AND fe -> fg +lg OR lm -> ln +k AND m -> n +hz RSHIFT 2 -> ia +kh LSHIFT 1 -> lb +NOT ey -> ez +NOT di -> dj +dz OR ef -> eg +lx -> a +NOT iz -> ja +gz LSHIFT 15 -> hd +ce OR cd -> cf +fq AND fr -> ft +at AND az -> bb +ha OR gz -> hb +fp AND fv -> fx +NOT gb -> gc +ia AND ig -> ii +gl OR gm -> gn +0 -> c +NOT ca -> cb +bn RSHIFT 1 -> cg +c LSHIFT 1 -> t +iw OR ix -> iy +kg OR kf -> kh +dy OR ej -> ek +km AND kn -> kp +NOT fc -> fd +hz RSHIFT 3 -> ib +NOT dq -> dr +NOT fg -> fh +dy RSHIFT 2 -> dz +kk RSHIFT 2 -> kl +1 AND fi -> fj +NOT hr -> hs +jp RSHIFT 1 -> ki +bl OR bm -> bn +1 AND gy -> gz +gr AND gt -> gu +db OR dc -> dd +de OR dk -> dl +as RSHIFT 5 -> av +lf RSHIFT 5 -> li +hm AND ho -> hp +cg OR ch -> ci +gj AND gu -> gw +ge LSHIFT 15 -> gi +e OR f -> g +fp OR fv -> fw +fb AND fd -> fe +cd LSHIFT 15 -> ch +b RSHIFT 1 -> v +at OR az -> ba +bn RSHIFT 2 -> bo +lh AND li -> lk +dl AND dn -> do +eg AND ei -> ej +ex AND ez -> fa +NOT kp -> kq +NOT lk -> ll +x AND ai -> ak +jp OR ka -> kb +NOT jd -> je +iy AND ja -> jb +jp RSHIFT 3 -> jr +fo OR fz -> ga +df OR dg -> dh +gj RSHIFT 2 -> gk +gj OR gu -> gv +NOT jh -> ji +ap LSHIFT 1 -> bj +NOT ls -> lt +ir LSHIFT 1 -> jl +bn AND by -> ca +lv LSHIFT 15 -> lz +ba AND bc -> bd +cy LSHIFT 15 -> dc +ln AND lp -> lq +x RSHIFT 1 -> aq +gk OR gq -> gr +NOT kx -> ky +jg AND ji -> jj +bn OR by -> bz +fl LSHIFT 1 -> gf +bp OR bq -> br +he OR hp -> hq +et RSHIFT 5 -> ew +iu RSHIFT 2 -> iv +gl AND gm -> go +x OR ai -> aj +hc OR hd -> he +lg AND lm -> lo +lh OR li -> lj +da LSHIFT 1 -> du +fo RSHIFT 2 -> fp +gk AND gq -> gs +bj OR bi -> bk +lf OR lq -> lr +cj AND cp -> cr +hu LSHIFT 15 -> hy +1 AND bh -> bi +fo RSHIFT 3 -> fq +NOT lo -> lp +hw LSHIFT 1 -> iq +dd RSHIFT 1 -> dw +dt LSHIFT 15 -> dx +dy AND ej -> el +an LSHIFT 15 -> ar +aq OR ar -> as +1 AND r -> s +fw AND fy -> fz +NOT im -> in +et RSHIFT 3 -> ev +1 AND ds -> dt +ec AND ee -> ef +NOT ak -> al +jl OR jk -> jm +1 AND en -> eo +lb OR la -> lc +iu AND jf -> jh +iu RSHIFT 5 -> ix +bo AND bu -> bw +cz OR cy -> da +iv AND jb -> jd +iw AND ix -> iz +lf RSHIFT 1 -> ly +iu OR jf -> jg +NOT dm -> dn +lw OR lv -> lx +gg LSHIFT 1 -> ha +lr AND lt -> lu +fm OR fn -> fo +he RSHIFT 3 -> hg +aj AND al -> am +1 AND kz -> la +dy RSHIFT 5 -> eb +jc AND je -> jf +cm AND co -> cp +gv AND gx -> gy +ev OR ew -> ex +jp AND ka -> kc +fk OR fj -> fl +dy RSHIFT 3 -> ea +NOT bs -> bt +NOT ag -> ah +dz AND ef -> eh +cf LSHIFT 1 -> cz +NOT cv -> cw +1 AND cx -> cy +de AND dk -> dm +ck AND cl -> cn +x RSHIFT 5 -> aa +dv LSHIFT 1 -> ep +he RSHIFT 2 -> hf +NOT bw -> bx +ck OR cl -> cm +bp AND bq -> bs +as OR bd -> be +he AND hp -> hr +ev AND ew -> ey +1 AND lu -> lv +kk RSHIFT 3 -> km +b AND n -> p +NOT kc -> kd +lc LSHIFT 1 -> lw +km OR kn -> ko +id AND if -> ig +ih AND ij -> ik +jr AND js -> ju +ci RSHIFT 5 -> cl +hz RSHIFT 1 -> is +1 AND ke -> kf +NOT gs -> gt +aw AND ay -> az +x RSHIFT 2 -> y +ab AND ad -> ae +ff AND fh -> fi +ci AND ct -> cv +eq LSHIFT 1 -> fk +gj RSHIFT 3 -> gl +u LSHIFT 1 -> ao +NOT bb -> bc +NOT hj -> hk +kw AND ky -> kz +as AND bd -> bf +dw OR dx -> dy +br AND bt -> bu +kk AND kv -> kx +ep OR eo -> eq +he RSHIFT 1 -> hx +ki OR kj -> kk +NOT ju -> jv +ek AND em -> en +kk RSHIFT 5 -> kn +NOT eh -> ei +hx OR hy -> hz +ea OR eb -> ec +s LSHIFT 15 -> w +fo RSHIFT 1 -> gh +kk OR kv -> kw +bn RSHIFT 5 -> bq +NOT ed -> ee +1 AND ht -> hu +cu AND cw -> cx +b RSHIFT 5 -> f +kl AND kr -> kt +iq OR ip -> ir +ci RSHIFT 2 -> cj +cj OR cp -> cq +o AND q -> r +dd RSHIFT 5 -> dg +b RSHIFT 2 -> d +ks AND ku -> kv +b RSHIFT 3 -> e +d OR j -> k +NOT p -> q +NOT cr -> cs +du OR dt -> dv +kf LSHIFT 15 -> kj +NOT ac -> ad +fo RSHIFT 5 -> fr +hz OR ik -> il +jx AND jz -> ka +gh OR gi -> gj +kk RSHIFT 1 -> ld +hz RSHIFT 5 -> ic +as RSHIFT 2 -> at +NOT jy -> jz +1 AND am -> an +ci OR ct -> cu +hg AND hh -> hj +jq OR jw -> jx +v OR w -> x +la LSHIFT 15 -> le +dh AND dj -> dk +dp AND dr -> ds +jq AND jw -> jy +au OR av -> aw +NOT bf -> bg +z OR aa -> ab +ga AND gc -> gd +hz AND ik -> im +jt AND jv -> jw +z AND aa -> ac +jr OR js -> jt +hb LSHIFT 1 -> hv +hf OR hl -> hm +ib OR ic -> id +fq OR fr -> fs +cq AND cs -> ct +ia OR ig -> ih +dd OR do -> dp +d AND j -> l +ib AND ic -> ie +as RSHIFT 3 -> au +be AND bg -> bh +dd AND do -> dq +NOT l -> m +1 AND gd -> ge +y AND ae -> ag +fo AND fz -> gb +NOT ie -> if +e AND f -> h +x RSHIFT 3 -> z +y OR ae -> af +hf AND hl -> hn +NOT h -> i +NOT hn -> ho +he RSHIFT 5 -> hh diff --git a/2015/day7.py b/2015/day7.py new file mode 100755 index 0000000..e38c406 --- /dev/null +++ b/2015/day7.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +def parse_line(line, identifiers): + elements = line.split() + length = len(elements) + match length: + case 3: # Assignment + return int(elements[0]), elements[2].strip() + case 4: # NOT + return ~identifiers[elements[1]], elements[3].strip() + case 5: # AND OR LSHIFT RSHIFT + match elements[1]: + case 'AND': + return identifiers[elements[0]] & identifiers[elements[2]], elements[4].strip() + case 'OR': + return identifiers[elements[0]] | identifiers[elements[2]], elements[4].strip() + case 'LSHIFT': + return identifiers[elements[0]] << int(elements[2]), elements[4].strip() + case 'RSHIFT': + return identifiers[elements[0]] >> int(elements[2]), elements[4].strip() + + +def main(): + with open('day7.sample', 'r') as file: + lines = file.readlines() + + identifiers = {} + for line in lines: + value, identifier = parse_line(line, identifiers) + identifiers[identifier] = value + + print(identifiers) + + +if __name__ == '__main__': + main() diff --git a/2015/day7.sample b/2015/day7.sample new file mode 100644 index 0000000..27b4f8d --- /dev/null +++ b/2015/day7.sample @@ -0,0 +1,8 @@ +123 -> x +456 -> y +x AND y -> d +x OR y -> e +x LSHIFT 2 -> f +y RSHIFT 2 -> g +NOT x -> h +NOT y -> i diff --git a/2016/day1 b/2016/day1 new file mode 100644 index 0000000..ec11913 --- /dev/null +++ b/2016/day1 @@ -0,0 +1 @@ +R1, L4, L5, L5, R2, R2, L1, L1, R2, L3, R4, R3, R2, L4, L2, R5, L1, R5, L5, L2, L3, L1, R1, R4, R5, L3, R2, L4, L5, R1, R2, L3, R3, L3, L1, L2, R5, R4, R5, L5, R1, L190, L3, L3, R3, R4, R47, L3, R5, R79, R5, R3, R1, L4, L3, L2, R194, L2, R1, L2, L2, R4, L5, L5, R1, R1, L1, L3, L2, R5, L3, L3, R4, R1, R5, L4, R3, R1, L1, L2, R4, R1, L2, R4, R4, L5, R3, L5, L3, R1, R1, L3, L1, L1, L3, L4, L1, L2, R1, L5, L3, R2, L5, L3, R5, R3, L4, L2, R2, R4, R4, L4, R5, L1, L3, R3, R4, R4, L5, R4, R2, L3, R4, R2, R1, R2, L4, L2, R2, L5, L5, L3, R5, L5, L1, R4, L1, R1, L1, R4, L5, L3, R4, R1, L3, R4, R1, L3, L1, R1, R2, L4, L2, R1, L5, L4, L5 diff --git a/2016/day1.py b/2016/day1.py new file mode 100755 index 0000000..b0ab57d --- /dev/null +++ b/2016/day1.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python3 + +def turn(direction, facing): + match facing: + case 'North': + if direction == 'R': + facing = 'East' + else: + facing = 'West' + case 'East': + if direction == 'R': + facing = 'South' + else: + facing = 'North' + case 'South': + if direction == 'R': + facing = 'West' + else: + facing = 'East' + case 'West': + if direction == 'R': + facing = 'North' + else: + facing = 'South' + return facing + + +def check_locations(blocks, facing, x_coord, y_coord, locations): + x_coord, y_coord = locations[-1] + match facing: + case 'North': + for block in range(1, blocks + 1): + if [x_coord + block, y_coord] in locations: + return [x_coord + block, y_coord] + locations.append([x_coord + block, y_coord]) + case 'East': + for block in range(1, blocks + 1): + if [x_coord, y_coord + block] in locations: + return [x_coord, y_coord + block] + locations.append([x_coord, y_coord + block]) + case 'South': + for block in range(1, blocks + 1): + if [x_coord - block, y_coord] in locations: + return [x_coord - block, y_coord] + locations.append([x_coord - block, y_coord]) + case 'West': + for block in range(1, blocks + 1): + if [x_coord, y_coord - block] in locations: + return [x_coord, y_coord - block] + locations.append([x_coord, y_coord - block]) + + +def walk(blocks, facing, x_coord, y_coord): + match facing: + case 'North': + x_coord += blocks + case 'East': + y_coord += blocks + case 'South': + x_coord -= blocks + case 'West': + y_coord -= blocks + return x_coord, y_coord + + +def main(): + x_coord = 0 + y_coord = 0 + facing = 'North' + + with open('day1', 'r') as file: + line = file.readlines()[0][:-1] + + sequences = line.split(', ') + + locations = [[0,0]] + hq_loc = [] + + for sequence in sequences: + direction = sequence[0] + blocks = int(sequence[1:]) + facing = turn(direction, facing) + x_coord, y_coord = walk(blocks , facing, x_coord, y_coord) + + for sequence in sequences: + direction = sequence[0] + blocks = int(sequence[1:]) + facing = turn(direction, facing) + hq_loc = check_locations(blocks, facing, x_coord, y_coord, locations) + if hq_loc: + break + + print(abs(x_coord) + abs(y_coord)) + print(abs(hq_loc[0]) + abs(hq_loc[1])) + + +if __name__ == '__main__': + main() diff --git a/2017/day1 b/2017/day1 new file mode 100644 index 0000000..2b1f776 --- /dev/null +++ b/2017/day1 @@ -0,0 +1 @@ +181445682966897848665963472661939865313976877194312684993521259486517527961396717561854825453963181134379574918373213732184697746668399631642622373684425326112585283946462323363991753895647177797691214784149215198715986947573668987188746878678399624533792551651335979847131975965677957755571358934665327487287312467771187981424785514785421781781976477326712674311994735947987383516699897916595433228294198759715959469578766739518475118771755787196238772345762941477359483456641194685333528329581113788599843621326313592354167846466415943566183192946217689936174884493199368681514958669615226362538622898367728662941275658917124167353496334664239539753835439929664552886538885727235662548783529353611441231681613535447417941911479391558481443933134283852879511395429489152435996669232681215627723723565872291296878528334773391626672491878762288953597499218397146685679387438634857358552943964839321464529237533868734473777756775687759355878519113426969197211824325893376812556798483325994128743242544899625215765851923959798197562831313891371735973761384464685316273343541852758525318144681364492173465174512856618292785483181956548813344752352933634979165667651165776587656468598791994573513652324764687515345959621493346623821965554755615219855842969932269414839446887613738174567989512857785566352285988991946436148652839391593178736624957214917527759574235133666461988355855613377789115472297915429318142824465141688559333787512328799783539285826471818279818457674417354335454395644435889386297695625378256613558911695145397779576526397241795181294322797687168326696497256684943829666672341162656479563522892141714998477865114944671225898297338685958644728534192317628618817551492975251364233974374724968483637518876583946828819994321129556511537619253381981544394112184655586964655164192552352534626295996968762388827294873362719636616182786976922445125551927969267591395292198155775434997827738862786341543524544822321112131815475829945625787561369956264826651461575948462782869972654343749617939132353399334744265286151177931594514857563664329299713436914721119746932159456287267887878779218815883191236858656959258484139254446341 diff --git a/2017/day1.py b/2017/day1.py new file mode 100755 index 0000000..dcbea8c --- /dev/null +++ b/2017/day1.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +def main(): + with open('day1', 'r') as file: + lines = file.readlines() + + line = lines[0] + total = 0 + first = False + for index, num in enumerate(line): + try: + if line[index] == line[index + 1]: + if first: + total += int(num) + else: + total += int(line[index]) + int(line[index + 1]) + first = True + except IndexError: + if line[index] == line[0]: + total += int(num) + + print(total) + +if __name__ == '__main__': + main() diff --git a/2017/day4.py b/2017/day4.py new file mode 100755 index 0000000..8d9a9c3 --- /dev/null +++ b/2017/day4.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 + + +lis = [] +for line in open("day4.sample"): + print(line) + for word in line.split(): + lis.append(word) + + + +print([word for line in open("day4.sample") for word in line.split()]) + + + +print(lis, type(lis)) diff --git a/2017/day4.sample b/2017/day4.sample new file mode 100644 index 0000000..c86b599 --- /dev/null +++ b/2017/day4.sample @@ -0,0 +1,3 @@ +sayndz zfxlkl attjtww cti sokkmty brx fhh suelqbp +xmuf znkhaes pggrlp zia znkhaes znkhaes +nti rxr bogebb zdwrin diff --git a/2020/day1 b/2020/day1 new file mode 100644 index 0000000..c706670 --- /dev/null +++ b/2020/day1 @@ -0,0 +1,200 @@ +1844 +1123 +1490 +1478 +1108 +1120 +1594 +1101 +1831 +1146 +1084 +1535 +1016 +1722 +1388 +1188 +1351 +1477 +1215 +1678 +1159 +1558 +1581 +1400 +1550 +1306 +1852 +1745 +1224 +1896 +1596 +1005 +1499 +1797 +976 +1777 +1129 +1601 +1058 +1510 +1704 +1818 +1795 +1364 +1276 +1362 +1801 +1985 +1421 +1311 +1855 +1977 +1613 +1951 +2001 +1327 +1872 +1517 +1040 +1692 +1595 +1769 +1956 +1763 +1470 +1898 +1366 +1443 +312 +1685 +1014 +1409 +1717 +1105 +1290 +1703 +1732 +1939 +1790 +1164 +1225 +1474 +1713 +1413 +1906 +1488 +1931 +1702 +1848 +1668 +1737 +1614 +1719 +1647 +1171 +1508 +1035 +1133 +1179 +1180 +1472 +1414 +1659 +1820 +1544 +1697 +1175 +1033 +1805 +1576 +1196 +1597 +1739 +1291 +1103 +1457 +1514 +1462 +1619 +1683 +1338 +1604 +1372 +1653 +16 +1725 +1181 +1952 +1201 +1531 +1505 +1912 +1527 +1853 +1905 +1833 +1913 +1131 +1069 +1537 +1754 +1551 +1435 +1914 +1093 +1273 +1726 +1094 +1439 +1689 +1607 +1646 +1588 +1698 +1539 +1493 +1352 +1163 +1482 +1044 +1523 +1142 +1253 +1250 +1986 +1049 +1330 +1219 +1162 +1088 +1100 +1532 +1727 +1761 +1107 +1916 +1220 +1319 +1098 +1431 +1260 +1642 +1269 +1102 +1432 +1267 +1824 +1658 +1149 +1024 +1963 +1498 +1904 +1812 +1600 +1773 +1283 +1463 +1776 +1406 diff --git a/2020/day1.py b/2020/day1.py new file mode 100755 index 0000000..128d125 --- /dev/null +++ b/2020/day1.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +def main(): + with open('day1', 'r') as file: + lines = file.readlines() + + numbers = [] + for line in lines: + first = int(line.strip()) + for sec in lines: + second = int(sec) + if (first + second) == 2020: + print(first,second, first * second) + for thi in lines: + third = int(thi) + if (first + second + third) == 2020: + print(first, second, third, first * second * third) + + +if __name__ == '__main__': + main() diff --git a/2020/day1.sample b/2020/day1.sample new file mode 100644 index 0000000..e3fb011 --- /dev/null +++ b/2020/day1.sample @@ -0,0 +1,6 @@ +1721 +979 +366 +299 +675 +1456 diff --git a/2021/day1 b/2021/day1 new file mode 100644 index 0000000..bc99d0b --- /dev/null +++ b/2021/day1 @@ -0,0 +1,2000 @@ +199 +227 +229 +230 +233 +228 +231 +226 +237 +259 +262 +265 +266 +265 +269 +276 +278 +279 +281 +287 +305 +316 +314 +320 +313 +314 +315 +329 +346 +357 +370 +369 +360 +384 +383 +401 +402 +403 +404 +403 +406 +408 +406 +401 +393 +395 +416 +418 +408 +411 +412 +416 +417 +404 +421 +436 +437 +436 +420 +388 +405 +403 +371 +376 +378 +374 +378 +377 +403 +411 +444 +424 +417 +416 +419 +436 +415 +413 +429 +446 +462 +463 +464 +467 +466 +475 +483 +478 +487 +488 +469 +470 +472 +473 +460 +463 +465 +477 +487 +508 +506 +509 +512 +513 +519 +525 +531 +498 +506 +504 +506 +507 +509 +510 +512 +537 +553 +536 +533 +524 +525 +526 +527 +530 +531 +533 +537 +538 +537 +539 +544 +552 +550 +576 +560 +556 +561 +552 +560 +572 +573 +572 +571 +573 +578 +581 +582 +578 +541 +546 +537 +545 +556 +565 +566 +571 +561 +573 +579 +578 +581 +600 +603 +604 +597 +598 +599 +598 +599 +580 +585 +586 +596 +597 +602 +593 +598 +599 +604 +608 +609 +616 +615 +613 +622 +625 +620 +632 +636 +628 +633 +640 +621 +620 +638 +646 +647 +648 +647 +654 +655 +663 +652 +664 +668 +669 +668 +663 +667 +659 +658 +666 +670 +685 +703 +706 +705 +706 +727 +730 +729 +735 +743 +749 +750 +751 +756 +774 +776 +767 +778 +777 +790 +791 +794 +798 +801 +804 +812 +818 +819 +818 +821 +825 +818 +829 +832 +835 +849 +848 +863 +859 +863 +871 +870 +869 +873 +875 +878 +874 +896 +903 +890 +891 +905 +912 +913 +911 +917 +941 +943 +944 +940 +943 +945 +947 +948 +953 +930 +932 +933 +948 +936 +937 +941 +947 +952 +957 +951 +953 +954 +958 +979 +982 +971 +974 +979 +984 +988 +989 +986 +987 +992 +998 +1013 +1024 +1022 +1023 +1014 +1019 +1042 +1048 +1047 +1060 +1056 +1067 +1054 +1053 +1061 +1063 +1068 +1074 +1104 +1105 +1107 +1119 +1126 +1127 +1129 +1143 +1145 +1146 +1151 +1159 +1183 +1185 +1192 +1183 +1185 +1182 +1180 +1198 +1215 +1221 +1224 +1227 +1230 +1262 +1289 +1291 +1294 +1297 +1300 +1303 +1321 +1323 +1329 +1331 +1341 +1362 +1369 +1370 +1388 +1389 +1393 +1407 +1386 +1380 +1381 +1378 +1398 +1402 +1399 +1422 +1433 +1449 +1451 +1449 +1462 +1454 +1455 +1452 +1471 +1472 +1487 +1477 +1459 +1463 +1461 +1463 +1473 +1489 +1482 +1516 +1527 +1521 +1522 +1527 +1529 +1531 +1538 +1550 +1553 +1548 +1549 +1545 +1548 +1543 +1546 +1549 +1572 +1576 +1581 +1575 +1584 +1602 +1604 +1605 +1606 +1611 +1610 +1623 +1618 +1614 +1622 +1613 +1608 +1611 +1638 +1632 +1643 +1649 +1652 +1655 +1652 +1653 +1654 +1658 +1659 +1661 +1667 +1695 +1710 +1719 +1726 +1727 +1725 +1726 +1736 +1741 +1763 +1752 +1769 +1770 +1767 +1768 +1769 +1771 +1799 +1798 +1810 +1813 +1816 +1826 +1837 +1842 +1841 +1848 +1853 +1823 +1836 +1835 +1837 +1836 +1839 +1838 +1840 +1841 +1839 +1843 +1844 +1862 +1873 +1877 +1880 +1882 +1881 +1895 +1891 +1896 +1899 +1893 +1894 +1892 +1894 +1895 +1921 +1920 +1922 +1928 +1925 +1933 +1943 +1942 +1936 +1941 +1919 +1912 +1914 +1922 +1918 +1934 +1932 +1946 +1949 +1955 +1964 +1974 +1977 +1978 +1983 +1984 +1986 +1990 +2005 +2022 +2026 +2032 +2031 +2029 +2031 +2035 +2041 +2042 +2043 +2053 +2054 +2058 +2062 +2063 +2055 +2049 +2021 +2022 +2054 +2052 +2084 +2076 +2079 +2090 +2088 +2093 +2095 +2093 +2091 +2089 +2095 +2096 +2102 +2127 +2129 +2132 +2117 +2125 +2131 +2132 +2126 +2134 +2140 +2137 +2138 +2136 +2137 +2141 +2153 +2152 +2170 +2177 +2147 +2159 +2161 +2160 +2173 +2176 +2194 +2205 +2206 +2213 +2231 +2232 +2242 +2243 +2217 +2224 +2225 +2230 +2226 +2214 +2212 +2227 +2230 +2237 +2238 +2241 +2264 +2283 +2288 +2308 +2309 +2311 +2312 +2314 +2316 +2317 +2318 +2321 +2326 +2324 +2325 +2321 +2324 +2322 +2325 +2327 +2335 +2369 +2370 +2374 +2375 +2344 +2347 +2348 +2341 +2346 +2355 +2356 +2371 +2368 +2370 +2375 +2378 +2379 +2370 +2363 +2365 +2366 +2363 +2364 +2372 +2374 +2392 +2399 +2397 +2384 +2400 +2401 +2402 +2401 +2400 +2402 +2412 +2422 +2423 +2426 +2424 +2425 +2421 +2422 +2440 +2441 +2451 +2442 +2443 +2444 +2446 +2451 +2452 +2450 +2458 +2457 +2490 +2496 +2506 +2507 +2508 +2511 +2531 +2536 +2537 +2539 +2529 +2530 +2561 +2562 +2592 +2595 +2584 +2601 +2603 +2589 +2586 +2588 +2586 +2596 +2613 +2616 +2618 +2621 +2629 +2637 +2638 +2619 +2621 +2619 +2631 +2621 +2619 +2624 +2628 +2634 +2636 +2637 +2626 +2632 +2623 +2630 +2629 +2630 +2633 +2620 +2629 +2635 +2614 +2617 +2612 +2613 +2609 +2601 +2604 +2611 +2602 +2607 +2611 +2639 +2646 +2647 +2618 +2613 +2614 +2635 +2642 +2649 +2653 +2652 +2628 +2629 +2631 +2636 +2639 +2649 +2665 +2667 +2666 +2665 +2668 +2672 +2673 +2675 +2693 +2694 +2696 +2701 +2702 +2703 +2700 +2716 +2718 +2719 +2718 +2719 +2722 +2723 +2715 +2726 +2737 +2757 +2758 +2759 +2762 +2760 +2765 +2759 +2763 +2764 +2774 +2785 +2786 +2802 +2803 +2802 +2824 +2833 +2834 +2830 +2832 +2842 +2828 +2829 +2836 +2838 +2813 +2811 +2798 +2799 +2796 +2805 +2808 +2807 +2811 +2812 +2811 +2812 +2793 +2787 +2802 +2805 +2804 +2822 +2825 +2837 +2835 +2842 +2838 +2849 +2840 +2841 +2853 +2854 +2863 +2877 +2886 +2864 +2866 +2846 +2860 +2840 +2842 +2844 +2866 +2867 +2870 +2856 +2860 +2861 +2860 +2872 +2877 +2881 +2883 +2881 +2883 +2880 +2881 +2882 +2880 +2902 +2903 +2904 +2937 +2939 +2938 +2945 +2954 +2950 +2966 +2967 +2976 +2980 +2982 +2976 +2986 +2997 +2996 +2994 +3004 +3007 +3008 +3016 +3014 +3054 +3078 +3095 +3114 +3115 +3120 +3107 +3109 +3124 +3140 +3144 +3150 +3163 +3165 +3164 +3158 +3172 +3175 +3174 +3184 +3188 +3198 +3193 +3224 +3226 +3227 +3252 +3273 +3280 +3289 +3291 +3290 +3291 +3279 +3281 +3282 +3281 +3298 +3302 +3289 +3304 +3295 +3312 +3314 +3327 +3328 +3337 +3348 +3349 +3340 +3348 +3351 +3350 +3351 +3350 +3345 +3339 +3343 +3344 +3329 +3354 +3356 +3358 +3363 +3365 +3373 +3376 +3383 +3384 +3388 +3389 +3390 +3397 +3398 +3401 +3409 +3411 +3412 +3411 +3418 +3428 +3430 +3432 +3418 +3410 +3418 +3424 +3425 +3426 +3430 +3439 +3441 +3422 +3423 +3425 +3426 +3428 +3429 +3436 +3448 +3447 +3443 +3445 +3468 +3482 +3483 +3499 +3506 +3513 +3518 +3523 +3524 +3525 +3529 +3532 +3529 +3565 +3577 +3576 +3577 +3576 +3539 +3557 +3554 +3563 +3562 +3564 +3565 +3586 +3583 +3590 +3589 +3580 +3581 +3574 +3599 +3597 +3609 +3610 +3611 +3614 +3613 +3611 +3612 +3611 +3598 +3596 +3597 +3585 +3568 +3569 +3550 +3561 +3563 +3551 +3552 +3555 +3553 +3554 +3553 +3552 +3555 +3557 +3560 +3585 +3591 +3604 +3609 +3640 +3641 +3645 +3644 +3643 +3646 +3644 +3664 +3653 +3660 +3667 +3664 +3665 +3668 +3670 +3649 +3640 +3639 +3647 +3654 +3650 +3648 +3654 +3651 +3652 +3653 +3654 +3655 +3671 +3660 +3671 +3675 +3679 +3680 +3681 +3686 +3690 +3691 +3693 +3695 +3698 +3697 +3699 +3708 +3712 +3714 +3712 +3711 +3716 +3731 +3732 +3736 +3753 +3755 +3756 +3767 +3747 +3746 +3733 +3711 +3722 +3718 +3721 +3722 +3723 +3724 +3727 +3731 +3732 +3741 +3743 +3750 +3751 +3738 +3741 +3739 +3740 +3756 +3755 +3751 +3750 +3755 +3757 +3773 +3778 +3781 +3782 +3768 +3772 +3766 +3770 +3778 +3792 +3798 +3801 +3803 +3801 +3812 +3833 +3873 +3868 +3865 +3866 +3906 +3910 +3897 +3907 +3910 +3898 +3914 +3917 +3908 +3912 +3920 +3934 +3930 +3934 +3935 +3937 +3942 +3943 +3948 +3964 +3978 +3985 +3986 +3993 +3995 +4014 +4021 +4024 +4025 +4024 +4027 +4028 +4043 +4047 +4049 +4036 +4039 +4038 +4037 +4045 +4040 +4041 +4043 +4035 +4046 +4063 +4054 +4055 +4064 +4067 +4060 +4061 +4062 +4069 +4070 +4063 +4064 +4077 +4065 +4074 +4076 +4078 +4091 +4100 +4104 +4105 +4106 +4107 +4115 +4110 +4112 +4113 +4114 +4115 +4092 +4093 +4107 +4109 +4108 +4112 +4143 +4144 +4145 +4146 +4145 +4144 +4126 +4130 +4134 +4149 +4151 +4161 +4162 +4160 +4146 +4170 +4188 +4196 +4194 +4193 +4196 +4197 +4198 +4200 +4205 +4218 +4228 +4216 +4224 +4226 +4241 +4245 +4247 +4251 +4245 +4244 +4266 +4259 +4262 +4269 +4270 +4275 +4281 +4298 +4305 +4309 +4311 +4325 +4328 +4346 +4347 +4357 +4360 +4359 +4357 +4391 +4396 +4391 +4397 +4395 +4405 +4410 +4412 +4433 +4420 +4421 +4422 +4423 +4431 +4437 +4447 +4451 +4458 +4457 +4458 +4456 +4455 +4458 +4460 +4431 +4432 +4431 +4441 +4444 +4436 +4408 +4406 +4414 +4415 +4413 +4422 +4449 +4430 +4428 +4397 +4395 +4396 +4398 +4396 +4399 +4406 +4413 +4422 +4421 +4429 +4431 +4430 +4462 +4460 +4480 +4482 +4486 +4484 +4483 +4497 +4493 +4496 +4506 +4504 +4497 +4498 +4503 +4513 +4525 +4533 +4547 +4560 +4561 +4563 +4562 +4572 +4571 +4575 +4557 +4561 +4562 +4550 +4552 +4543 +4537 +4534 +4542 +4561 +4563 +4562 +4583 +4582 +4591 +4592 +4597 +4601 +4599 +4600 +4610 +4601 +4612 +4630 +4616 +4619 +4623 +4624 +4636 +4638 +4645 +4651 +4655 +4660 +4659 +4658 +4657 +4658 +4661 +4670 +4665 +4656 +4664 +4666 +4667 +4669 +4696 +4701 +4712 +4711 +4719 +4679 +4680 +4686 +4684 +4685 +4689 +4682 +4686 +4688 +4687 +4688 +4687 +4693 +4672 +4670 +4667 +4673 +4643 +4644 +4653 +4668 +4669 +4672 +4685 +4663 +4665 +4672 +4696 +4698 +4701 +4699 +4687 +4690 +4687 +4684 +4685 +4687 +4689 +4685 +4692 +4690 +4696 +4702 +4703 +4704 +4717 +4718 +4719 +4711 +4717 +4719 +4726 +4722 +4736 +4735 +4739 +4748 +4741 +4738 +4736 +4737 +4736 +4740 +4748 +4749 +4757 +4760 +4768 +4754 +4756 +4772 +4773 +4775 +4770 +4766 +4769 +4762 +4771 +4773 +4775 +4776 +4778 +4782 +4770 +4763 +4765 +4764 +4765 +4764 +4777 +4780 +4786 +4797 +4803 +4812 +4811 +4818 +4823 +4820 +4821 +4831 +4834 +4862 +4865 +4856 +4857 +4863 +4860 +4861 +4858 +4846 +4848 +4852 +4853 +4854 +4856 +4832 +4833 +4832 +4830 +4826 +4833 +4851 +4852 +4855 +4856 +4857 +4852 +4854 +4860 +4863 +4887 +4878 +4879 +4880 +4893 +4888 +4891 +4892 +4896 +4897 +4900 +4905 +4903 +4909 +4927 +4942 +4946 +4952 +4970 +4971 +4987 +4990 +4991 +4990 +4989 +4988 +4989 +4995 +4996 +5004 +5003 +5005 +5009 +4997 +4981 +4977 +4979 +4982 +4984 +4994 +5005 +5009 +5008 +5036 +5034 +5033 +5030 +5032 +5034 +5030 +5031 +5034 +5070 +5072 +5071 +5073 +5077 +5078 +5070 +5084 +5085 +5091 +5071 +5080 +5075 +5070 +5067 +5072 +5075 +5082 +5085 +5091 +5104 +5120 +5123 +5122 +5105 +5120 +5128 +5116 +5118 +5122 +5120 +5140 +5142 +5145 +5148 +5152 +5153 +5154 +5157 +5172 +5179 +5177 +5185 +5191 +5200 +5201 +5207 +5205 +5206 +5198 +5205 +5186 +5188 +5197 +5194 +5203 +5204 +5205 +5208 +5214 +5220 +5219 +5224 +5227 +5241 +5233 +5253 +5283 +5287 +5291 +5289 +5296 +5297 +5294 +5288 +5289 +5290 +5278 +5290 +5288 +5294 +5295 +5294 +5292 +5289 +5299 +5283 +5285 +5290 +5289 +5291 +5302 +5304 +5305 +5315 +5316 +5323 +5337 +5341 +5345 +5346 +5358 +5361 +5367 +5348 +5354 +5344 +5339 +5342 +5341 +5354 +5356 +5355 +5354 +5355 +5356 +5342 +5348 +5350 +5351 +5355 +5378 +5380 +5404 +5405 +5407 +5417 +5419 +5411 +5412 +5413 +5416 +5420 +5391 +5377 +5386 +5387 +5390 +5383 +5385 +5384 +5390 +5389 +5390 +5409 +5414 +5424 +5427 +5428 +5430 +5443 +5435 +5430 +5427 +5428 +5422 +5452 +5460 +5464 +5465 +5472 +5473 +5481 +5480 +5481 +5482 +5483 +5493 +5495 +5492 +5501 +5517 +5519 +5527 +5532 +5529 +5532 +5542 +5532 +5550 +5551 +5560 +5543 +5549 +5555 +5554 +5555 +5552 +5562 +5563 +5564 +5566 +5568 +5571 +5549 +5556 +5557 +5563 +5564 +5567 +5563 +5570 +5559 +5580 +5585 +5568 +5569 +5562 +5578 +5579 +5565 +5567 +5583 +5584 +5592 +5590 +5593 +5595 +5594 +5597 +5582 +5588 +5594 +5596 +5598 +5597 +5595 +5605 +5593 +5590 +5599 +5603 +5597 +5632 +5621 +5624 +5628 +5634 +5662 +5663 +5666 +5674 +5678 +5677 +5678 +5679 +5680 +5681 +5687 +5690 +5685 +5684 +5683 +5689 +5690 +5691 +5689 +5694 +5698 +5701 +5698 +5733 +5757 +5767 +5794 +5812 +5804 +5802 +5810 +5826 +5856 +5855 +5860 +5861 +5846 +5865 +5885 +5874 +5883 +5888 +5892 +5894 +5877 +5840 +5841 +5814 +5815 +5818 +5821 +5822 +5819 +5818 +5842 +5849 +5850 +5851 +5854 +5856 +5854 +5851 +5864 +5866 +5867 +5871 +5874 +5879 +5888 +5886 +5890 +5894 +5889 +5875 +5863 +5847 +5857 +5853 +5858 +5859 +5862 +5867 +5862 +5866 +5874 +5875 +5894 +5897 +5877 +5886 +5887 +5891 +5881 +5886 +5885 +5886 +5887 +5888 +5892 +5891 +5903 +5902 +5901 +5902 +5903 +5908 +5905 +5912 +5914 +5920 +5927 +5916 +5917 +5918 +5921 +5931 +5939 +5942 +5943 +5949 +5962 +5990 +5985 +5982 +5980 +5979 +5990 +5995 +6012 +6029 +6038 +6050 +6051 +6057 +6052 +6061 +6060 +6050 +6058 +6059 +6060 +6064 +6065 +6092 +6091 +6090 +6089 +6085 +6101 +6107 +6110 +6109 +6120 +6117 +6110 diff --git a/2021/day1.py b/2021/day1.py new file mode 100755 index 0000000..5c2a9e2 --- /dev/null +++ b/2021/day1.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +def main(): + with open('day1', 'r') as file: + lines = file.readlines() + + prev = lines[0] + count = 0 + for line in lines[1:]: + if int(prev) < int(line.strip()): + count += 1 + prev = line + + print(count) + + prev = int(lines[0]) + int(lines[1]) + int(lines[2]) + count = 0 + for index in range(len(lines) - 3): + if prev < int(lines[index+1]) + int(lines[index+2]) + int(lines[index+3]): + count += 1 + prev = int(lines[index+1]) + int(lines[index+2]) + int(lines[index+3]) + + print(count) + + +if __name__ == '__main__': + main() diff --git a/2021/day13 b/2021/day13 new file mode 100644 index 0000000..f9e121c --- /dev/null +++ b/2021/day13 @@ -0,0 +1,963 @@ +1026,284 +612,2 +355,653 +711,884 +1205,14 +971,348 +550,313 +1261,236 +1155,838 +33,487 +1287,690 +1230,722 +1230,110 +73,854 +1178,81 +216,719 +875,794 +900,334 +1277,61 +783,240 +1099,159 +303,528 +624,327 +108,322 +698,444 +990,397 +1131,856 +527,273 +1195,831 +1029,49 +1220,688 +177,724 +671,478 +1016,807 +385,141 +944,140 +1084,525 +984,893 +1265,243 +793,543 +334,581 +780,128 +326,669 +826,845 +609,38 +299,126 +828,758 +607,212 +818,313 +296,343 +127,421 +612,486 +571,294 +811,838 +192,45 +991,516 +80,546 +554,547 +592,33 +311,192 +1237,488 +1205,880 +1131,605 +542,410 +344,674 +284,284 +326,569 +976,581 +1292,795 +70,494 +847,320 +62,275 +842,705 +393,792 +678,294 +313,1 +559,775 +11,457 +646,544 +144,67 +559,878 +1066,782 +492,549 +45,682 +1128,84 +746,323 +291,585 +713,786 +774,86 +597,114 +1005,75 +488,446 +94,527 +269,589 +423,617 +258,591 +395,23 +1205,238 +340,420 +27,261 +587,792 +170,173 +972,254 +875,396 +1131,528 +850,2 +892,94 +490,873 +1081,628 +1041,254 +925,219 +1245,435 +969,109 +984,673 +627,411 +689,855 +711,487 +1294,668 +209,18 +981,2 +885,360 +1101,204 +499,201 +870,193 +435,794 +107,212 +1210,99 +639,864 +445,18 +564,766 +127,660 +1295,724 +62,705 +15,170 +595,775 +428,11 +189,325 +831,73 +380,735 +803,394 +898,100 +1243,344 +1099,253 +970,868 +865,38 +1227,854 +0,542 +490,318 +831,821 +373,428 +1193,652 +1074,542 +483,133 +1297,221 +1108,729 +726,848 +705,684 +202,506 +397,793 +536,86 +684,401 +1014,674 +1206,313 +1216,255 +134,849 +189,95 +706,661 +662,257 +396,863 +616,165 +1017,285 +917,254 +475,500 +377,658 +231,103 +261,550 +1014,253 +892,653 +1265,341 +492,245 +1261,96 +785,722 +1170,362 +933,210 +268,112 +961,75 +1260,233 +1253,667 +848,849 +1299,546 +1036,159 +1011,126 +385,723 +30,327 +47,682 +1309,208 +522,793 +406,570 +592,189 +499,873 +1216,415 +236,542 +1183,869 +586,59 +564,284 +130,807 +490,128 +870,253 +666,780 +1014,641 +1133,170 +1268,296 +805,394 +423,197 +62,640 +554,291 +162,128 +97,136 +1041,589 +644,478 +739,600 +202,729 +937,362 +1260,141 +900,784 +874,546 +766,719 +974,463 +140,362 +351,338 +1033,236 +915,863 +97,696 +386,784 +62,702 +370,200 +277,236 +800,84 +1019,585 +1213,422 +999,590 +564,653 +274,719 +179,366 +791,768 +1213,24 +728,795 +276,213 +1248,204 +279,178 +887,276 +609,856 +383,39 +522,81 +1230,784 +933,236 +783,660 +1190,162 +1111,137 +524,807 +343,438 +274,607 +960,420 +1277,385 +1303,154 +52,771 +776,21 +1084,291 +795,752 +358,551 +502,338 +564,654 +197,498 +694,165 +1298,619 +726,324 +229,360 +604,661 +175,681 +45,385 +1265,354 +1299,180 +1155,693 +38,378 +1119,635 +351,80 +1134,499 +530,542 +607,570 +898,336 +494,448 +124,240 +530,352 +209,316 +216,175 +845,325 +433,753 +281,10 +970,420 +756,547 +1150,448 +1300,332 +990,133 +120,162 +1211,198 +1041,108 +1006,824 +57,108 +281,532 +1227,600 +0,38 +248,324 +701,38 +874,644 +1029,532 +643,546 +390,544 +1074,459 +771,417 +701,89 +93,429 +522,529 +219,407 +254,99 +435,851 +1081,11 +1034,141 +440,865 +967,273 +644,561 +560,255 +811,761 +643,714 +335,628 +527,654 +991,826 +269,780 +1155,761 +666,562 +132,81 +606,124 +534,694 +100,99 +229,628 +1310,466 +1004,382 +385,780 +1186,318 +1131,842 +1197,135 +179,842 +698,2 +175,821 +226,603 +932,690 +776,648 +621,285 +445,876 +1148,345 +728,877 +350,70 +124,521 +136,301 +763,548 +641,634 +1026,532 +1213,792 +1257,821 +1017,39 +1213,266 +724,59 +1258,771 +242,794 +199,49 +966,674 +971,796 +587,316 +917,640 +574,348 +10,113 +997,893 +105,238 +366,826 +211,159 +385,675 +139,781 +1248,189 +684,45 +1134,171 +425,326 +281,49 +281,84 +639,58 +1171,304 +1215,471 +62,254 +980,626 +999,304 +1022,364 +621,833 +1096,865 +999,621 +557,248 +867,794 +952,220 +522,101 +534,200 +807,73 +90,508 +597,395 +627,483 +418,800 +788,81 +654,121 +1166,532 +62,749 +105,14 +1014,551 +976,133 +179,605 +518,558 +268,784 +1156,798 +818,766 +346,756 +246,336 +59,103 +1161,455 +350,672 +194,493 +160,448 +547,263 +1245,584 +780,364 +311,456 +428,413 +892,205 +310,738 +530,766 +97,430 +1178,365 +940,162 +585,773 +296,674 +197,844 +1263,212 +45,877 +177,170 +254,599 +999,276 +739,114 +269,227 +1252,112 +937,466 +477,394 +132,365 +18,795 +410,110 +612,408 +370,732 +97,422 +1248,749 +339,42 +780,542 +811,348 +557,136 +263,472 +154,798 +574,558 +527,212 +1283,821 +1222,397 +294,359 +956,294 +455,397 +373,84 +1091,234 +378,690 +1121,569 +1052,31 +398,46 +674,138 +293,609 +1300,751 +139,590 +776,694 +1,226 +1047,472 +723,887 +1253,114 +589,94 +780,318 +45,540 +315,348 +1139,166 +691,645 +783,269 +862,38 +1178,450 +15,724 +992,462 +229,180 +1133,410 +1238,547 +530,318 +124,542 +541,759 +1255,407 +920,544 +139,304 +380,159 +672,674 +77,138 +398,772 +1215,327 +77,756 +694,427 +776,226 +1146,889 +1275,297 +343,273 +664,798 +535,72 +1108,164 +385,640 +68,143 +264,145 +763,407 +919,198 +1220,571 +436,644 +314,868 +669,484 +339,98 +1265,682 +666,333 +763,346 +786,807 +428,525 +1176,849 +1113,844 +366,875 +155,469 +534,284 +1294,786 +477,113 +115,570 +648,313 +1178,345 +967,590 +949,39 +445,690 +372,136 +1277,487 +209,486 +57,780 +984,876 +396,591 +375,255 +1303,826 +236,459 +560,639 +822,446 +358,668 +1074,94 +833,394 +753,459 +1171,113 +1220,123 +299,521 +599,487 +326,893 +16,108 +99,696 +1171,590 +550,581 +952,332 +484,621 +115,63 +1158,445 +219,234 +1016,87 +479,73 +1005,819 +32,87 +130,87 +416,721 +780,373 +350,420 +1026,834 +683,768 +1094,47 +393,542 +557,292 +246,768 +385,499 +221,141 +1268,598 +390,145 +1041,590 +959,338 +1148,21 +313,561 +477,500 +855,621 +746,284 +872,847 +97,24 +927,39 +627,821 +887,343 +909,210 +284,532 +776,284 +914,591 +703,831 +816,448 +1260,661 +1205,126 +574,546 +763,375 +967,254 +507,38 +155,133 +498,89 +231,690 +373,466 +42,598 +586,54 +914,303 +919,646 +932,242 +826,621 +1252,782 +514,705 +933,535 +105,880 +1146,535 +1,208 +340,868 +176,499 +557,198 +574,110 +994,254 +701,805 +917,577 +319,516 +460,786 +564,688 +1230,558 +1265,877 +937,84 +905,84 +1186,206 +952,551 +633,595 +277,210 +667,9 +18,99 +246,322 +1155,166 +537,354 +882,861 +120,873 +206,572 +94,415 +820,784 +701,465 +967,142 +957,101 +703,324 +609,651 +274,383 +393,688 +997,113 +627,768 +1213,214 +974,350 +418,206 +296,641 +246,558 +1258,186 +291,521 +1248,254 +536,808 +47,212 +1183,234 +1042,110 +156,89 +152,21 +127,436 +587,887 +833,113 +1033,882 +937,458 +90,386 +1036,735 +638,108 +947,309 +15,836 +400,795 +107,498 +326,18 +194,625 +1253,141 +445,130 +418,653 +518,593 +1242,751 +171,728 +18,771 +65,352 +47,324 +1108,506 +68,751 +875,548 +314,474 +1108,165 +709,821 +140,189 +1205,432 +408,770 +293,386 +708,771 +919,248 +736,722 +1233,756 +736,348 +1216,639 +97,628 +832,395 +875,487 +878,0 +930,607 +671,836 +390,413 +547,487 +373,234 +599,407 +452,602 +45,341 +937,884 +1283,633 +269,108 +831,521 +751,343 +52,571 +981,238 +90,123 +288,19 +818,245 +1158,415 +811,693 +1272,50 +783,436 +1091,711 +97,214 +435,407 +261,102 +1056,99 +788,549 +656,121 +301,351 +423,103 +162,649 +1253,780 +45,212 +492,128 +242,346 +189,773 +1042,784 +1000,556 +547,346 +13,708 +293,855 +221,96 +319,628 +433,798 +279,271 +773,710 +835,366 +761,768 +1061,532 +55,212 +1014,103 +567,666 +654,38 +1198,410 +503,73 +343,254 +288,530 +803,856 +805,439 +372,758 +12,275 +530,373 +358,332 +689,61 +296,114 +1158,21 +592,861 +619,645 +425,646 +281,845 +433,141 +1241,325 +154,544 +721,94 +1178,338 +10,562 +499,56 +724,54 +492,560 +933,658 +827,133 +1081,360 +1068,336 +325,892 +53,821 +994,864 +170,621 +440,641 +527,240 +1297,673 +1175,96 +311,276 +1183,421 +858,602 +1245,459 +306,512 +541,154 +1123,304 +1148,128 +534,668 +626,45 +736,336 +267,343 +492,101 +638,332 +231,791 +1108,542 +1061,756 +587,344 +1178,556 +713,114 +361,855 +244,602 +1211,696 +828,880 +910,795 +537,710 +1288,196 +164,318 +304,420 +65,584 +1026,648 +72,547 +982,225 +959,80 +320,761 +11,546 +525,396 +902,770 +1183,436 +984,18 +820,873 +492,345 +999,456 +862,892 +1146,318 +944,530 +187,304 +1047,696 +971,98 +1235,722 +279,324 +57,786 +518,348 +10,332 +154,350 +344,220 +249,756 +269,171 +636,67 +740,784 +1186,542 +1029,845 +808,21 +59,775 +391,696 +756,603 +704,770 +313,551 +373,884 +967,459 +749,429 +780,688 +277,12 +300,369 +885,646 +918,472 +1041,171 +606,770 +277,882 +425,86 +1099,511 +1056,599 +1265,509 +1033,12 +1156,544 +739,294 +933,684 +499,838 +416,173 +641,260 +300,525 +194,269 +378,652 +1163,285 +713,443 +281,18 +643,9 +1053,325 +1186,240 +274,511 +23,204 +567,228 +186,257 +268,110 +592,77 +887,103 +769,154 +683,73 +1223,228 +479,521 +281,789 +1046,145 +1084,883 +557,602 +662,637 +628,600 +105,126 +440,193 +1198,484 +482,758 +997,561 +490,466 +136,546 +736,546 +956,525 + +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/2021/day13.py b/2021/day13.py new file mode 100755 index 0000000..f79366d --- /dev/null +++ b/2021/day13.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 + +def get_max_coords(points): + max_x = 0 + max_y = 0 + for x, y in points: + if int(x) > max_x: + max_x = int(x) + if int(y) > max_y: + max_y = int(y) + return max_x, max_y + + +def print_coords(points, max_x, max_y): + for y in range(max_y + 1): + for x in range(max_x + 1): + if [f'{x}',f'{y}'] in points: + print('#', end='') + else: + print('.', end='') + print() + + +def fold_y(points, temp_points, line): + for x, y in points: + x = int(x) + y = int(y) + if y > line: + new_y = line - (y - line) + temp_points.append([f'{x}', f'{new_y}']) + else: + temp_points.append([f'{x}', f'{y}']) + + +def fold_x(points, temp_points, line): + for x, y in points: + x = int(x) + y = int(y) + if x > line: + new_x = line - (x - line) + temp_points.append([f'{new_x}', f'{y}']) + else: + temp_points.append([f'{x}' ,f'{y}']) + + +def do_instructions(instructions, points): + first = True + for axis, line in instructions: + line = int(line) + temp_points = [] + match axis: + case 'y': + fold_y(points, temp_points, line) + case 'x': + fold_x(points, temp_points, line) + if first: + get_uniq = [tuple(point) for point in temp_points] + print(len(set(tuple(get_uniq)))) + first = False + points = temp_points + return points + + +def main(): + with open('day13', 'r') as file: + lines = file.readlines() + + instructions = [] + points = [] + for line in lines: + line = line.strip().split(',') + if len(line) == 2: + points.append(line) + elif line[0] == '': + pass + else: + line = line[0].split() + instructions.append(line[2].split('=')) + + points = do_instructions(instructions, points) + max_x, max_y = get_max_coords(points) + print_coords(points, max_x, max_y) + + +if __name__ == '__main__': + main() diff --git a/2021/day13.sample b/2021/day13.sample new file mode 100644 index 0000000..282114c --- /dev/null +++ b/2021/day13.sample @@ -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 diff --git a/2021/day14 b/2021/day14 new file mode 100644 index 0000000..3ba485a --- /dev/null +++ b/2021/day14 @@ -0,0 +1,102 @@ +KBKPHKHHNBCVCHPSPNHF + +OP -> H +CF -> C +BB -> V +KH -> O +CV -> S +FV -> O +FS -> K +KO -> C +PP -> S +SH -> K +FH -> O +NF -> H +PN -> P +BO -> H +OK -> K +PO -> P +SF -> K +BF -> P +HH -> S +KP -> H +HB -> N +NP -> V +KK -> P +PF -> P +BK -> V +OF -> H +FO -> S +VC -> P +FK -> B +NK -> S +CB -> B +PV -> C +CO -> N +BN -> C +HV -> H +OC -> N +NB -> O +CS -> S +HK -> C +VS -> F +BH -> C +PC -> S +KC -> O +VO -> P +FB -> K +BV -> V +VN -> N +ON -> F +VH -> H +CN -> O +HO -> O +SV -> O +SS -> H +KF -> N +SP -> C +NS -> V +SO -> F +BC -> P +HC -> C +FP -> H +OH -> S +OB -> S +HF -> V +SC -> B +SN -> N +VK -> C +NC -> V +VV -> S +SK -> K +PK -> K +PS -> N +KB -> S +KS -> C +NN -> C +OO -> C +BS -> B +NV -> H +FF -> P +FC -> N +OS -> H +KN -> N +VP -> B +PH -> N +NH -> S +OV -> O +FN -> V +CP -> B +NO -> V +CK -> C +VF -> B +HS -> B +KV -> K +VB -> H +SB -> S +BP -> S +CC -> F +HP -> B +PB -> P +HN -> P +CH -> O diff --git a/2021/day14-2.py b/2021/day14-2.py new file mode 100755 index 0000000..ba01846 --- /dev/null +++ b/2021/day14-2.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 +from collections import Counter + + +def create_semi_memo(tenth, pair_insertion): + for key in pair_insertion.keys(): + key_l = [ x for x in key ] + p_t, elements = do_insert(key_l, pair_insertion, 10) + tenth[key] = [p_t[1:-1], elements] + + +def do_final_insert(polymer_template, tenth, final_elements, iterations): + for count in range(1,iterations + 1): + length_pt = len(polymer_template) + for index in range(1, length_pt + 1): + if(index == length_pt): + break + p_t = f'{polymer_template[-index*2]}{polymer_template[-index*2+1]}' + for zindex in range(len(tenth[p_t][0])): + polymer_template.insert(-index*2+1+zindex, tenth[p_t][0][zindex]) + final_elements = Counter(final_elements) + Counter(tenth[p_t][1]) + + return final_elements + + +def do_insert(polymer_template, pair_insertion, iterations): + elements = dict() + for count in range(1,iterations + 1): + length_pt = len(polymer_template) + for index in range(1, length_pt + 1): + if(index == length_pt): + break + p_t = f'{polymer_template[-index*2]}{polymer_template[-index*2+1]}' + polymer_template.insert(-index*2+1, pair_insertion[p_t]) + try: + elements[pair_insertion[p_t]] += 1 + except KeyError: + elements[pair_insertion[p_t]] = 1 + print(count) + + return polymer_template, elements + + +def main(): + with open('day14', 'r') as file: + lines = file.readlines() + + polymer_template = lines[0].strip() + pair_insertion = dict() + final_elements = dict() + tenth = dict() + + for line in lines[2:]: + line = line.strip().split() + pair_insertion[line[0]] = line[2] + + for polymer in polymer_template: + try: + final_elements[polymer] += 1 + except KeyError: + final_elements[polymer] = 1 + + polymer_template = [ x for x in polymer_template ] + + polymer_template, elements = do_insert(polymer_template, pair_insertion, 40) + + maxi = max(list(elements.values())) + mixi = min(list(elements.values())) + + + print(maxi-mixi) + + +if __name__ == '__main__': + main() diff --git a/2021/day14.py b/2021/day14.py new file mode 100755 index 0000000..be238bf --- /dev/null +++ b/2021/day14.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 + +from collections import Counter + +def get_final_element_count(pair_count, pair_insertion, final_element_count, iterations): + for _ in range(iterations): + temp_pair_count = Counter() + for key, value in pair_count.items(): + if value: + temp_pair_count[f"{key[0]}{pair_insertion[key]}"] += value + temp_pair_count[f"{pair_insertion[key]}{key[1]}"] += value + final_element_count[pair_insertion[key]] += value + pair_count = temp_pair_count + + +def build_dicts(polymer_template): + final_element_count = Counter() + pair_count = Counter() + + for polymer in polymer_template: + final_element_count[polymer] += 1 + + for index in range(len(polymer_template) - 1): + p_t = f'{polymer_template[index]}{polymer_template[index+1]}' + pair_count[p_t] += 1 + + return pair_count, final_element_count + + +def get_pair_insertion(lines): + pair_insertion = {} + for line in lines[2:]: + line = line.strip().split() + pair_insertion[line[0]] = line[2] + return pair_insertion + + +def print_difference(final_element_count): + maxi = max(list(final_element_count.values())) + mini = min(list(final_element_count.values())) + print(maxi - mini) + + +def main(): + with open('day14', 'r') as file: + lines = file.readlines() + + polymer_template = list(lines[0].strip()) + pair_insertion = get_pair_insertion(lines) + + # Part1 + pair_count, final_element_count = build_dicts(polymer_template) + get_final_element_count(pair_count, pair_insertion, final_element_count, 10) + print_difference(final_element_count) + + # Part2 + pair_count, final_element_count = build_dicts(polymer_template) + get_final_element_count(pair_count, pair_insertion, final_element_count, 40) + print_difference(final_element_count) + + +if __name__ == '__main__': + main() diff --git a/2021/day2 b/2021/day2 new file mode 100644 index 0000000..551814a --- /dev/null +++ b/2021/day2 @@ -0,0 +1,1000 @@ +forward 6 +down 2 +forward 2 +down 8 +forward 3 +down 6 +down 8 +down 9 +forward 7 +forward 8 +down 9 +down 8 +down 9 +up 8 +forward 1 +down 7 +down 3 +forward 3 +forward 1 +down 3 +forward 3 +forward 1 +up 8 +down 5 +down 1 +forward 6 +forward 2 +up 9 +down 3 +down 8 +down 3 +down 3 +up 2 +down 7 +down 3 +up 5 +forward 4 +down 9 +forward 6 +forward 3 +forward 1 +forward 3 +down 2 +up 9 +down 4 +forward 6 +down 3 +forward 2 +down 2 +up 5 +up 1 +forward 3 +forward 6 +down 6 +forward 7 +forward 1 +down 3 +down 8 +forward 2 +down 7 +up 1 +up 2 +forward 5 +down 8 +down 8 +forward 9 +forward 7 +forward 2 +forward 7 +up 6 +up 9 +down 4 +forward 4 +forward 4 +up 1 +down 7 +forward 9 +forward 3 +down 6 +down 9 +forward 7 +forward 4 +up 7 +up 6 +up 8 +down 9 +forward 1 +down 1 +forward 8 +down 7 +forward 5 +down 3 +down 3 +down 8 +down 8 +down 4 +up 4 +forward 3 +down 8 +down 9 +up 3 +up 8 +down 9 +up 5 +forward 2 +forward 5 +forward 5 +down 8 +forward 9 +forward 8 +down 5 +down 9 +forward 6 +forward 2 +forward 3 +up 1 +forward 1 +up 2 +up 2 +forward 4 +forward 8 +forward 5 +down 1 +up 4 +forward 5 +up 7 +down 5 +down 5 +forward 8 +up 2 +down 7 +down 6 +down 5 +down 5 +down 1 +down 8 +forward 9 +forward 2 +up 6 +up 4 +down 8 +forward 1 +forward 2 +down 2 +forward 7 +forward 7 +forward 3 +forward 6 +forward 8 +down 3 +forward 6 +up 5 +down 3 +down 8 +up 1 +forward 1 +down 7 +down 3 +up 5 +forward 6 +forward 8 +forward 9 +up 5 +up 5 +up 5 +forward 8 +up 5 +down 6 +down 7 +down 5 +up 7 +up 1 +up 3 +forward 8 +up 9 +down 7 +down 4 +up 6 +up 8 +up 9 +up 9 +forward 5 +up 5 +forward 2 +forward 2 +forward 6 +up 2 +down 8 +up 2 +forward 5 +down 9 +up 7 +down 9 +forward 1 +forward 8 +up 1 +forward 7 +forward 2 +down 3 +forward 3 +forward 2 +up 9 +forward 4 +forward 9 +down 9 +forward 5 +forward 1 +forward 5 +forward 8 +up 5 +forward 1 +down 4 +up 8 +up 4 +up 7 +forward 4 +down 1 +up 6 +forward 6 +down 2 +down 7 +forward 4 +up 7 +forward 7 +forward 9 +down 5 +up 5 +forward 4 +down 6 +forward 1 +up 8 +up 8 +down 8 +down 7 +forward 7 +down 3 +forward 7 +down 3 +down 5 +down 4 +up 8 +down 2 +down 2 +up 5 +forward 9 +up 9 +forward 2 +up 4 +forward 4 +down 2 +down 7 +forward 7 +down 1 +down 6 +down 4 +forward 6 +up 4 +forward 4 +down 6 +down 8 +down 3 +forward 7 +down 3 +forward 7 +down 7 +forward 4 +up 9 +down 5 +forward 7 +forward 7 +up 6 +down 3 +forward 9 +down 1 +forward 4 +up 9 +down 3 +up 9 +down 5 +up 6 +forward 1 +forward 9 +up 4 +down 3 +forward 1 +down 7 +down 2 +forward 2 +down 6 +up 4 +down 4 +up 9 +down 3 +down 9 +down 4 +down 1 +up 8 +down 2 +up 1 +forward 5 +forward 9 +forward 1 +up 4 +forward 5 +down 7 +up 6 +down 3 +forward 8 +down 1 +down 5 +forward 5 +down 5 +down 7 +down 8 +down 7 +up 6 +forward 8 +down 8 +forward 6 +down 6 +down 7 +down 3 +forward 2 +down 6 +down 8 +down 7 +down 3 +up 1 +down 7 +forward 8 +forward 2 +forward 5 +down 4 +up 4 +forward 9 +down 9 +forward 6 +down 7 +down 4 +down 8 +up 9 +forward 7 +down 4 +forward 7 +forward 1 +forward 7 +down 9 +down 7 +forward 3 +forward 3 +forward 2 +down 5 +up 5 +forward 5 +down 2 +forward 7 +forward 9 +forward 7 +down 7 +down 9 +down 5 +forward 2 +up 5 +down 3 +forward 7 +down 4 +down 3 +up 5 +down 6 +down 3 +up 4 +forward 3 +down 1 +forward 6 +forward 6 +down 8 +forward 9 +down 2 +up 3 +down 4 +down 5 +forward 3 +down 9 +forward 2 +up 3 +up 4 +forward 9 +down 2 +forward 9 +forward 3 +down 4 +down 2 +down 5 +down 4 +forward 4 +down 1 +down 9 +down 2 +forward 8 +down 5 +forward 5 +up 7 +down 5 +down 2 +forward 5 +up 4 +down 5 +up 3 +forward 7 +down 9 +forward 5 +forward 2 +forward 1 +down 7 +down 9 +down 2 +up 2 +up 2 +up 4 +down 4 +down 7 +down 3 +forward 5 +forward 3 +up 6 +down 6 +up 6 +up 9 +forward 8 +forward 4 +up 3 +forward 1 +forward 2 +up 5 +forward 5 +forward 8 +forward 7 +forward 4 +down 1 +down 8 +down 1 +forward 3 +up 1 +forward 7 +forward 4 +down 8 +forward 7 +forward 9 +forward 3 +down 9 +down 9 +down 3 +up 6 +up 1 +down 4 +forward 5 +forward 4 +forward 6 +forward 8 +down 6 +down 3 +forward 5 +forward 6 +down 4 +down 2 +up 3 +down 3 +down 7 +down 5 +down 5 +forward 6 +down 4 +forward 1 +up 2 +forward 3 +down 1 +down 4 +down 9 +down 7 +down 9 +forward 9 +down 6 +down 3 +down 2 +down 5 +up 8 +forward 5 +forward 5 +forward 4 +up 5 +forward 1 +down 9 +down 1 +up 5 +forward 8 +forward 6 +forward 5 +down 1 +up 5 +down 8 +up 7 +down 8 +down 2 +down 3 +forward 2 +up 4 +down 6 +up 6 +down 3 +down 7 +up 3 +forward 4 +down 3 +forward 4 +up 9 +forward 5 +down 2 +forward 7 +forward 5 +up 3 +up 2 +forward 2 +down 8 +down 1 +down 3 +up 5 +down 4 +forward 4 +down 1 +forward 9 +down 3 +down 7 +down 4 +down 4 +forward 7 +up 5 +forward 4 +down 8 +up 4 +forward 6 +down 1 +up 4 +forward 4 +down 6 +up 5 +up 1 +forward 2 +down 5 +forward 8 +forward 6 +down 8 +down 7 +down 7 +down 1 +forward 5 +forward 7 +forward 7 +forward 7 +up 3 +forward 9 +forward 1 +down 9 +forward 4 +up 8 +forward 1 +forward 5 +forward 4 +down 2 +forward 4 +forward 9 +forward 3 +down 1 +forward 4 +forward 9 +forward 5 +down 5 +down 5 +forward 7 +down 3 +forward 4 +down 6 +forward 7 +down 2 +down 1 +down 5 +forward 4 +forward 9 +down 4 +forward 2 +down 8 +up 5 +down 9 +forward 8 +down 3 +up 6 +down 2 +down 4 +forward 4 +up 2 +down 4 +down 4 +up 7 +down 6 +forward 4 +down 7 +forward 3 +down 1 +up 1 +down 2 +down 6 +down 4 +up 3 +down 6 +up 2 +down 6 +forward 3 +down 9 +forward 5 +down 5 +down 9 +down 9 +down 7 +forward 9 +forward 8 +forward 9 +up 9 +forward 7 +forward 4 +forward 4 +up 5 +forward 2 +down 1 +up 9 +forward 2 +forward 7 +forward 1 +down 9 +forward 9 +up 8 +up 1 +up 7 +up 7 +down 5 +forward 2 +forward 8 +forward 6 +down 7 +forward 1 +down 9 +down 4 +down 4 +down 1 +up 7 +forward 4 +forward 6 +up 5 +forward 2 +down 9 +down 7 +forward 1 +forward 2 +down 5 +forward 3 +forward 8 +forward 6 +forward 3 +forward 2 +down 1 +forward 1 +forward 1 +forward 3 +down 9 +up 9 +down 9 +down 6 +forward 7 +down 6 +forward 9 +down 9 +down 7 +down 1 +down 9 +up 9 +down 6 +forward 9 +down 6 +forward 3 +down 8 +up 5 +forward 5 +forward 8 +up 3 +down 8 +up 6 +forward 4 +down 2 +forward 6 +down 9 +forward 6 +forward 4 +forward 9 +forward 3 +down 2 +down 4 +forward 5 +down 9 +up 7 +forward 4 +up 1 +forward 1 +down 6 +forward 3 +forward 7 +forward 2 +forward 2 +down 5 +down 9 +down 3 +down 5 +up 3 +forward 1 +down 2 +down 4 +down 1 +up 9 +up 5 +up 1 +down 1 +up 9 +down 5 +up 3 +up 3 +down 7 +forward 4 +down 6 +forward 2 +forward 7 +forward 4 +down 2 +forward 6 +forward 2 +down 3 +up 3 +up 9 +forward 9 +forward 9 +forward 6 +down 8 +down 1 +forward 9 +up 1 +down 6 +forward 6 +up 5 +forward 2 +forward 6 +down 9 +forward 1 +forward 8 +down 8 +forward 4 +forward 7 +up 6 +up 1 +forward 7 +forward 3 +forward 2 +down 4 +down 7 +down 7 +down 1 +down 6 +forward 1 +down 9 +up 9 +up 9 +down 2 +down 2 +forward 5 +up 2 +forward 7 +up 5 +down 9 +forward 7 +forward 2 +down 8 +up 1 +down 5 +forward 6 +down 8 +down 7 +forward 4 +up 2 +down 8 +forward 2 +down 5 +down 4 +down 9 +down 1 +down 9 +down 6 +down 3 +forward 1 +forward 6 +up 1 +up 1 +up 9 +down 2 +down 2 +forward 5 +down 3 +forward 4 +down 3 +down 7 +down 7 +forward 4 +up 3 +forward 4 +down 3 +forward 8 +forward 1 +up 2 +up 1 +forward 1 +down 6 +down 1 +down 3 +forward 7 +down 7 +forward 4 +forward 5 +forward 3 +down 5 +forward 9 +forward 5 +down 7 +forward 6 +down 4 +down 4 +down 9 +down 3 +up 9 +forward 7 +down 7 +forward 6 +down 2 +down 9 +forward 4 +forward 1 +forward 4 +down 5 +forward 7 +down 9 +down 8 +forward 9 +forward 1 +down 9 +forward 6 +up 5 +forward 9 +down 1 +down 5 +forward 4 +forward 5 +forward 8 +down 5 +forward 9 +down 6 +down 2 +up 4 +up 8 +forward 3 +forward 4 +down 3 +forward 4 +up 6 +forward 3 +forward 8 +forward 7 +down 1 +down 9 +down 8 +down 8 +down 1 +forward 9 +up 4 +down 5 +forward 7 +down 8 +down 3 +forward 9 +down 5 +forward 7 +forward 2 +down 4 +forward 2 +forward 7 +down 6 +forward 7 +down 2 +forward 9 +down 9 +forward 8 +forward 8 +down 6 +forward 7 +down 8 +forward 7 +forward 3 +down 1 +up 8 +down 5 +down 6 +up 5 +forward 5 +forward 5 +up 5 +up 3 +up 7 +down 6 +forward 8 +forward 4 +down 2 +up 5 +forward 8 +down 6 +forward 4 +forward 2 +up 8 +down 8 +down 5 +down 4 +forward 9 +forward 9 +forward 6 +forward 6 +down 3 +up 1 +down 4 +down 8 +down 9 +down 1 +forward 3 +forward 1 +down 9 +down 3 +down 7 +forward 6 +forward 9 +down 8 +down 8 +forward 6 +forward 1 +down 3 +forward 1 +down 8 +down 3 +down 9 +up 1 +forward 6 +up 2 +down 3 +forward 4 +forward 2 +up 2 +down 5 +forward 1 +down 3 +forward 9 +forward 4 +forward 6 +down 3 +forward 7 +down 6 +up 3 +up 7 +up 5 +down 4 +forward 4 +up 1 +forward 7 +up 9 +forward 3 +up 1 +down 3 +down 4 +forward 4 +up 3 +down 6 +down 9 +down 6 +forward 4 +down 9 +down 6 +forward 4 +forward 3 +down 3 +up 7 +down 9 +forward 8 diff --git a/2021/day2.py b/2021/day2.py new file mode 100755 index 0000000..016fe8d --- /dev/null +++ b/2021/day2.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +def main(): + with open('day2', 'r') as file: + lines = file.readlines() + + position = 0 + depth = 0 + position_2 = 0 + depth_2 = 0 + aim = 0 + for line in lines: + command = line.split() + + match command[0]: + case 'forward': + position += int(command[1]) + position_2 += int(command[1]) + depth_2 += aim * int(command[1]) + case 'up': + depth -= int(command[1]) + aim -= int(command[1]) + case 'down': + depth += int(command[1]) + aim += int(command[1]) + + print(position * depth) + print(position_2 * depth_2) + + +if __name__ == '__main__': + main() diff --git a/2021/day2.sample b/2021/day2.sample new file mode 100644 index 0000000..b7172ac --- /dev/null +++ b/2021/day2.sample @@ -0,0 +1,6 @@ +forward 5 +down 5 +forward 8 +up 3 +down 8 +forward 2 diff --git a/2022/day1 b/2022/day1 new file mode 100644 index 0000000..98e0ab4 --- /dev/null +++ b/2022/day1 @@ -0,0 +1,2255 @@ +3344 +8938 +7923 +3979 +2753 +5730 +4225 + +24216 +7432 +18284 + +3475 +9177 +6769 +11335 +8061 +9302 +8132 + +25796 + +20937 + +2039 +4989 +5932 +5434 +5088 +7185 +1271 +8359 +5489 +8646 + +7796 +1233 +3529 +4118 +7093 +7090 +8757 +2283 +5562 +3789 + +2296 +2105 +1978 +2981 +5682 +1627 +2285 +5654 +5596 +2022 +2733 +3078 +3176 +4158 + +6294 +3789 +1863 +5121 +6122 +7309 +7063 +4233 +1717 +6755 +5505 +2713 + +4988 +5133 +4933 +6407 +2897 +2682 +5328 +4268 +1518 +4631 +2736 +1432 +3812 +1031 + +4553 +1109 +7214 +2744 +8389 +3180 +7464 +5584 +7689 +6452 + +5645 +6207 +2497 +1114 +5747 +2620 +2621 +1866 +2334 +1324 +5879 +6322 +4954 + +8723 +24316 +4375 + +4051 +6866 +7417 +4650 +6035 +6580 +3881 +3041 +1443 +6659 +2951 +2387 + +5606 +1862 +3300 +6106 +5944 +2306 +1935 +5717 +6204 +1882 +2455 +4790 +4534 +4144 + +3278 +5536 +4686 +4331 +1750 +1742 +2103 +6754 +5417 +2242 +2374 +5133 +2315 + +34403 + +5574 +2129 +2846 +5790 +1428 +1220 +1523 +5768 +2226 +1442 +1139 +3295 +3831 + +3231 +3998 +5904 +6878 +3082 +2159 +2806 +2388 +1878 +1393 +6929 +6812 + +18094 + +4972 +4575 +5522 +5582 +2776 +3971 +3595 +1959 +4161 +4550 +1987 +4519 +4551 +3546 +3562 + +4913 +5328 +2726 +5349 +6670 +7650 +7799 +3818 +5536 +2765 + +1674 +3454 +5921 +6170 +3474 +1401 +5993 +5098 +3269 +5671 +5385 +5418 + +4381 +35451 + +1970 +6227 +6781 +3622 +2921 +2360 +5673 +2344 +5503 +5006 +6866 +1804 +2559 + +12473 +1374 +23850 + +7943 +1442 +3091 +2907 +1538 +6027 +1389 +4851 +3301 +1324 +6017 + +13712 +11949 +4399 +1093 +2546 +6876 + +5429 +1453 +7989 +9605 +2344 +10505 +4563 +3537 + +6061 +1428 +3435 +5752 +1097 +3313 +2318 +1656 +2206 +6922 +6612 +2805 +3123 + +2613 +6493 +3283 +5206 +4118 +3058 +1377 +4453 +6195 +3371 +5520 +6197 +5121 +1622 + +8199 +5761 +6985 +6058 +8277 +9247 +8937 +4739 +5107 + +11764 +13344 +5462 + +4453 +10616 +8770 +6014 +6991 +7898 + +5873 +12987 +16138 + +9294 +8381 +3175 +1945 +8195 +2851 +1780 +6140 + +3655 +3450 +6771 +4950 +3491 +6883 +4408 +4505 +2513 +6768 +4868 +3883 +4458 + +39217 + +15599 +1459 +19930 +6992 + +9392 +6380 +4470 +5228 +8009 +7680 +1815 +4365 +5529 + +8677 +6381 +10150 +2299 +2071 +9364 +5633 + +1778 +5304 +1883 +2215 +4288 +4214 +7602 +2987 +7011 +1652 +5977 + +2093 +20240 +18383 + +4600 +2704 +3915 +3853 +5659 +2905 +3480 +3546 +4647 +6062 +3613 +6095 +4079 + +6352 +4362 +5767 +7708 +2318 +10738 +1956 + +5581 +6478 +5624 +3850 +5025 +3754 +2559 +4730 +1299 +1187 +3771 +1432 +1590 +5108 + +3412 +10022 +1478 +3654 +4938 +3611 + +3455 +5118 +6647 +7160 +7244 +2902 +6305 +1204 +2124 +5595 +7040 +5145 + +1502 +8426 +6808 +9175 +3902 +5516 +5310 +4122 +7357 + +8679 +14080 + +23992 +17036 + +1880 + +2799 +3910 +3661 +3680 +4159 +5746 +6249 +2614 +2012 +7433 +5092 +3067 + +35016 +24321 + +9575 +2970 +17157 + +3129 +2954 +2520 +5998 +2854 +5823 +2469 +3786 +2683 +3300 +3360 +5413 +3959 + +28905 +4100 + +24304 +7180 +23566 + +5990 +1740 +1955 +5498 +1754 +3458 +4856 +4499 +3560 +3275 +1443 +1815 +1511 +1106 + +1466 + +10351 +8066 +5699 + +4995 +7451 +7189 +2348 +3600 +3320 +3351 +5857 +6388 +3787 +1923 +6228 + +6125 +1302 +6779 +3279 +13428 +7624 + +41865 + +2353 +11924 +6498 +10636 +1592 +3990 +2269 + +7281 +4294 +3083 +10444 +4489 +4468 +1400 +4482 + +63998 + +2373 +2091 +6067 +3372 +1996 +6542 +1423 +5041 +6251 +4682 +5574 +2506 +6784 + +1243 +1014 +1653 +2960 +1459 +4820 +4623 +5541 +3455 +3260 +1161 +1395 +3963 + +3299 +1686 +4068 +7455 +3737 +6857 +7771 +7383 +7769 +4641 +3105 + +8109 +1367 +5553 +8315 +8042 +4244 +6974 +1062 + +50228 + +6657 +22682 + +4093 +5296 +8752 +9532 +11488 +3792 +11225 + +2753 +16207 +10646 +11950 + +1505 +4569 +6688 +4674 +7154 +7342 +4675 +8434 +5637 +3789 + +5625 +3177 +2820 +1075 +3657 +4862 +3879 +1954 +3185 +4563 +1413 +5323 +6048 +3166 + +4933 +1874 +5953 +6528 +6915 +3449 +6867 +6892 +6105 +3012 +2055 +5516 +3026 + +14676 +25751 +4615 + +3163 +5888 +4144 +3845 +6817 +6989 +6211 +1620 +7624 +1390 +5321 + +8348 +2441 +12492 +12656 +13889 + +6433 +1032 +2005 +5844 +3864 +2370 +6664 +5540 +2943 +5135 +3375 +2236 +4305 + +6269 +3979 +1844 +3799 +3947 +5858 +1338 +2761 +2285 +5192 +1358 +1810 +5009 +1346 + +4183 +3118 +4232 +5655 +4391 +4210 +5644 +3865 +4049 +1951 +2839 +5212 +1862 +5991 +4452 + +4299 +1037 +3491 +3002 +6062 +2026 +1007 +7398 +1697 +5797 +5922 +5352 + +53946 + +7483 +3663 +1134 +4279 +5315 +2756 +1280 +5807 +1892 +3701 +2848 + +21603 +4098 +21937 + +1914 +1812 +6990 +2754 +2459 +5984 +3895 +7411 +5240 +1022 +4323 +4382 + +3803 +1698 +5774 +1680 +2122 +2865 +6470 +2921 +7619 +4584 +1788 + +28678 +10385 + +12207 +12265 +3932 +13284 +12672 + +5559 +5610 +1230 +5547 +3945 +1566 +2589 +1948 +2313 +4243 +2472 +1343 +1317 +5152 +1953 + +1082 +6063 +1974 +2054 +2931 +5433 +4410 +4584 +4896 +2825 +3945 +5849 +3615 +2464 +1560 + +6494 +7717 +4697 +3012 +4515 +3802 +8621 +6041 +6939 +3059 + +1747 +8291 +4058 +2884 +1775 +8465 +5889 +4807 + +6263 +7346 +8014 +8081 +5361 +4950 +2721 +5656 +3858 +7486 + +11877 +5145 +10149 +2148 + +8389 +4492 +5074 +9457 +5132 +4355 +3254 +9607 +4059 + +5858 +7062 +9260 +6672 +2291 +1448 +7436 + +8943 +6577 +8042 +2056 +9801 +9060 +10243 +10758 + +11606 + +6340 +4468 +4225 +6861 +5648 +2951 +2556 +5794 +2657 +1450 +5888 +4363 + +1294 +3826 +3132 +2798 +5133 +2118 +4319 +1681 +5402 +4255 +4831 +1300 + +4233 +6221 +6336 +5287 +5566 +2796 +3047 +5486 +1849 +3572 +3709 +7014 + +2418 +7218 +1153 +8036 +2015 +1385 +5385 +2775 + +5788 +17132 +1734 +6843 + +17843 +2755 +4097 +1314 + +7448 +3025 +3255 +6379 +1817 +7363 +4086 +3106 +7192 +3632 +2748 +6634 + +11495 +6431 +6756 +7335 + +3090 +2890 +6300 +5939 +4045 +1781 +5080 +6123 +2589 +5990 +4438 +2903 +2789 +4761 + +2633 +5069 +6129 +1870 +2148 +2688 +4932 +5756 +5281 +3209 +2040 +5708 +2292 +2027 + +68293 + +4087 +4630 +5781 +5165 +3022 +1847 +4922 +2792 +4629 +6178 +3427 +4536 +4802 +1733 + +11367 +12689 +13239 + +7698 +7879 +2401 +7045 +9018 +2767 +8286 +5754 +7154 + +43194 + +4845 +3694 +1107 +3687 +7597 +7787 +8056 +8010 + +3598 +4505 +3676 +5174 +4271 +1290 +1116 +5257 +1343 +2660 +6227 +1303 +1217 + +31264 +17846 + +3026 +3533 +4579 +4017 +3465 +5489 +3720 +3146 +1755 +6197 +2181 +6449 +4893 +1766 + +1225 +2725 +5173 +3401 +4172 +2673 +6005 +8950 +8838 + +7416 +1467 +4741 +2043 +3032 +2290 +4182 +4493 +4860 +4543 +6791 + +9989 +23051 +12756 + +2995 +1859 +2029 +1520 +1287 +5281 +2299 +2794 +6913 +1477 +3639 +5475 +1198 + +4513 +5732 +6462 +1327 +1149 +6276 +5925 +5654 +5283 +1177 +1802 +2093 +4928 +1355 + +8874 +2550 +10268 +8362 +9158 +6929 +10674 + +5052 +2678 +6754 +6411 +1197 +7463 +3835 +5308 +8160 + +9428 +1308 +1957 +6146 +7962 +9350 +3699 +6982 +7111 + +5388 +3451 +3865 +4881 +5709 +6812 +3177 +2124 +3329 +8718 + +16156 +14022 +16031 +7972 +2381 + +3696 +12103 +9136 +9793 +11491 +6030 + +10542 +9283 + +1040 +3593 +1510 +2450 +5138 +5137 +1935 +3159 +2562 +1604 +5280 +1282 +1059 +3784 +2287 + +2464 +4363 +6262 +1136 +7072 +2328 +1517 +7229 +5730 +2456 +1681 +7213 + +4983 +4935 +6580 +1118 +5291 +4664 +4778 +6818 +5331 +6254 +5525 +1214 +1659 + +4535 +4602 +1741 +2803 +2795 +1195 +2041 +1147 +5091 +4244 +6115 +4765 +2074 +4711 +2985 + +1487 +5322 +2729 +5893 +4743 +5788 +5701 +5954 +1570 +2214 +7415 +2549 + +7483 +12474 +7468 +5340 + +1699 +1294 +4841 +3882 +1746 +5642 +5753 +4051 +2750 +4079 +5881 +4307 +2535 + +36712 +25729 + +1493 +9804 +6491 +3737 +5900 +8810 +2677 + +32912 +35589 + +15457 +17689 +15413 + +9642 +12851 +7416 +5456 + +10946 +9357 + +34589 + +11079 +18789 + +1029 +13280 +1556 +6080 +14840 + +2352 +7024 +1303 + +6432 +4312 +3800 +1713 +4580 +2574 +6955 +6129 +1054 +4104 +4150 +3146 +1777 + +8253 +6799 +1492 +8292 +6260 +4014 +7500 +3738 +1349 +7391 + +9308 +8918 +4943 +1408 +6212 +7375 +8604 +6907 + +3994 +10181 +7867 +4339 +8321 +3496 +6332 +8291 + +5058 +6311 +8770 +10517 +8510 +1807 +10295 +2060 + +11864 +12981 +10287 +10881 + +17316 +9524 +16372 + +4423 +5322 +4954 +11336 +8543 +8031 + +1576 +9103 +8531 +11398 +4900 +1621 + +5162 +1057 +12960 +16173 +8403 + +2436 +4121 +5143 +3486 +5542 +2598 +6157 +5536 +6005 +1953 +2645 +1790 + +1211 +5673 +7658 +6331 +6354 +5775 +2821 +5983 +5338 +6135 +7436 + +3891 +4230 +6457 +5382 +8435 +8484 +6872 +1750 +6127 + +8997 +7290 +6789 +13725 +3285 +13318 + +7602 +6264 +6286 +5290 +4403 +3829 +5456 +2632 +2556 +5225 +1189 + +9054 +11332 +1990 +6952 +3916 +10222 +1268 + +3599 +4346 +2535 +2775 +1140 +5020 +1050 +1119 +1373 +6191 +6996 +7381 + +15115 +5092 + +5201 +4358 +6447 +3800 +5425 +2062 +6314 +3184 +5203 +5626 +6024 +1408 +2543 +5400 + +4602 +8699 +3729 +3608 +3425 +6182 +1210 +4268 +8660 + +5167 +3056 +2162 +5024 +5586 +7900 +4688 +2166 +7268 +2577 + +2871 +4288 +3167 +7065 +7042 +6419 +2788 +6489 +1584 +3162 +5541 + +8083 +9590 +8100 +2032 +6749 +4610 +4924 +2628 +2110 + +2103 +5752 +2489 +2898 +5077 +4422 +1491 +5660 +2916 +6302 +5032 +1998 +5007 +3953 + +7090 +2458 +15291 +7943 +4677 + +3938 +6524 +3715 +1700 +3637 +3124 +6519 +5349 +1768 +5571 +1725 +1038 +4694 + +19691 + +6409 +2963 +4723 +3601 +6292 +1298 +4875 +4930 +5750 +6376 +4620 +5066 +6434 +5973 + +7194 +10283 +4302 +6346 +6744 +4990 +9302 +3257 + +5500 +4929 +4011 +3026 +1247 +5017 +2477 +2815 +3206 +3386 +5563 +3704 +2510 +5969 + +3588 +4251 +1214 +4568 +4747 +4950 +4670 +3810 +4616 +1599 +5738 +2651 +5971 + +7252 +4958 +7736 +7267 +1115 +1936 +3503 +8340 +3581 + +19911 +9923 +5937 +11827 + +16111 +1929 +1567 +2584 + +4411 +6070 +5904 +5425 +1684 +2343 +1569 +4476 +3774 +5901 +2230 +4560 +4894 +3532 +3679 + +19875 +3275 +1303 + +1111 +2927 +1812 +2341 +5611 +1602 +1876 +2430 +2810 +5400 +1909 +1341 +2605 +1860 + +1387 +4755 +1827 +3107 +5734 +3912 +7449 +5100 + +12046 +4731 +10977 +8509 +15801 + +9891 +19111 +15136 +6515 + +5839 +2497 +4195 +2027 +5340 +6432 +7256 +2774 +4934 +6521 +4715 + +5351 +6545 +5531 +10516 +10280 +10482 +6863 + +54895 + +3515 +3873 +1035 +9079 +10474 +8983 +6396 + +1564 +5340 +2239 +2539 +2464 +1083 +3777 +2981 +4247 +4471 +1687 +1693 +3053 +5160 +3384 + +4827 +3949 +3489 +5192 +3342 +4695 +4461 +6165 +1891 +5060 +5961 +1543 +2959 +6262 + +18480 +2939 +10591 + +3496 +14216 +4695 + +2178 +5400 +5298 +6806 +2108 +3793 +5762 +4787 +3032 +3819 +1834 +2905 +5070 + +8889 +1553 +11822 +11140 +1604 +11187 +3094 + +3950 +3808 +6643 +1323 +4637 +1465 +5416 +6504 +5400 +6691 +6056 +4358 +5209 + +5821 +4259 +2389 +7085 +6813 +2094 +2901 +7089 +6160 +6301 +4980 +4239 + +5431 +5016 +9948 +1158 +3133 +4783 + +2650 +6541 +6230 +6789 +6499 +2613 +2358 +3241 +3777 +5018 +4522 +4057 +5587 + +3428 +5879 +2228 +2436 +5905 +4346 +6072 +3843 +2432 +1342 +1339 +4727 +6823 + +15873 +19800 +13068 + +1866 +12061 +11047 +15922 + +19221 +9883 +5634 + +1072 +13511 +18294 + +64548 + +5313 +13972 +2829 +16260 + +2945 +2469 +1966 +2968 +4563 +3434 +3095 +5102 +5678 +2491 +3625 +5366 +2994 + +4920 +3123 +4726 +5313 +3148 +3510 +5397 +2081 +5252 +1949 +4929 +6472 +5292 + +6040 +3246 +6110 +4395 +2589 +6227 +4105 +3881 +5992 +4294 + +6363 +3364 +7225 +7105 +1912 +7460 +1929 +2680 +6231 +3061 +7856 + +5043 +1059 +4183 +4697 +3634 +3572 +1636 +2635 +2733 +5600 +4000 +6300 +1367 + +2560 +1074 +1473 +6555 +6887 +5044 +6544 +5101 +3041 +3100 +2924 +5388 +6025 + +8736 + +2235 +19236 +12524 + +3968 +2552 +11328 +10347 +5092 +4822 + +3051 +6914 +7082 +4322 +4701 +5313 +1889 +5562 +7529 +7673 +3085 + +1518 +10390 +1706 +5313 +7800 +8948 + +6670 +6555 +1881 +6658 +5687 +1338 +1547 +6876 +4657 +2061 +3742 +2958 +6836 + +9112 +2305 +9461 +10472 +8796 +8858 +5303 +3259 + +4281 +1131 +2165 +10304 +9662 +9627 +10574 + +8949 +12010 +13033 +5232 +3433 +8212 + +8478 +9908 +9043 +4869 +11600 +12466 + +2444 +8308 +9337 +3539 +6796 +7175 +4099 +9456 +6075 + +2503 +1993 +3162 +9282 +3378 + +4406 +1417 +10195 +6361 +3735 +10131 +4131 +2617 + +28770 + +11378 +13601 +14324 + +9222 +1090 +2246 +3436 +4692 +2317 +6684 +5515 +3608 + +8442 +8781 +6388 +6511 +5283 +3505 +7294 +3703 +2752 +2541 + +2160 +5683 +8706 +7818 +1283 +3659 +1465 +7255 +2556 +7496 + +4351 +2585 +3091 +6105 +2960 +6796 +6028 +1223 +3791 +2543 +2221 +1342 +1228 + +2678 +5749 +8275 +6535 +4567 +2629 +5222 +8406 +3528 +7274 + +11561 +8495 +11196 +6072 +4726 +6342 +4271 + +3035 +4638 +6716 +4871 +5516 +2387 +1828 +3695 +5199 +4602 +2372 +5376 +6229 + +5904 +7241 +1735 +4137 +5267 +7228 +6840 +2122 +5707 +3875 +5913 +6192 + +3372 +6579 +6596 +4463 +2498 +3147 +1505 +1879 +5437 +6317 +2129 +3425 +1569 + +7582 +4017 +9553 +5929 + +2721 +1439 +5723 +1790 +10437 +10251 +6175 + +3037 +2342 + +4409 +7389 +6107 +1920 +5975 +3859 +5681 +7411 +2409 +5083 +2678 +3001 + +6304 +6453 +8158 +1532 +2956 +1314 +4902 +5140 + +1964 +6243 +8353 +3374 +7134 +1951 +2425 +6063 +2765 + +7148 +12369 +7870 +3802 +10446 +10955 + +1377 +2579 +4886 +4537 +5929 +2946 +3894 +5212 +3825 +1003 +1884 +5017 +4114 +1895 diff --git a/2022/day1.py b/2022/day1.py new file mode 100755 index 0000000..fd79bc4 --- /dev/null +++ b/2022/day1.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +def main(): + with open('day1', 'r') as file: + lines = file.readlines() + + list_calories = [] + current_calories = 0 + max_calories = 0 + for line in lines: + if line == '\n': + list_calories.append(current_calories) + if current_calories > max_calories: + max_calories = current_calories + current_calories = 0 + continue + current_calories += int(line) + + list_calories = sorted(list_calories, reverse=True) + top_three = sum(list_calories[:3]) + print(list_calories[0]) + print(top_three) + +if __name__ == '__main__': + main() diff --git a/2022/day2 b/2022/day2 new file mode 100644 index 0000000..20e0cef --- /dev/null +++ b/2022/day2 @@ -0,0 +1,2500 @@ +C Y +C X +A Z +B X +B Z +C X +C X +B Z +C X +B Z +C X +C X +A X +C Y +A X +C Y +B Y +C X +C Y +B Z +A X +C X +B X +B X +B Z +A Z +C Z +B Z +B Z +C X +B Z +C X +B Z +B Z +C X +C Y +B Z +C Y +A Z +B Y +C X +C Y +A Z +B Z +B Z +C X +C Y +B X +B Z +A X +B X +A X +B Z +C Y +C Y +A X +C X +C X +B X +A Z +C Y +C X +B Z +A Z +C Y +B X +C Y +B Z +C X +B X +B Z +B Z +C Z +B Y +C Y +B Y +A Z +A X +A Y +A Y +C Y +C X +C X +B Z +B X +C X +B Z +A Z +C Y +C Z +C Z +B X +B Z +C Y +A Y +A X +C X +B Z +B Y +B X +B Z +B Z +A X +C Y +C Y +C X +A X +B Z +A Z +A X +B Z +C X +C Z +C Z +C Y +C Z +B Z +C Z +C Y +B Z +A X +C Y +B X +C Y +B Z +C Y +A Z +A X +B Z +A X +A Y +B Z +C X +C Y +C Y +B Z +B Z +A Z +C X +A Z +A X +A Z +B Z +B X +A Z +B Z +B Y +C X +C Y +C X +C X +A Z +A Z +C Y +B Z +C Y +B X +C Y +C Y +B Z +C X +B Z +A Z +C Y +C Y +B Z +A X +C X +B Z +C X +B Y +A Y +C X +B X +C Y +B Z +C Z +C X +C Z +B Z +B Y +A X +A Z +B Z +A Z +C X +A X +C X +C Y +C Z +A Z +B Z +B X +B X +A Y +B Y +C Y +B Y +B Z +A X +A Y +A Z +B X +B Z +C Z +C Z +B Z +C Y +C Y +C X +C X +B Z +B Z +C Y +A Z +C X +C Y +A Y +A X +B Z +C Z +C X +C X +C X +A Z +C Y +B Z +B Z +C X +C Y +C Z +B Z +C Y +A X +A Z +A Z +C Y +A X +B Z +C Y +C X +C X +B Z +C Z +B Z +B Z +B X +A Z +C Y +C Y +C X +B Z +B Y +B Z +B Z +C Y +A X +A Y +C Y +A X +C Y +C Z +A Y +A X +B Z +A X +A X +A Y +B X +B Z +C Z +B Z +B Z +B X +B X +C X +A X +C Y +C X +C Y +A X +B Z +A X +A Y +B Z +C Y +B Z +B Z +C Y +A Y +A Z +C X +C Y +C Y +C X +C Z +C Y +B Z +C Z +B X +C Z +B Z +A Z +B X +C X +C X +B X +B Z +C X +C X +B X +A Z +A X +A Z +B Z +B Z +B Z +A X +C Y +C Y +B Z +A X +A X +B Y +C Y +B X +C X +C Y +C X +C Y +A X +B X +A Z +A Y +B Y +A Z +B X +B Z +B Z +A Y +B X +C Y +B X +B Z +B Y +A X +A Z +C X +C X +C Z +C Z +B X +C X +B X +C X +B X +B Z +B Z +B X +B Y +C Y +A Z +B Y +A Z +C Y +B Z +C Z +C Z +B Y +B X +B X +C X +A Y +A Z +B Y +A Z +A Z +A X +A Z +B Y +A X +A X +C Z +C X +C X +C X +C Z +A Z +C Z +B Y +B Z +A X +B Z +C Z +C X +C Y +C X +A Z +C Y +C Y +C Y +B X +C Y +A Y +C Y +C X +A Z +A X +B Z +C Z +C X +A X +B Y +C Y +B Z +B Z +B Z +C Z +A Z +C Y +C X +C Z +C X +B Z +B Z +A X +B Z +A Z +A Z +B X +C Y +C Y +A X +B X +B Y +A X +C Y +A Z +C Y +C Y +B X +B X +B Z +B X +A Y +C Y +C Y +C Z +B X +A Y +A X +A X +C Y +C Z +C Y +A X +C Y +A X +B Y +B X +A X +C X +C X +A X +A Z +A X +C Y +B Y +B Z +B Y +C Z +A Z +B Y +A Z +A X +C X +B Z +C Z +B X +B Z +A Z +B Z +C X +B Z +B X +B Y +C Z +B Y +C Y +C X +C X +C Y +A Z +B Z +B X +B Z +B X +C Z +A X +A X +A X +B Y +B Y +B Z +A X +B Z +A X +A Z +B Z +B X +B X +A Z +A X +B Z +C Z +C Z +C Z +B Z +C Y +C X +C X +B Z +C Z +B Z +C Y +C X +B Z +C Z +B Z +B Z +B Z +C X +C X +B Y +B Z +B Z +C X +C Y +A X +A Z +C Z +C Z +C X +C Y +A Z +C Z +B Z +B Z +C Y +C X +B X +B Z +A Z +B Z +C Y +A X +B X +A X +C Z +C Y +C X +C X +B Z +C Z +B Z +C Z +C Z +A X +B Z +B Y +B Z +C X +B Z +A Z +C X +A X +B Z +C Z +C X +A X +C Z +A Y +B Z +C Z +C Y +A Z +B X +C Z +A X +A Y +C X +C Z +B Z +C X +A Z +B Z +C Z +C Z +A Y +C Y +C X +A Y +B Z +A Y +C X +C X +C Z +B X +B Z +C Y +A X +A Z +B Z +B Z +C Z +B Z +A X +A Y +B Y +A Z +B Z +B Z +C X +A Y +C Y +B Z +C X +B Y +B X +C Y +C X +B Z +B Z +B Z +C Y +B X +A X +B Z +C X +C Z +C X +A Z +B Z +C Y +B Z +A X +A X +B Z +C Z +C Z +B X +A Z +C Z +C X +B X +C Y +B Z +A X +C X +A Z +C Z +B X +B Z +A X +A X +B Z +C Y +C X +A Y +C X +C X +A X +A Z +B Y +C Z +C Z +C X +A Y +C X +B X +C X +B Y +C Y +B Z +A Z +C Z +A Y +A Z +B Y +C X +B Z +C X +C Y +C Z +B X +A X +C X +A Z +B Z +A Y +C Y +B Z +C X +C X +C X +B Y +C Y +B X +C X +A Z +A Y +A Z +C X +C Z +C X +C Z +B Y +A Z +B Z +C Z +B Z +B Z +C X +B Z +A Z +C Z +C Z +C X +A Y +B X +B Z +A Z +B Z +A X +B Z +C Y +C X +C X +A X +C X +B X +C Y +C X +B Z +B Z +C X +B Y +C Y +B Y +B X +C X +B X +B Z +B Z +C Y +A X +A X +A Z +A Y +C X +B Y +B Y +A Y +C Z +B X +B Z +B Z +C X +C Y +B Z +C Y +C Z +C X +C Z +A Z +B Y +A Z +B Z +C Y +C X +C Y +B Z +B Z +C X +C X +B Z +A X +A Z +C Y +B Y +A Y +B X +B X +A Z +B Z +B Z +A Z +A Z +C X +C X +C Y +C Z +A Y +C Y +B X +B Z +C X +B Z +C Z +B Z +C X +B Z +B X +A Y +B Z +C X +C Y +B Z +C X +C Y +C X +C X +A X +C X +C Y +A Z +B Z +C X +C Y +C Y +A Z +B Z +C X +C X +B X +A X +C X +C Y +B Z +C X +C X +C X +C Z +C Z +B Z +B Z +C Z +C Z +C X +A Z +C Y +C Y +C X +C Z +C Y +A Z +A Z +A Z +C Y +C Y +B X +B Z +B Y +C Z +A Z +C Z +C Y +C Z +A Y +A Y +B X +B Z +B X +A X +B X +C Z +C X +B Z +C Z +C Z +B Z +C X +C X +A X +C Z +C Y +A Z +A Z +C Z +A Y +B Y +B Z +C Z +A Z +A X +C Y +B Z +A X +B Z +B Z +A Z +A X +A Z +C Z +C X +B X +C Y +B Z +B X +C Y +C Y +B Z +C X +C Y +C Z +A Z +B X +C Y +A Z +C X +B Y +B Y +C Y +B Z +B Z +A X +C X +B Z +C X +B Z +B Y +C Y +B X +C Z +B Z +C Z +B Z +B Y +C X +C Z +C Z +C Y +B X +B Z +C Y +B Z +C Z +B Z +B Z +B Y +C X +C Y +C X +C X +A Z +C Y +C Y +C Z +A X +C X +B Y +B X +A Y +C X +B Z +C Y +C Y +B Z +B Y +B Z +C Y +C Y +C Y +C X +C X +A Z +C Y +C X +C X +A Y +C Y +B Z +A X +A X +C X +B Z +C Y +C Z +B Z +B Z +C Z +C Y +B Z +B X +C Z +B Z +C Y +C Z +B X +A Y +A Z +B X +C Z +C Y +A X +B Z +A X +B Z +B X +C Z +C Y +C X +A Z +C Y +C Y +A Z +A X +C Y +A X +A X +A X +B Z +C Y +B Z +B Z +B Z +C X +B Z +A X +B Y +C Y +C X +C X +C Y +C Y +A X +A X +C Y +C Z +B X +C Y +A X +C X +C X +C Y +B Z +B Z +A Y +B Z +C Y +C Y +C Y +B Z +C Z +C X +C X +B Z +C X +B X +B Z +B Y +C X +C Y +A X +B Z +B Z +C X +B Z +B X +B Z +C Y +B Z +C Y +C X +B Z +B Y +A Y +A X +A Z +A Z +B Y +A X +A X +C Y +C Y +A X +B Z +C X +A Z +B Z +B Z +A Y +C X +B Z +A Y +C Z +C Y +B X +C Z +C Z +C X +C Y +C X +C Y +B Z +B Z +B Z +B Z +A X +C Z +B Z +A Z +A X +A X +C X +C Y +C X +C X +C Z +C X +A Y +B Z +C X +A Z +B Z +C Y +B Z +A Z +A X +C X +A Z +C Z +A X +C Z +C Y +C Y +A X +C X +B Y +C Y +C Y +A Z +B Z +A Z +C Z +A Z +C Y +A X +C X +C Y +C Y +B Y +B Z +A Z +C X +B Y +A X +C Y +A Y +C Z +A Z +C Z +A X +B X +A Z +A Y +C X +A X +B Z +B Y +C Y +B Y +C X +B Z +C X +C Y +B Z +B X +B X +A X +C X +C Z +A X +B Z +C X +C X +C Z +B Y +A Z +A X +C Y +C Z +B Z +C X +B Y +B X +C X +C Z +C Y +B Z +A Z +B X +B Z +C X +C Y +C X +C X +B Z +B Z +B Z +B Z +B Z +C X +A Y +C Z +C Y +C X +C X +A Z +B Z +C Y +C Z +B X +B X +C Z +B Z +C Z +B X +B Z +C Z +C Y +B Z +A X +A X +C Y +C Z +C X +C X +A Z +C Z +C Z +B Z +C Z +B X +C X +A X +C X +B X +C Z +C X +A X +C Y +B Z +B X +C X +C X +C Z +B X +B Z +B Z +A Z +B Z +B X +A Z +C Y +B Z +C Z +C X +C Z +B Y +C Y +A X +B Y +B Z +C Z +B X +C Z +C Y +B Z +B Z +B Z +B Z +A X +B X +B Z +B Y +B Y +B Z +A Z +B Z +B Z +B X +B X +C X +B X +A Z +B Z +A Y +C X +B Y +A X +B Z +A X +B Z +C Y +C X +B Z +C Y +A Y +A X +C Z +B X +A Y +B Z +C Y +A X +C Z +C Y +C Z +A Z +B Y +A Z +C Y +C Y +A Y +A Z +C Y +C X +C X +C X +C Z +A Y +C X +C Y +A Z +B Y +B Y +B Z +A Z +B Z +A Y +B X +A Z +B Z +B Y +C Z +A Y +B X +A Z +B Y +B Z +B Z +B Z +B Z +B Z +A X +C Z +C Y +B Z +C X +A X +B Y +A Y +B Z +C Z +C X +C Y +B Z +B Z +C Z +B Z +B X +A X +A X +C X +B X +A Z +B X +C X +C Y +C Y +B Z +A Y +B Z +C Z +C Y +B Y +B Z +C Y +C Y +A Z +A X +A Y +C Z +A Y +C X +B Z +C Y +B Z +B Z +A Z +B Y +C X +B X +C X +B X +A Z +C X +C X +B Z +B X +C X +A X +C X +B Z +C Y +C X +B Z +A Z +B Y +A Z +B X +B X +A Z +B X +C Z +B Z +C Z +B Z +B X +A Z +C X +C X +C X +C Z +C X +C X +A Z +B Z +C Y +A Y +B X +C X +B Z +B X +C X +C Z +C Z +B Z +B Z +B X +C Y +A X +A X +B Z +B Z +B Z +C Z +B Z +C Z +A Y +A Y +B Y +C X +C Z +B Z +B Z +C X +B Z +B X +A Z +C X +B X +A Y +C Y +B Z +C Y +C Z +C Y +C Z +B Z +A X +C Z +B Z +B Z +A X +C X +C Y +C Y +C Y +C Y +B Z +B Z +B Z +C Z +A X +B Z +C Z +B Z +B X +C Z +B Z +C X +C Z +C X +B X +B Z +C X +A Z +B Z +B Y +C Y +B Z +C Z +C Z +C Z +C Y +B Z +B Z +B X +B Z +C Z +C Y +B X +B Z +C X +C Y +B X +C Y +C X +B Z +A Z +C X +A X +C X +A X +A X +B Z +B Z +A Y +B Z +A Z +C X +A Z +B Z +B Z +A Z +A X +B Z +B X +C X +B Z +C X +B X +A X +C Y +C Z +C Z +B Z +A Z +A Z +B Z +C X +B Y +C X +C Y +A Z +C X +C X +B Z +C Y +C Y +C X +B X +C Z +A X +A Y +B X +B Z +B Y +B X +C Y +C Z +B Z +B X +A X +C X +A X +A Z +B Z +B Y +B X +B Y +C Z +C X +C X +C Y +A Y +C Z +C Z +C Z +B X +C Y +C X +A Z +B X +C Y +C Y +A Z +C Z +C X +C X +A X +C X +B Z +B X +A Z +C X +B Z +B Z +B Z +B Z +A X +A Z +B X +B Z +B X +B Y +B X +B Z +A Y +C X +C Z +A Z +C X +C Y +A X +A Z +B X +B Y +C Y +C X +A X +C Z +C X +B Z +A X +B Z +A Y +A X +C Y +C X +C Y +A X +C Y +C Y +C Y +C Z +A X +A X +B Z +C X +B Z +B Z +B Z +C X +C X +B Z +B X +A X +A Z +A Y +C X +A X +A Z +B Z +B Z +C Y +A X +B Z +C Y +A X +A Z +C Y +A Z +C Z +C Z +C Y +C Z +A X +C Y +A Y +A X +A X +B X +A Z +C X +B X +C Y +C X +B Z +B Z +B Z +B Y +B Y +C Y +A X +B Z +A Z +C X +B X +A Z +C X +C Y +C Y +B Z +B Z +A Z +B Y +B Z +B Z +C X +B Y +B Z +B Z +C X +C Y +C Z +A Z +C Y +A X +C X +B Y +B Z +A Y +A X +B Z +B X +C X +A Z +C X +C Y +B X +C Y +C X +A Y +B Z +B Z +C Z +B Z +C Y +C X +C X +B Y +C Z +C X +C Y +A Z +C Y +A Z +A Y +A X +C Y +B Z +A Z +C X +C X +C X +C X +C X +B Z +A Y +A X +A Z +C Y +A Y +B Z +B Z +C X +A X +A X +C X +C X +C X +B X +A X +B Z +B Z +B X +B Z +A Y +C Z +C Y +B X +B X +B Z +A X +A X +B Z +B Z +C X +A X +C X +A Z +A X +C Z +A Z +C Z +B Z +A X +B Y +C Z +A Z +A Z +C X +A Z +B X +B Y +B Z +C X +B X +C X +B Z +B X +C Y +C X +C X +C Y +B Z +A Z +B X +C X +C Y +A Y +C X +A X +B Z +C Y +C Y +C Y +B Z +C Y +B Z +C X +B Z +B Z +A Y +C X +B X +C Z +B Z +B Z +A X +B Y +A X +B Z +C Z +B Z +C Z +A Z +C X +B Z +C X +B Z +C X +B Z +B Z +C X +B X +B Z +A Z +C X +C Y +B X +C Y +C Y +C X +B Z +C X +C X +A X +B Z +C Y +C Y +B Z +B Z +C Z +C X +C Y +B Z +A X +C Y +C Z +B Z +B X +C Y +A Z +C Z +C X +C Y +C X +C Z +A X +B X +C Y +C X +C Y +C X +C X +C Z +C X +C Z +B Z +C X +C X +A Z +C Z +C X +C X +B Z +C Y +B Z +C Y +C X +A X +C Z +C Z +A Z +B X +C Y +A Z +B Y +C Y +B X +C Y +B Z +B Y +B Z +C Z +B Z +C X +C Z +A Y +B Z +B Z +B Y +B X +B Z +C Z +C X +C Y +A Z +C X +C X +C Z +B X +B Z +C X +A Z +A Z +B Y +C X +C X +A X +C X +C X +A Z +B Z +C X +B Z +C X +C Y +B Z +C X +A X +B Z +C X +C Y +A X +C Z +B Z +B Z +C Y +C X +A Y +C Y +C X +C Y +A Z +B Z +A Y +B Y +C Y +A X +A X +C X +B Z +A Z +A X +B Y +B X +C X +B X +C X +C Z +B Y +C Y +C Z +B Z +B Y +A Z +B X +A Z +C X +A X +A X +B Z +B Z +A Y +C X +B Y +C Z +B Z +C X +A X +C X +C Z +A X +C X +C Z +C Z +C X +A X +A X +C Z +A Y +C Z +B Y +C X +C Z +A X +C Z +B Z +C Z +A Z +B Z +C Z +A Y +A Z +B Y +B X +A Y +C X +C Y +B X +B Z +C Z +B Z +C Z +C Z +A X +A Y +C X +B Z +A X +A Y +C Z +C Y +C Y +B Z +C X +B Z +B Z +A Y +B Z +B Z +B Z +B Z +B Z +B Z +B Z +C X +B X +B Z +A X +A X +C X +A Y +C X +C X +C Y +B Z +B X +C Y +A Y +A Y +C X +A Z +B Z +C X +C Z +C X +A Z +B Z +B Z +B X +B Z +C Y +A Y +C X +C X +A Z +B X +B Z +B Z +B X +C Y +C Y +A X +A Z +B Z +B Z +C X +B Y +A X +A X +C X +C Y +C Y +B Y +C X +C X +C X +A X +B Z +A Z +B X +B Z +B Z +A Z +C X +A X +B Z +B Z +C Y +C Y +B Z +C X +B X +C X +B Y +C Y +C X +C X +B Z +A X +A Z +B Z +A X +C X +A Z +C X +A Y +C Y +C Y +A X +C X +C X +C Z +B X +B Z +A Y +B Z +A Y +A X +C X +B Z +C X +C Z +C X +B Z +B Z +B Z +C Z +B Z +A Z +A Z +C Y +C Z +B X +A Y +A Z +A Z +B X +A Z +C Y +B Z +C X +C Y +B Z +A Z +C X +B Z +C X +A Y +B X +C Z +B Z +C X +A Z +B X +B Z +B Z +A Y +B X +A Z +C X +B Y +B Z +C X +C Z +B X +B Z +C X +A X +A Z +A Z +B Z +B Z +C X +B Z +C Z +B Z +C X +C Y +C Z +B Z +B Z +C X +B Y +A X +B X +A X +B Z +B Z +C X +A Z +A Z +A Z +A X +C X +B Z +A Z +C Y +C Z +A Z +C X +A Y +C Y +C Z +C Z +B Z +A X +A Y +C X +A Y +C X +A X +B Z +C Y +A X +B Z +A X +A Y +C X +A X +C Y +B X +B Z +A Z +B Z +A X +C Y +A Y +A Z +A Z +C Z +B Z +B Y +C Y +C X +B Z +A X +A X +C X +C Y +C X +A X +C Z +C X +B X +C X +A X +C X +B Z +A Z +A Z +C Z +C Z +A Z +A X +C Y +C X +B Z +C Y +C X +A Z +C Z +A Z +A Z +C Z +B Z +C X +A Z +B X +C Y +A Z +A X +A Z +A Z +A Z +A Z +C X +C Y +B X +B Z +A X +C Z +C Z +A Z +C X +C Z +B Z +A Z +C Z +C Y +A X +B Z +A Y +A Z +A Z +C Z +B Z +C Y +C X +A Y +A Y +B X +C Y +C X +B Z +C Z +C X +B Y +C X +C X +C Z +C Z +B Z +C Z +A Z +C Y +B Z +C Z +C Z +A Z +B Z +C Y +C Z +A X +B Z +B Z +A Y +B Z +C X +A Z +B X +B Z +C Z +B X +B Z +B Z +A X +A Y +A Z +B Z +B Z +A Z +A Y +B X +C Y +C Y +C Y +A Y +B Z +B X +A Z +A Z +C Y +C X +A Z +A Z +C Y +A Z +C X +C Z +B X +B Z +A X +C Z +A Z +C Y +B Z +A Z +C X +C X +B Z +C Z +B X +B X +A Z +B X +B X +C Y +A X +C Y +C X +C Y +C X +C Z +B X +B X +C X +A Z +B X +B Z +C Z +C Y +C Y +C X +B Z +C Y +B Z +C Y +C Y +B Z +A Z +A X +C Z +A Z +A X +C Y +B X +C Y +A Y +B Z +A Z +A X +C X +C X +A Y +C Z +C X +A X +C Y +B Z +B X +A Y +B Z +C X +C X +B Z +A X +C X +A Z +C Y +A Z +A Z +A X +C Z +B X +A Y +C Z +A Y +C Y +A X +A Z +A Z +A X +B Z diff --git a/2022/day2.py b/2022/day2.py new file mode 100755 index 0000000..f5fdf5a --- /dev/null +++ b/2022/day2.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 + +def compute_result_one(opp, my_play): + match opp: + case 'A': + match my_play: + case 'X': + result = 3 + case 'Y': + result = 6 + case 'Z': + result = 0 + case 'B': + match my_play: + case 'X': + result = 0 + case 'Y': + result = 3 + case 'Z': + result = 6 + case 'C': + match my_play: + case 'X': + result = 6 + case 'Y': + result = 0 + case 'Z': + result = 3 + return result + + +def compute_result_two(opp, my_play): + match opp: + case 'A': + match my_play: + case 'X': + result = 3 + case 'Y': + result = 4 + case 'Z': + result = 8 + case 'B': + match my_play: + case 'X': + result = 1 + case 'Y': + result = 5 + case 'Z': + result = 9 + case 'C': + match my_play: + case 'X': + result = 2 + case 'Y': + result = 6 + case 'Z': + result = 7 + return result + + +def main(): + me = { + 'X': 1, # Rock + 'Y': 2, # Paper + 'Z': 3 # Scissors + } + + score = 0 + with open('day2', 'r') as file: + lines = file.readlines() + for line in lines: + opp, my_play = line.split() + score += me[my_play] + result = compute_result_one(opp, my_play) + score += result + print(score) + + score = 0 + with open('day2', 'r') as file: + lines = file.readlines() + for line in lines: + opp, my_play = line.split() + result = compute_result_two(opp, my_play) + score += result + print(score) + +if __name__ == '__main__': + main() diff --git a/2022/day3 b/2022/day3 new file mode 100644 index 0000000..5df5015 --- /dev/null +++ b/2022/day3 @@ -0,0 +1,300 @@ +NGvdqJmJvpNbGRMGQgRsfgfn +WlHTHShlLwSWjFRsncfbcwsgQc +BHtSBHWHSCWLZHlhjTHLLdbNNqNpzpDzNvDvtPmmPp +JJSShnTpDSJJlllfwBNVbMQWwhQhgQtt +cTzrvrHdLwwzttQNWB +qrFqTFvqZvrmsplsjlnDflnZ +mhhhVHvNNddHMwBqQwlWZZtv +fbjzjJllCtWjjrZtjq +CbgcgpPRDJfzVHFFnSnsSDlm +ZqBPqBQnPLmqZsFqhsvFsLZQMfSSMbbWddWbjbJSrgWgJf +NRHnlllcDwwCNClNtttHbNJrSJNfbdWMdfbWgdrJ +cHGlzTptHtCpncHnCpHpRGzDmvVhqLmvLPmPvLqPmzsqqmPB +rCzVtMMbMvCmmvGlclFQFfLpJFJfJpcLHPJL +nDGGwqGqnRTfpHLpRFpLFf +ZNdNTDsWgNZsZBndnGrzrlMrjgrmjVGjvC +MgFZHFTgqFFDZZDTdVdHrzQvLzCGwpCPrGLqQpzz +JsnmbjhmffJbRNJppzPPzwzzrwdv +lfblfthBRbBRjnjhBtBlZgdVcFSTVFDtSSWgMcdM +hPVhVhWPCMhlDTTWdrPlTcLjfbZbFNjZBbFNBbdBFbsB +MHSwMJpHnqJHwtqHGqGGmvqZsZFjBmsBNRBFfLbsFsZfsZ +pqtMHHQpvqnwMpgJMCChTQhVVlclPWrCCD +zRBBhZFwWZlBQpMZNNNJsfDpLsNsJppN +SvggPbjvVSvvtgGVPbbnSMcCLtMrDddssJdsLdfdCD +mTSmMgHjgmgGgqzTwZwBlBFzwB +WLzWZHWSZPFRVSPSPM +hmrvmGvfTCmhBGBqTfnmJFfdbQcwdMhMwRdbQMVQQcMhsQ +JGJJnrnnCmqBTJTrNBqBLDzHFLFDNgjZlWtDNZHL +bwbbnWwpbTwFHwRzzzmH +ZccjZjddjPVhJmrBQHHFQRHcWF +NVhWldsMjZZZLSnvSTGTgvMb +ccJbHpzccZJsNpJCmHHlBTgHnlTPmF +qvQGQfDVhhDfvVfVDSdDCbFnjmllPQjlbCmnFgjg +hSbtWRGvhdfDVdVRfvRNpsWsZLNMZzcswLZWMM +vlTdlBTMdtjcvLGmtb +SSgfSsJngCSSwNFgspHFNFFpjlbGjQbbQGLthLnWtmWWhjbm +SJsfqqgfNHwJfHgCpwzBZVMDBPMMRPTlqzBr +VHsVhtbRHRpVHBfBCJdNfGjggGJdqLGq +wSzSrrSMPDSDwzPjdqJjNwGdsLqGjj +MnrnQTnWZWWzWQDMvZhtHtshhHlHBcBBsvVt +DZbPqdTqGTZtRrzjFmZZtF +gjQwVvBVWgfghvgmcrBNFccHFRmHtF +QlgvWlfgVsQfdlqqjqPDbPlM +VcfLwwcMlpnfVDrDtrtvbjMtTM +mmgBgzSQmQdgHBFSLvvbDTJmTDvTJJDr +RWNBHHzWNSdSdzFgSLNWWfZGwfpcwWVnnfpCCWlV +GDZLtsJMFGLDPnbblJlNJNcJ +BBRgSwqwqRZhTVSqjVgRwCdQcmcPmdnPPnPnmjlrbmQj +RCqfVvhfCCShBCRfVCwztDGZMHpLWHftFptspF +dlZqlBfBSShZhvprbCJTDrJCJjJNDh +WGRwQwHsMVVGMsVGcRVtQWRVpNCjWNDbzbDNJnbnrCbprrNW +HgHRRVGGwLgLBPvgSp +QPlZSlZzVLLDwhDfBppf +bghGGhmqrspDcfbsbs +tTrdTgFddtnvmdgvtCTdGTTqFZjjQQPVZPSZSjlZhVVQjlRS +BgBFHnwwSTNHqSPN +GJmCbDdlbZGCLhsstNLsMZZZ +JGJpCCDvmlVDVldGJBVfBBRwRjnVWWBRfN +WTFWQgGQtTMqMCJJzDVDgCchhj +mNPBmPlPHrWmwmNLHmShcnJjhrnzJzdcdzdjJJ +SHssNRSmvPRmlsmLwwsmwLvpQptpQWMQbGFQFtfpFfZQ +DgpNLVjgNjjmzGPVRmfrZrctdTcrzfwzdfMc +bnbNqnbFNwMcMtMfwF +svCQHHhShnbCvHChsvHlLDVhJJLRJGNpgPJPjLLD +TmBzgTVVBgfbmTVfPmFRJcHctnHDLDDLJqqBGB +hwvlNCCvSphMwSvrlwCCrrDcfRlJDLRtGqcqHnqRqLGR +pMSSMMNCSwMjjWhwrrjShQNFmsPmPFWbbZzVfZsPPPZVmZ +sTTrWGCMggpVWhSBltWp +HNJdwLDzNcJnNLwJJPqpllqhBpqStjfwlfpj +PJHzDzFLtLccdLggvrGGmgvFssgG +FwCssBFRBlvbBVdQ +jPzjDpqNGqJzZGSNHppPclFvvdfVflblbJlmFfll +SDzDpSNqjZjjZFSrHrFZTTCMLsnTLnnnMhrLtLnn +ScWQvvSDddGrWVrG +fwhPFLpwTfTjrzwHdmmmGdgdsPsqdRmV +CHlFpTpwwCjwFjwjCBnrvQBZZcBSnZtvZl +vJvdWVNslWtJcDtDHrDf +GCnnMZpZnSZpvDqFtftfjfZqrh +TbGMSRCRvWbPNsWB +NNNdsRddGNdZZTCBtqbtBgtC +zhFHppHhzcgmzQhccjgmjhQTnvvBFtBnCBbbnTvtCCtntt +HpjmhfSjQwfzwHmcggfzjSLfVWPDsWMsMdWdDSMsGWPPllVN +WSvcSSwrGzFsznqPNNWqPqlllB +djVDdHdSPRqlntjN +LpZZgpLgLHTDHVpDSTsffvGwrcfffGwv +wGlbWGVvGlWlrvppbFMjQjsBjCsjmCzzQzNv +ZgfdJcfZhMNCgSBRCQRz +hcLDZPZdqZhJPhcTHJfPHVqlqtFWMrGGrpwVGVpWrV +dsngCgdssHDVsHdsFDvMDvmMmjTjDFTL +qZpSqptZZGWLTLSjlLHFzl +NZqqRpWqhQpNhqhpZRWBJQQssJbbCsdbHsCbgb +QdGBjjbHsBsBbBdGcwwTGrCRRrFcPPTC +ZDtvWfMDvWScSrpzPccCdr +hhZMgffDhZNvtDgHQsQQVQmBVVHNdV +LhQLrzVdVmqcjmTNzm +tHMZDJDZCDDtZMWwCJjcffqqfjRmqSRqcq +CpHpZZWWtWpWwBplZWmQbhVBVPhnPrhbLQPvvs +FFgFSmJmSgGpZzsmgGmbDlDzMQPDNPzRQRDjQQzV +CLwnwWBdrtthttTWBWdPnVvRVVVNMSVQPvVnnV +BTtdLthfhTrLdftCwqrddmGFcSfpGbsmFGHpmGFHHc +JFJnMZwQBqnJJBqZJqPqMFBlbmBHblWbrmlfbWgbvmWrgW +spCTjtVzsNDdsNdTsjVTtNzgHfmWWgHSSrgrbSbbhHbVHS +TfCdjjsjzLNsfTszcdqcQMnRMPPRnFRPQRFP +VvDgDqTDtTNWTWfNFWlW +pzPvdssRNQFQRNZF +CCpBpsrrccGvttgGqBDG +jmZrrjlCJqmCVFMPbFbBZPVp +dfLLfRMGTdHbssPLLPbFwL +QWWHHTRQdRRHRMhzWQfvddngqJqjjNgqqjlgvrtjJmtn +sGGwJdHDDTfWbTcRzbbz +BmjvdhNVlFBZmSZvFrWpfpcBrbzbWcbqpf +SLmSZLhNhMhwtLswPHGssd +mGhlPclTmhhlJRWlRTDPlJtTFMngBcLSBHHBHLHSwncFgLwB +jQVbjprjVfzbZQrzdGnHrrBLgSGwGFLHHg +zzZqjQjdvsRlGqThGJ +GSPQPvVmSwpVQGVlSQmWJRcFBpnFBcBWcJcJDc +rTTCLmhTTbZNqMNbhjfhmDzsFDWzsDnfcBWDDDzcFs +qmjhrhCtbMCZNhZMhNTZbLjvQdHdHGgwgdtQHlllQwlQgv +ggpCCgvjPTJWjBjWWJgCWCdVVHRZdLfZhqLdZRHZrf +GsstmNslzzzGlMnGMnVZRZrLpZqdhZHZrZHM +lNbDsbltmzpsmmmnnccBJTwPgWvvvTwPwFPS +FWbTRTdWGCnThqQVBQqJ +rrDMPrDcSrvtcJdLVhVHQMQVBQ +rNtNwrZtDNPmZStwvcvRlGFRlzCRlpmdpplbpb +gHrHrlFgjCrNDfCMTzwwLN +WhvTvvWnmQvpGWNNLzwWfNzW +vTnRZhnRRBhscBVpcBTvnsjFltPqggqHPHHjHrPcgrFg +VzfWRVsnNzWfsvpQPvvFbdVQpQ +SqCqqhLDTTCTTCDcSdbpPvdPFFvhMbdMvF +BCLBDCDGLlTClCSrglrGzWmrszzmHRJmfJfJpHNz +dwGBHGdwdcCMCBzzZJJssZFsBBgt +NRqbRbQhLQRLrQlTggFWlZtRlTvW +FbNDFDLqnmLmNbqbLQbhLNDpPcVHMSVMwCVHcPnVGccwjdcM +LdHtrrrHrLZrBVbQjtPnnsVb +TwfhhcTCTCpfJJwpTJwhDDPnbGsbFjlQnnQjFBFslsBQDl +pwJCThfRCMMMvhchhwHSmWLZHLNHMdrdZzPg +LbMQbHbHQLLMsWLvszvzvqCfqCCqss +ScWlpmplWrDzlzvznJ +RNNcZWhSZmdVdPwHbQQTTwNwjP +jFFFtHZjwmLNmnQCFL +sVbdsqcqHBHqrQrLPmWqQnmr +sfGJVVzJJsczczfsczBzzvdbTMTptlTZZgDSDtGlplZSlgHt +MgMQJdqqMDQJDggzTMgVplvffmctcCzmfjRlmmmjjR +HrGbGswnBBtRvccBlljB +HZPHRRGGshZHnnnwPnshnVZqMJJDdpQDVgDdVDWDpQ +whwQRQGHRVhWRRcLLJgLmL +jSnnzgBnpCZdCBjNmnNNJmllJTlccT +jPSzrzpzpCjgfZZrZCFpdwQDQVVPttGDtVqQVtHqth +mvnGFmvGhTcSCBcBpv +bwMRzbQLwBQRWSctCcTtLpss +JJgHZqRrbqDnmBjhDh +MVvvGrsbGtVsgTggHjSFHJBBBg +PPNpCpQPZppplttDNwZPBdfTFPPTSBWSFjjSTH +CpNwChQCzDDNZwhZlpwZpqrqsGGsmmctGbbbzcmMms +pjMbgCgdQjCgBjQQCncwcGGLDZvFtGLsZZFZtH +zPhhrVhVVSmqVqhmzPqvDtsLLHrFWFvGFGFsvt +SVPzVTzJNBfjDQbQTb +CRDjjRmmLhjRFFChmHDNLZzsZNnPZNzlnnsvlv +SSqcMwdrctQVtqTwSSgnvZnsZvnBZpcPsvlvbz +trMGSSVdQQqdGMtwwQCmRHHhmJFhsfJGfjHh +phJzrnJJwNNSJhSnwpwGGZzmvNfmmDvfcvcDfvbRPNcvvR +tWtgQBqsqdLFLmZvTRTfDZcb +ttssdgQqsHQtZFsqVdgdgdCBJGSphnljnJhjwrhnpJrrzJHl +srzpVWrWTptbrPpPPtcWpNhNNNdfhhDgDNvfBDNNds +jmnQHmLqlnSlGMjqnLLljRHqdNdgwHZBgfhZvBdNhDwBhhtZ +MjSlnLmMLnCGjlSQLVWCzbrcTpPtpFbFWr +ZnQRczHZsMSRZQcBRSZRscQwJbWFbbQwpWTjdFLJTJTWwd +PVmGqDlGhDPVNvqDmmqtqLbbpJfFJwpbdJpdbfdjwdbl +VGNCgGPgqVqhNvmNCNZnSsRLRsMzzgBRnHrS +ZgMMgJMhjmZrZgggmlTTbfwTfRfbRGwlGTDf +nPqQttNVPzSPnqpGDwDDbGfwbJ +dJvQzzJtdSPWSthhHMjgMvrHghsv +cMvwHCWcMnwWnScWVFzTqHpHFpVBFtFp +bbblgRDhtlGgRPFBRqFpmzVFBTFp +fPbtGJGhfDfDsPhQJDPbbnjjSWnwjdvQCnSSCnCSCM +NcgDtwghTLntgNtLrjfHSSFlSbCfprlL +ZGGMmdmVZVvsRQvMGRVVZCHPfpZSfZbFPlbPjCfH +RVRjvRzMQQJBVmzzgWgzTWTWhNcWzN +gsgBqdsWprWddpBghBpwwJzbLcvhCZmwZCFcJC +PRPtStHfwmJvzPmF +HnSHHRQDVFsVVgsgTWsG +QRQTRrDHSLSNzzZLzZ +dBmPwfwffWtWRtzdhhLzLzLzzLFN +BtWnWCCVBWtCBmRPqVmqmntjjlJHJslJQVsQjsbbHrjHDQ +TwwJrHSMnHGvWHMvvSqrrZbRrRqfqVNfbNRc +GjhstmPFFhlFtmmjQtlgVcZVfcgqqNRNpgRcbP +CzdCdFCtdzGWGJwWWHdW +zfSVfSpHVpCHSZLnsttDnvDvpcsqRc +rWzMGWFFPBFjqjDjFDFs +PbQQWbJPrQwPrrPBwrJCVzZZLZdLSLLmfZfHJd +gPDPLgsLNslNLHqlLqqjhjnwwjJbDjnjwTRnGD +tzdMdMddmcRMdtcFFGWnwWjFwjFhGbTG +mRMmttpVHNCNpNZN +mfCFGfDDFCDWtvvstjjJ +njnVnrggLlwVVqLpvHVpMpMsHVhhMW +QQPPPnjlPPSgwBrnNLcdFCNNGFbmbZFcZzFf +NzNHFNFnFrtgwwPchvGFFS +LsjdQCVsTsLCTTdMCJtQgPPqwhPgqScPGvSZ +jdLdVjJtCVjRCMpmpNfNNWHrNzDrNrHrmr +NmggPPrPbPmdCbcfCNLVRRWpWTWRVTpdVVWspW +qGhDzGqnwGQnJrjllJWttMRDFRtMVsTDTTZs +SrnHhGQlvLmSfbfc +DmdPCJMLlQdSjGCqjcGGccHH +zWtBwfsgvVnBfftWtnnpTmnTRhppHpTqpc +wzFtwZWmsVFzZtvPJSPbMFJFDJJJJd +wrPRRSJSWrTSRzRWrqlfCLlcBfBGDqrL +gVNQjgdVhdfqqhlDCBDs +NmjgbtmNtjNnjbPbvRJPbpwZwZSD +tNHGccGNthtSGmVjjVmrrVPqSB +fgDTwRwDFmLTFlspBBqjjBgqBssB +mLCZwZRMJMbtdWMtvd +TPzHPPgChjsgPdPTjQvZLvnpLQnvlRQn +GScFSzFWWrfGGMrVFMqGqmrBnplmwmnlZZlmnvvvLRnJLLvJ +qVSVFtFtFtSzrTNNDsHhhNTHht +NQqtqmqmNhvvclvhcljJ +CSCfMZSgWMvfWgrbjwcMJwrrrclr +CGSCZgSGZPRTSCWWDgGBRtnFRvqNRsLLzmsLzqpq +tWmtCZjnWZWCGjtnnmtcwFvvlgSDTDTvVwsVgCfT +LpLhpLdqbBMNsQPBQhpLvgFqllgfllvVvwTDTwlw +pNQBBdLbBPpPHLmGsRWjRZJzWZHc +WtjBSvBjWzTtzvDTjBfbbthsMNRNgCMQDgRcCcQwLRgCQgNc +HJmqnHqHpplVnlPdqGrpGQNLCgSwLMwFwFFCgnMLRw +SdJGpHVZmqpVVVdZVJGddsjvzzvZTsZvWTbvszWjWj +FhRhhLZgLZhCRWZBFFWRmGbvSgHqvvbPvHTPccVncb +wzSMpjJdwssdrdDfJJJsJSvpGVPqGpvVqTVqTnccnTvH +rwfMMdtDjNwjzDrjDDdtChRZWSWhmCWBSmLQRW +RWLNLWrhtrhWJmLnSStBBdVtBGVVBt +wQqnzjCFbflqpQlQFTDDGGsGDBZBSZMsDVfG +QvqCTwjjTqwbTqjznFzQvqjFJgmvgghJgPmgmvPNmNRJJNgN +qLqwhztjhqqDDzjZqqjPMmFmCnVDsmgbggggTMDC +WBhWJQrJcRmnFnWMTTCF +lvvJSlGSvBvJQBrcpSfwwLjLPjLfhptjwNtp +sbFjnZpPPGZLZzCRhqbJhJMCqMgS +vtNvFHBcNwNDHffvtfQMSMJVRMBMChVqSMCBJV +cQlvTffDlFWTlcfFTlHQNtzzGGWGdLsGWdrnzspjGdGr +LMQtlzlMQLLrztVfVdfqDdrhrhdd +JPJTHcvPTPTJGPZgbmvGPmcZhwRVdDBdSWfdRHSBfqBSVHqq +sJchPZGccmcbvcmgmPcCnnnnpzppQppspFjQntMl +qtQQtsMDqtPDGQltPHbsLFnMccRNcVLLrVNVwMVM +LCSdzZdBZmvzZTCBfJrwnWppFcWrFpdRnWpR +ThSgBZTLJmPHlgQHjPtq +mrwGPrVrbjbPVmwmbdTwbGfJMDJMgsqhhDjsqjJppfqt +SQnLnWnWHLSFCRnlQRnFhqfsDMJMppqDfcWgpDfD +NCSvLQnRSQFBLBzdgvTbbwPrzbPZ +FFjvvHZbHZnZpvFHZcFbgQVwgwQnJfQPVNQJGqSq +RWmCmdClRtTzVRwVfVQPNQgN +shwhzTsmlbhZDLbBHL +PpPHllshHDTlsprJrsPQpltzjVzjLNggZNznLNLnhNnnjL +qRBvSwqBdRqvmfvCRSSLjcnVcVmLgmnNZjmQVg +vdfbSfBWffMbQqQdtprtslHJsWDGHptt +pqQdFWlQZpGZpLpS +wnjwJhjvVgjwvwvsgwgtsRTtssGTtLrNtrSrHS +VDJVMGCCChjccDJDwgwVJvMBzBfzbzbDPPFBFBbffzbQqq +gBwwBZGhcfhnFjvrQjMhrjQQ +PPLJNdNldlNSRmzLSlpbHQvbvdMtjjbMtMtt +lqDJmlSmlmPzqNmzmVnvnBZDgvBWgcZTfD +HMqrwWqzWJqHzrjgGFNNtQFMFQnFBt +LddPLdVmchPSvmcvTZlvghLLFBDNDtFGDQpRnntnFDQnFPnB +SbSvZTSLSgqbCHJWzr +TGcjzjgtNqjttgNNTTjmGwLhfQQfDnDLDwSQWTSCvh +PHJRJJbBVMPRMJHbJRMPbwCQSSvfCDhVhvvwwvQLnW +ZJPMbHbJJJsdsJplRRRZsPJztrFrqtzGrgmcrprcmFjDgN +tlDpSbpwgbgtpddJppgJwJDtNQWGQlcGQGhlhnGGWcrcWWFr +MTZLqzjfFLqLjRfvqsQhNPGnhGGsnchW +LMCzjzMTTjjFRfZMBTCvRfLRDDbVVpSbSgwwwtSBSSDJgStg +ZLVTrJmJDHFtzSTlpc +wNhhNfhvwwvvfvPnsNPhglszqpcHcFbbFSzSzzCHzb +NWjPwgNgRHGWvhwWPfgfGwjMDQJdQLVLJLQVVLRdBRJrZr +CPRJCFJTqZfJlJRqssHJftCWQMnHHwMbbngMMrQMgMWwQn +BmzVVhvvcvDdWgwVrTnrMb +BjzvhjLLczzBjLchDLmLJtsCqFClTqsZCPtPTCjq +DbWjNCWQCRRNsDPpFGcjjcqFqFfm +PZdMSzSZTtZZqVmpqmmmTpgg +ZvZMzBztzvhvddPMQlNCQDbQLBLrsRRW +WzWFhHpWhvCpPpPLswMHswMMHLbgmH +NNZSZTVQNrTnqDqrrwtwwLstsMGMnbntGm +TBmQcrNqNSQVmrmQBPdpFFzhFlPzzCPF +nBgmSrjgmjtmrbjSFGLWtLVpFVQQVGFL +JlChvCzvqCqWffwFdFVQfPVPHPFGLV +JzvTThZcCCMcMMwJzlbjTjmnRgRTTBnWgbBn +rppjbbDpGnwrGprVCLLJZDzQqZzLNQqc +htflFBFmBBlWTTgsggtZHMQLCCCcHqHMfZczHq +gFdFTWgRhBmWWTFSGQbVnSSPnvndpv +qFSRRGGgTgThTQhcllCWCJCctWWhfJ +bvbdzNDMzHZNNHFHfJWWjljWNNfcnWtn +PdbPdPBHmsdbdbPdBHBdmdmsgrTqsGQRTwSpSFrqrRSFpRwp +pQJZZGQtChQtpWZQTTWhNtVdVWSLBrsLSVrLvrvrLdBd +lMHnzGRgPRMSMBLcvBSS +nglFzflzHRDGgzfzPgHRbTDQthbZbhhppNbbCqhb +jVrvrJjpZfZCCGctwhbhMRcM +BQQnFFTBdBndzssFsdTbRwDGTPGbcMbwtDgbcG +HnLtQQBLtWNrVpqjJvWN +dnVlsnJlMqnlNqJdnMRvDHBRvbBLHLpRSPPPRS +NcGGCthFwcFwmjCTGDSfPSSHSPfPtDHfbD +zNWNZGWNzQnWlJWVJn +tMGSBtRtvjFcGpQrQQQQrp +FffbJTJfPLNbTnJJmlVcQVfpQmlWVVfH +FTdJJdhNvZhMtRSh +pSTfMtMLSTPsPsBszP +jdlmlFHHhVdmVHFNFRnHzHQJsGZBJbbJDvsDRPBsrGrDrJ +VHnFjcdccjlmNVmnzmNVmCMggfqwtLLfSMwWtcWMSg diff --git a/2022/day3.py b/2022/day3.py new file mode 100755 index 0000000..b0d8b48 --- /dev/null +++ b/2022/day3.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +from string import ascii_letters + +priority = {letter:index+1 for index,letter in enumerate(ascii_letters)} + +def main(): + with open('day3', 'r') as file: + lines = file.readlines() + + priorities = 0 + for line in lines: + length_compartments = int(len(line) / 2) + first = line[:length_compartments] + second = line[length_compartments:] + + + for item in first: + if item in second: + priorities += priority[item] + break + print(priorities) + + priorities = 0 + for index, line in enumerate(lines): + mod_index = (index + 1) % 3 + match mod_index: + case 1: + first = line + case 2: + second = line + case 0: + third = line + + for item in first: + if (item in second) and (item in third): + priorities += priority[item] + break + print(priorities) + +if __name__ == '__main__': + main() diff --git a/2022/day4 b/2022/day4 new file mode 100644 index 0000000..76a9d92 --- /dev/null +++ b/2022/day4 @@ -0,0 +1,1000 @@ +17-99,18-24 +14-91,22-91 +63-76,66-83 +17-57,17-28 +77-88,14-78 +15-92,14-15 +23-23,24-40 +14-42,41-42 +23-74,21-24 +6-94,94-94 +16-18,17-52 +50-96,40-96 +4-67,3-66 +26-81,26-99 +18-93,24-93 +13-18,17-61 +7-46,47-92 +46-91,46-98 +1-73,72-73 +51-86,36-52 +16-16,13-16 +5-35,1-36 +14-99,5-15 +2-32,2-92 +45-86,44-45 +10-96,10-97 +2-89,89-95 +9-95,8-97 +40-78,41-50 +48-66,4-49 +21-24,22-49 +43-92,98-98 +91-92,42-92 +3-95,3-98 +8-11,10-99 +65-75,40-64 +55-83,82-82 +34-50,24-35 +20-62,19-62 +43-74,42-46 +28-32,28-32 +38-52,51-51 +5-75,66-75 +32-46,41-55 +97-97,2-98 +13-34,12-13 +33-93,85-99 +7-80,12-79 +98-98,54-99 +37-38,38-79 +20-79,28-82 +1-1,2-66 +7-68,1-30 +35-35,36-52 +3-46,2-46 +21-62,51-63 +30-30,29-42 +7-64,8-64 +4-94,5-93 +35-60,36-60 +75-76,69-76 +6-80,5-95 +23-50,24-50 +25-92,89-92 +34-56,35-35 +65-84,65-69 +47-76,47-96 +1-3,2-98 +10-55,16-55 +5-89,99-99 +8-74,7-74 +13-82,13-82 +1-99,3-98 +11-17,10-29 +81-98,63-98 +61-71,60-97 +6-92,60-91 +7-96,6-96 +18-81,13-82 +46-61,47-91 +22-91,19-91 +23-23,23-95 +20-20,21-96 +4-69,8-70 +5-22,21-59 +74-80,75-81 +95-95,24-93 +15-85,9-86 +6-7,7-93 +11-28,10-12 +15-27,16-62 +12-24,11-33 +21-22,22-65 +31-73,7-30 +2-80,1-81 +1-92,1-90 +4-38,5-19 +1-40,4-94 +49-70,48-48 +3-91,91-91 +32-99,29-33 +11-52,10-70 +16-95,15-17 +18-18,18-26 +83-99,83-84 +11-94,11-12 +27-80,68-80 +17-96,95-96 +2-83,1-91 +58-66,59-65 +45-45,14-54 +2-3,3-92 +47-47,48-85 +39-39,39-77 +30-31,30-63 +10-11,11-43 +6-86,10-85 +45-57,57-58 +1-5,4-97 +1-27,2-53 +7-90,7-90 +3-28,2-3 +77-79,8-78 +45-48,28-47 +13-73,64-74 +14-97,14-83 +50-51,51-94 +21-86,22-22 +11-49,12-49 +30-68,67-68 +48-50,49-81 +24-96,23-24 +27-44,26-28 +9-80,10-74 +44-74,2-44 +66-73,64-78 +8-82,8-82 +3-85,55-93 +22-65,13-64 +10-19,10-26 +79-83,29-79 +48-56,52-60 +25-93,3-93 +1-99,5-97 +60-81,60-81 +15-26,10-24 +50-78,10-51 +32-75,33-75 +11-21,10-93 +1-71,1-98 +29-65,30-35 +52-90,51-52 +56-95,75-94 +8-9,9-98 +2-53,4-52 +7-65,3-13 +73-83,72-83 +9-18,8-76 +14-38,4-37 +22-57,22-78 +2-99,12-98 +2-43,20-44 +13-88,87-95 +5-61,5-63 +14-68,14-52 +9-89,8-99 +43-99,42-43 +10-39,39-39 +45-60,42-45 +39-40,39-89 +44-97,96-96 +10-96,15-99 +50-90,90-94 +40-90,39-89 +39-39,40-66 +15-96,15-96 +48-59,49-58 +19-58,18-19 +21-92,20-91 +1-89,1-2 +13-91,12-14 +70-80,69-94 +28-92,27-28 +5-95,95-95 +21-22,22-74 +2-58,3-7 +35-51,35-36 +88-89,1-89 +84-86,73-85 +22-63,9-58 +44-93,44-45 +54-81,53-54 +5-91,90-92 +12-29,2-25 +4-97,97-97 +1-90,8-89 +17-37,17-37 +10-89,15-90 +18-19,19-19 +24-44,25-75 +21-77,17-77 +1-99,2-97 +12-91,11-91 +50-64,50-64 +51-97,52-97 +7-45,6-6 +61-62,61-82 +5-8,5-13 +13-35,36-94 +91-91,44-93 +2-78,1-1 +51-52,52-80 +52-74,52-80 +58-63,15-62 +9-78,9-9 +19-93,20-93 +7-18,4-17 +27-73,72-98 +17-89,16-88 +20-83,21-61 +55-55,55-96 +43-88,48-87 +52-62,51-93 +5-27,10-26 +3-62,2-93 +3-95,4-87 +30-96,62-97 +25-26,46-97 +44-82,43-88 +9-30,11-97 +31-32,31-77 +25-26,25-77 +18-55,17-19 +14-91,15-92 +7-76,8-76 +62-63,63-66 +26-99,7-47 +5-79,4-4 +2-97,3-97 +85-86,35-85 +6-90,21-90 +44-90,90-90 +32-89,33-84 +28-88,31-87 +27-45,28-43 +26-52,47-63 +14-53,24-82 +26-76,26-70 +7-90,9-91 +69-69,11-69 +10-82,10-47 +39-68,40-40 +10-94,10-10 +28-78,27-82 +7-95,96-96 +68-83,68-83 +28-51,50-50 +98-99,2-99 +7-65,6-6 +52-54,53-80 +13-78,13-70 +96-96,28-96 +59-60,20-60 +44-78,36-44 +13-15,14-68 +38-71,71-72 +6-92,6-98 +42-77,43-58 +31-61,25-60 +3-97,12-98 +3-36,2-3 +29-69,32-96 +17-69,17-89 +4-96,4-96 +79-99,72-97 +1-99,98-99 +22-95,21-22 +2-97,2-3 +5-96,4-97 +23-24,24-53 +6-96,96-98 +75-76,4-76 +4-67,7-66 +53-91,52-98 +37-37,38-99 +36-94,37-95 +21-79,20-22 +42-82,41-42 +28-54,41-59 +57-97,57-57 +47-93,48-93 +28-96,29-92 +15-73,72-73 +89-90,90-99 +47-49,34-48 +80-82,81-84 +60-80,59-80 +11-12,12-77 +36-96,11-37 +16-95,4-95 +2-98,1-1 +51-86,24-52 +89-94,2-90 +8-9,8-90 +2-98,2-3 +4-4,4-5 +5-98,4-5 +67-81,41-81 +1-84,84-84 +7-95,12-95 +5-5,5-86 +1-84,30-99 +58-88,44-71 +50-98,50-98 +18-61,31-74 +47-48,47-69 +2-41,1-41 +65-98,65-98 +28-62,59-62 +3-38,1-4 +34-43,41-44 +26-91,25-25 +17-57,21-57 +20-21,21-86 +20-82,42-81 +1-61,4-70 +49-91,26-73 +5-78,78-78 +27-98,28-98 +55-59,54-61 +3-94,1-3 +6-40,39-99 +16-75,17-54 +1-96,2-97 +7-7,8-96 +11-98,11-98 +96-98,95-97 +5-85,2-85 +1-98,1-1 +6-11,7-35 +5-54,3-68 +19-96,20-96 +49-85,56-85 +33-58,57-57 +66-79,67-80 +9-99,8-10 +10-86,46-86 +5-14,13-86 +42-96,19-69 +2-83,11-83 +9-29,9-93 +9-80,8-38 +28-28,29-82 +5-73,5-48 +23-54,23-54 +17-96,6-74 +49-76,48-77 +36-59,37-48 +12-96,11-97 +81-98,82-99 +41-41,42-50 +9-9,10-15 +87-91,11-91 +54-63,55-64 +45-46,45-70 +72-82,68-91 +6-94,93-94 +18-64,19-64 +46-64,34-48 +7-62,61-63 +2-95,3-95 +45-45,46-55 +57-65,56-94 +33-95,94-98 +22-88,22-28 +68-89,69-90 +10-24,11-15 +32-98,26-55 +5-83,83-83 +13-79,11-14 +44-46,45-81 +2-94,1-1 +54-64,52-64 +12-21,21-96 +38-39,7-39 +73-96,60-76 +69-94,2-70 +1-5,3-3 +36-79,28-46 +1-8,2-56 +30-31,5-30 +8-89,15-90 +7-93,30-96 +85-87,63-86 +10-10,11-77 +2-5,2-97 +16-96,17-79 +52-68,52-55 +15-91,14-38 +1-62,2-62 +63-98,62-64 +8-76,30-76 +1-3,2-93 +22-92,7-91 +11-44,12-57 +3-4,3-46 +9-9,10-86 +43-58,43-50 +13-67,64-68 +2-3,3-77 +12-97,35-99 +1-99,4-99 +29-56,15-56 +52-98,53-84 +24-80,9-59 +10-10,1-11 +12-49,19-79 +10-15,11-84 +17-71,14-18 +42-89,41-45 +3-97,97-98 +42-42,43-83 +9-74,32-74 +20-21,21-89 +55-55,54-54 +67-78,41-68 +21-22,22-93 +11-66,11-87 +11-11,11-93 +94-94,18-95 +1-99,13-99 +57-89,6-57 +18-19,18-25 +6-15,6-39 +17-96,3-95 +10-77,9-11 +34-94,33-34 +26-60,45-60 +25-25,12-98 +77-78,63-78 +29-29,29-70 +94-99,36-95 +91-91,2-92 +3-25,4-6 +78-88,79-85 +60-80,59-80 +64-93,60-89 +63-78,47-75 +36-85,84-98 +90-90,47-90 +2-39,5-39 +6-90,24-91 +12-96,21-97 +57-98,56-58 +27-76,76-76 +24-80,24-25 +50-90,89-98 +90-99,90-97 +17-44,44-45 +4-77,1-77 +46-90,47-86 +10-86,10-86 +24-80,23-80 +24-24,24-96 +20-22,20-24 +2-77,5-77 +47-61,46-46 +65-67,66-75 +8-18,7-18 +18-19,18-95 +50-85,50-85 +63-82,62-82 +2-62,47-77 +22-38,23-92 +64-90,64-74 +62-77,63-65 +14-15,15-84 +30-51,31-75 +25-38,30-39 +1-84,2-75 +38-81,39-80 +30-83,5-83 +11-91,21-90 +30-90,31-90 +25-93,92-98 +87-93,69-88 +14-51,12-60 +32-32,31-31 +33-89,50-90 +2-96,1-96 +96-99,12-97 +43-44,3-42 +2-94,3-94 +7-10,9-90 +59-65,38-65 +6-17,5-13 +37-83,38-47 +57-72,9-72 +3-4,4-42 +1-93,2-83 +34-63,11-62 +1-92,7-92 +39-39,39-63 +13-98,14-91 +96-96,2-96 +3-94,2-2 +97-97,17-98 +3-94,3-99 +18-95,17-19 +44-54,41-52 +24-29,25-69 +4-8,7-59 +16-93,8-93 +23-53,53-54 +74-98,73-73 +96-99,50-96 +33-99,33-86 +19-34,9-35 +12-30,15-47 +3-85,34-86 +11-23,13-35 +28-45,21-46 +2-99,2-50 +7-83,81-81 +39-65,40-95 +3-69,5-68 +1-94,3-93 +2-89,1-2 +1-58,3-82 +3-88,1-56 +4-21,20-39 +59-64,44-64 +49-81,81-81 +11-97,11-12 +84-84,19-85 +45-46,35-46 +4-20,3-54 +45-95,44-95 +40-40,14-41 +7-61,8-61 +41-86,85-86 +46-46,42-47 +75-75,76-76 +6-99,7-94 +57-94,58-95 +3-83,1-84 +35-35,36-58 +22-63,21-64 +85-85,86-94 +3-50,2-20 +12-78,78-91 +2-95,6-96 +18-62,26-61 +13-90,13-92 +1-17,17-67 +16-18,17-57 +32-85,32-97 +87-89,85-89 +41-62,40-63 +3-68,67-87 +26-93,21-92 +24-78,14-78 +3-51,4-51 +5-27,14-26 +26-74,25-88 +47-89,48-88 +27-97,88-96 +6-6,6-60 +24-37,23-60 +41-84,83-85 +78-80,22-79 +92-93,37-92 +18-79,17-79 +22-72,71-91 +28-39,33-35 +45-90,7-90 +4-98,90-99 +27-99,26-35 +1-99,2-2 +62-66,63-97 +65-94,93-93 +68-79,68-93 +70-70,50-71 +74-90,73-95 +7-96,73-97 +1-34,33-34 +16-93,15-15 +55-59,56-62 +2-24,4-24 +43-44,44-74 +18-97,96-97 +4-45,3-3 +13-99,98-98 +7-32,31-38 +41-44,42-49 +28-96,27-59 +5-53,5-37 +68-86,67-96 +34-63,26-64 +97-98,3-97 +30-74,31-85 +9-93,10-98 +66-93,65-76 +30-78,13-78 +29-48,33-48 +8-8,8-99 +10-78,16-78 +30-51,30-30 +19-48,19-19 +10-53,9-54 +3-91,4-91 +42-47,45-56 +47-87,46-65 +8-17,16-78 +34-75,50-74 +98-99,27-98 +16-40,29-41 +22-25,24-84 +9-83,15-84 +75-76,32-75 +11-11,12-99 +14-98,14-15 +66-66,27-66 +8-21,7-20 +4-88,34-89 +38-88,37-77 +80-81,42-81 +4-31,8-95 +8-10,9-89 +55-95,55-73 +29-87,87-88 +2-2,2-99 +28-92,96-98 +9-17,9-42 +48-95,49-94 +4-27,3-91 +43-68,42-72 +76-94,75-87 +8-9,9-96 +15-15,16-79 +15-68,14-36 +11-64,3-62 +8-78,44-77 +49-60,50-64 +15-87,16-79 +86-87,62-87 +24-60,59-60 +1-99,1-99 +26-82,26-82 +2-95,1-97 +6-92,6-93 +16-59,15-58 +7-87,87-87 +87-97,22-88 +45-46,46-46 +10-90,61-90 +16-68,4-68 +17-18,7-18 +36-90,89-89 +38-52,38-78 +13-92,13-92 +34-34,34-38 +50-51,49-82 +7-98,5-20 +5-72,61-82 +48-49,48-97 +23-54,24-80 +19-95,20-67 +13-64,64-64 +49-92,91-92 +74-84,73-83 +18-35,34-59 +61-91,10-91 +70-89,89-89 +1-47,1-2 +21-68,19-22 +38-76,38-96 +29-79,78-79 +29-88,30-73 +35-88,34-58 +21-21,22-68 +35-63,2-64 +13-56,11-11 +12-96,11-96 +6-14,9-59 +3-61,47-84 +14-33,14-15 +62-69,62-92 +33-59,32-59 +3-90,24-89 +37-98,42-99 +5-66,7-67 +28-46,12-29 +31-73,72-73 +15-75,15-96 +12-17,14-16 +92-93,8-93 +7-79,5-45 +21-32,22-29 +23-26,22-95 +2-80,4-80 +11-95,77-95 +69-98,60-96 +67-84,67-73 +81-91,91-92 +38-86,37-85 +11-11,9-30 +1-28,2-52 +20-72,20-72 +4-57,3-98 +37-40,36-40 +24-81,23-23 +20-90,3-89 +43-45,1-44 +2-77,6-77 +11-99,98-98 +63-90,62-85 +3-95,2-98 +18-21,22-43 +20-77,21-77 +53-81,45-84 +79-87,82-87 +1-87,62-90 +34-73,35-84 +56-86,17-86 +13-88,14-84 +17-83,17-82 +24-98,24-59 +8-99,9-27 +72-88,88-88 +9-93,9-82 +59-69,63-91 +20-26,20-25 +1-89,90-92 +59-97,42-81 +41-79,40-42 +28-76,28-77 +33-84,31-83 +42-74,42-75 +22-98,23-96 +17-30,16-62 +28-33,29-83 +3-97,98-98 +7-38,5-38 +61-69,35-68 +77-77,4-78 +40-44,36-46 +35-86,34-35 +57-93,56-72 +37-86,5-86 +24-76,23-76 +1-13,13-14 +69-97,6-97 +6-7,7-37 +1-24,2-6 +36-99,7-97 +10-25,24-97 +32-90,90-91 +2-99,2-94 +14-92,6-91 +24-45,23-57 +32-55,42-47 +46-85,46-47 +4-76,3-19 +80-80,80-95 +69-70,68-70 +7-96,1-81 +68-99,49-96 +22-98,23-27 +64-96,65-97 +24-51,23-50 +32-33,33-84 +20-98,19-98 +17-19,18-92 +2-98,2-98 +26-73,22-85 +36-89,23-87 +65-86,86-97 +17-76,16-91 +25-48,25-37 +42-92,38-92 +3-90,3-56 +91-98,85-92 +38-54,39-54 +7-97,7-99 +31-95,31-32 +27-94,26-28 +57-85,23-84 +52-54,53-87 +45-62,61-62 +16-17,16-75 +14-97,15-98 +1-83,82-82 +1-93,26-93 +12-97,10-96 +87-87,1-88 +29-92,30-93 +21-23,22-90 +7-78,11-79 +7-97,12-95 +8-96,7-98 +11-79,24-80 +20-35,7-31 +39-46,39-39 +38-89,39-89 +33-60,7-63 +3-59,2-2 +21-34,21-88 +1-78,2-77 +61-71,53-71 +21-53,22-53 +47-97,46-97 +47-48,47-69 +79-82,72-81 +94-96,1-95 +28-29,28-62 +51-98,51-59 +9-58,58-84 +11-74,32-74 +80-80,13-79 +12-98,12-94 +47-96,48-97 +50-97,96-99 +65-66,44-88 +38-71,70-99 +22-65,22-23 +12-56,49-55 +10-10,10-58 +30-43,39-62 +61-94,3-62 +60-87,12-60 +12-96,12-98 +1-29,13-32 +7-8,7-73 +27-74,27-74 +66-74,65-75 +53-73,72-73 +2-3,3-98 +9-18,39-46 +1-59,3-98 +9-39,8-97 +54-54,39-55 +23-73,41-91 +48-89,48-91 +17-40,7-41 +77-89,51-78 +22-80,21-80 +9-57,19-69 +28-61,29-60 +98-98,17-99 +11-83,11-83 +32-60,39-61 +11-62,11-12 +31-94,25-85 +2-13,1-7 +8-95,7-7 +62-70,91-94 +38-98,38-98 +33-94,33-78 +6-70,29-71 +14-95,2-61 +25-25,25-44 +44-70,36-52 +19-19,20-27 +20-75,5-76 +2-94,93-93 +37-40,38-40 +2-97,2-2 +57-78,56-84 +40-88,10-59 +91-96,30-91 +1-1,2-63 +21-83,20-20 +49-91,48-92 +45-58,5-51 +21-21,22-90 +95-97,7-96 +1-2,1-45 +31-70,32-70 +35-36,1-35 +12-95,12-86 +63-97,63-97 +11-34,10-27 +21-81,20-21 +80-83,74-79 +5-99,98-98 +27-38,26-87 +18-43,19-42 +3-91,2-7 +12-77,12-96 +67-76,51-75 +78-82,7-78 +47-95,46-95 +12-84,13-45 +35-65,35-75 +71-71,13-72 +2-99,98-98 +6-82,5-7 +49-50,50-52 +3-98,1-98 +61-61,22-61 +27-42,29-41 +5-21,20-80 +51-82,50-50 +2-11,4-10 +10-83,10-98 +33-33,2-33 +1-2,1-97 +17-96,3-95 +45-77,46-59 +18-58,17-18 +41-94,93-94 +2-97,95-99 +67-82,64-82 +1-94,1-94 +5-23,2-24 +16-20,6-20 +3-6,5-93 +21-35,20-45 +4-94,59-98 +53-86,40-54 +6-8,7-95 +1-97,1-1 +26-46,36-47 +82-82,52-82 +21-38,22-34 +88-94,20-94 +96-97,1-96 +36-48,35-48 +65-65,66-90 +2-97,1-2 +80-97,80-92 +74-87,68-81 +69-82,70-79 +87-96,4-95 +91-91,33-90 +17-73,73-74 +22-22,21-98 +44-63,45-64 +37-55,51-61 +51-56,56-56 +29-83,28-84 +69-70,69-97 +22-24,23-30 +7-7,8-90 +8-32,3-31 +79-79,79-91 +4-98,5-80 +1-99,2-70 +11-52,12-12 +35-88,36-88 +31-92,30-93 +8-34,33-82 +3-97,99-99 +5-86,54-70 +5-98,3-99 +4-93,1-4 +15-92,14-91 +9-94,13-94 +2-98,2-30 +9-95,29-95 +59-94,60-95 +36-95,81-98 +17-95,18-96 +3-26,25-84 +32-99,13-75 +9-44,8-97 +3-96,96-99 +21-21,20-59 +14-56,28-55 +19-35,35-84 +82-83,56-83 +89-89,78-89 +24-64,23-57 +71-71,39-72 +84-91,90-94 +18-98,19-98 +12-70,13-71 +75-95,94-95 +72-79,72-77 +11-90,10-94 +2-98,2-98 +4-86,3-87 +6-97,2-97 +68-97,45-97 +91-92,12-92 +32-59,32-98 +11-91,12-85 +28-84,74-85 +8-99,2-99 +2-69,3-9 +72-97,58-91 +4-33,3-33 +12-63,11-64 +56-56,57-70 +56-62,51-59 +17-70,18-62 +1-94,1-99 +1-78,1-1 +3-97,2-2 diff --git a/2022/day4.py b/2022/day4.py new file mode 100755 index 0000000..ec9f21a --- /dev/null +++ b/2022/day4.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +def part_one(lines): + pairs = 0 + for line in lines: + first, second = line.split(',') + one, two = first.split('-') + three, four = second.split('-') + one = int(one) + two = int(two) + three = int(three) + four = int(four) + + first_section_ids = [] + for index in range(one, two+1): + index_space = str(index) + ' ' + first_section_ids.append(index_space) + + first_ids = ''.join(first_section_ids) + + second_section_ids = [] + for index in range(three, four+1): + index_space = str(index) + ' ' + second_section_ids.append(index_space) + + second_ids = ''.join(second_section_ids) + + if len(first_ids) == 2 and not (one in range(three, four)): + continue + if len(second_ids) == 2 and not (three in range(one, two)): + continue + + if (first_ids in second_ids) or (second_ids in first_ids): + pairs += 1 + + print(pairs) + + +def part_two(lines): + pairs = 0 + for line in lines: + first, second = line.split(',') + one, two = first.split('-') + three, four = second.split('-') + one = int(one) + two = int(two) + three = int(three) + four = int(four) + + first_section_ids = [] + for index in range(one, two+1): + index_space = str(index) + ' ' + first_section_ids.append(index_space) + + second_section_ids = [] + for index in range(three, four+1): + index_space = str(index) + ' ' + second_section_ids.append(index_space) + + for ids in first_section_ids: + if ids in second_section_ids: + pairs += 1 + break + + print(pairs) + + +def main(): + with open('day4', 'r') as file: + lines = file.readlines() + + part_one(lines) + part_two(lines) + + +if __name__ == '__main__': + main() diff --git a/2022/day5 b/2022/day5 new file mode 100644 index 0000000..43b4c37 --- /dev/null +++ b/2022/day5 @@ -0,0 +1,512 @@ + [J] [Z] [G] + [Z] [T] [S] [P] [R] +[R] [Q] [V] [B] [G] [J] +[W] [W] [N] [L] [V] [W] [C] +[F] [Q] [T] [G] [C] [T] [T] [W] +[H] [D] [W] [W] [H] [T] [R] [M] [B] +[T] [G] [T] [R] [B] [P] [B] [G] [G] +[S] [S] [B] [D] [F] [L] [Z] [N] [L] + 1 2 3 4 5 6 7 8 9 + +move 4 from 2 to 1 +move 1 from 6 to 9 +move 6 from 4 to 7 +move 1 from 2 to 5 +move 3 from 6 to 3 +move 4 from 3 to 9 +move 2 from 1 to 3 +move 6 from 7 to 5 +move 5 from 7 to 6 +move 6 from 8 to 7 +move 6 from 7 to 6 +move 1 from 8 to 3 +move 15 from 6 to 4 +move 7 from 5 to 6 +move 1 from 7 to 2 +move 2 from 5 to 3 +move 5 from 9 to 8 +move 5 from 5 to 6 +move 1 from 7 to 4 +move 5 from 6 to 5 +move 3 from 3 to 8 +move 4 from 5 to 8 +move 1 from 2 to 8 +move 7 from 1 to 2 +move 2 from 6 to 2 +move 2 from 5 to 8 +move 1 from 1 to 8 +move 8 from 2 to 6 +move 3 from 3 to 4 +move 4 from 9 to 3 +move 5 from 3 to 6 +move 5 from 6 to 8 +move 3 from 4 to 8 +move 13 from 6 to 5 +move 14 from 4 to 8 +move 1 from 2 to 6 +move 1 from 4 to 2 +move 12 from 5 to 4 +move 30 from 8 to 6 +move 1 from 8 to 9 +move 1 from 9 to 4 +move 15 from 4 to 5 +move 1 from 2 to 9 +move 1 from 4 to 2 +move 1 from 2 to 1 +move 1 from 9 to 3 +move 8 from 5 to 7 +move 2 from 5 to 6 +move 7 from 8 to 1 +move 1 from 3 to 4 +move 1 from 7 to 3 +move 1 from 4 to 6 +move 26 from 6 to 7 +move 1 from 3 to 7 +move 3 from 7 to 2 +move 1 from 1 to 9 +move 16 from 7 to 5 +move 2 from 7 to 4 +move 12 from 7 to 6 +move 1 from 1 to 9 +move 4 from 6 to 1 +move 7 from 1 to 5 +move 2 from 1 to 8 +move 1 from 7 to 2 +move 1 from 1 to 4 +move 2 from 4 to 5 +move 1 from 9 to 4 +move 3 from 6 to 9 +move 8 from 6 to 5 +move 5 from 5 to 9 +move 19 from 5 to 8 +move 1 from 9 to 8 +move 3 from 8 to 7 +move 1 from 7 to 3 +move 8 from 5 to 2 +move 2 from 4 to 2 +move 4 from 9 to 8 +move 1 from 2 to 3 +move 2 from 3 to 2 +move 4 from 9 to 5 +move 8 from 8 to 4 +move 9 from 8 to 5 +move 5 from 8 to 4 +move 5 from 5 to 7 +move 12 from 2 to 3 +move 2 from 2 to 8 +move 1 from 8 to 6 +move 1 from 8 to 7 +move 10 from 4 to 3 +move 1 from 2 to 9 +move 13 from 5 to 3 +move 1 from 7 to 5 +move 27 from 3 to 4 +move 1 from 8 to 7 +move 3 from 5 to 2 +move 6 from 6 to 3 +move 2 from 4 to 1 +move 27 from 4 to 2 +move 2 from 7 to 8 +move 23 from 2 to 4 +move 2 from 1 to 4 +move 2 from 7 to 2 +move 4 from 2 to 9 +move 10 from 3 to 4 +move 1 from 3 to 5 +move 1 from 5 to 1 +move 5 from 2 to 5 +move 30 from 4 to 2 +move 1 from 8 to 9 +move 1 from 8 to 1 +move 27 from 2 to 3 +move 2 from 4 to 2 +move 1 from 9 to 4 +move 2 from 1 to 3 +move 8 from 3 to 7 +move 19 from 3 to 1 +move 1 from 4 to 7 +move 5 from 9 to 1 +move 4 from 2 to 9 +move 4 from 3 to 4 +move 1 from 3 to 5 +move 1 from 2 to 7 +move 1 from 9 to 3 +move 1 from 9 to 1 +move 5 from 5 to 4 +move 5 from 7 to 3 +move 1 from 5 to 6 +move 23 from 1 to 6 +move 1 from 9 to 2 +move 1 from 2 to 5 +move 24 from 6 to 9 +move 6 from 4 to 7 +move 4 from 4 to 8 +move 1 from 4 to 9 +move 4 from 7 to 4 +move 4 from 3 to 4 +move 4 from 9 to 8 +move 6 from 7 to 9 +move 4 from 7 to 6 +move 1 from 1 to 4 +move 2 from 6 to 4 +move 1 from 6 to 2 +move 1 from 1 to 8 +move 1 from 7 to 3 +move 1 from 6 to 9 +move 13 from 4 to 2 +move 3 from 3 to 2 +move 15 from 9 to 8 +move 1 from 5 to 9 +move 5 from 9 to 1 +move 4 from 1 to 7 +move 4 from 7 to 3 +move 8 from 2 to 7 +move 9 from 8 to 2 +move 1 from 1 to 2 +move 7 from 9 to 2 +move 4 from 3 to 1 +move 4 from 1 to 4 +move 2 from 9 to 1 +move 20 from 2 to 8 +move 3 from 4 to 8 +move 1 from 2 to 3 +move 4 from 2 to 7 +move 1 from 3 to 4 +move 1 from 9 to 3 +move 1 from 4 to 7 +move 1 from 2 to 5 +move 1 from 4 to 3 +move 2 from 1 to 6 +move 1 from 5 to 6 +move 1 from 7 to 1 +move 12 from 7 to 2 +move 12 from 2 to 6 +move 9 from 6 to 2 +move 1 from 6 to 8 +move 1 from 3 to 9 +move 8 from 2 to 4 +move 1 from 9 to 6 +move 1 from 4 to 6 +move 4 from 4 to 9 +move 1 from 4 to 9 +move 1 from 1 to 5 +move 2 from 6 to 3 +move 1 from 5 to 4 +move 1 from 2 to 8 +move 10 from 8 to 6 +move 10 from 8 to 3 +move 1 from 3 to 4 +move 8 from 8 to 1 +move 3 from 9 to 8 +move 2 from 9 to 1 +move 11 from 6 to 7 +move 1 from 1 to 7 +move 8 from 1 to 4 +move 3 from 6 to 7 +move 1 from 1 to 4 +move 14 from 8 to 6 +move 1 from 8 to 7 +move 1 from 6 to 8 +move 6 from 4 to 1 +move 1 from 8 to 5 +move 4 from 1 to 8 +move 2 from 7 to 1 +move 1 from 6 to 7 +move 5 from 4 to 2 +move 2 from 4 to 3 +move 4 from 2 to 8 +move 15 from 7 to 3 +move 3 from 3 to 6 +move 1 from 5 to 2 +move 21 from 3 to 6 +move 2 from 8 to 7 +move 1 from 7 to 8 +move 32 from 6 to 9 +move 1 from 7 to 8 +move 5 from 8 to 4 +move 2 from 8 to 7 +move 14 from 9 to 8 +move 14 from 8 to 1 +move 2 from 6 to 1 +move 2 from 7 to 4 +move 1 from 9 to 3 +move 17 from 9 to 5 +move 6 from 1 to 8 +move 4 from 4 to 6 +move 2 from 2 to 5 +move 2 from 8 to 2 +move 1 from 6 to 7 +move 2 from 2 to 6 +move 4 from 3 to 2 +move 7 from 6 to 3 +move 6 from 5 to 7 +move 1 from 8 to 9 +move 1 from 6 to 7 +move 4 from 8 to 6 +move 1 from 9 to 3 +move 4 from 1 to 4 +move 12 from 5 to 9 +move 7 from 7 to 8 +move 3 from 4 to 2 +move 8 from 9 to 4 +move 2 from 6 to 2 +move 1 from 7 to 4 +move 2 from 6 to 9 +move 1 from 5 to 3 +move 1 from 8 to 1 +move 2 from 8 to 7 +move 2 from 2 to 9 +move 7 from 2 to 3 +move 8 from 4 to 1 +move 2 from 8 to 4 +move 4 from 9 to 7 +move 2 from 9 to 5 +move 16 from 1 to 3 +move 3 from 7 to 4 +move 1 from 7 to 6 +move 1 from 6 to 2 +move 2 from 5 to 3 +move 10 from 4 to 2 +move 2 from 8 to 7 +move 19 from 3 to 8 +move 17 from 3 to 9 +move 3 from 1 to 7 +move 17 from 9 to 2 +move 1 from 7 to 5 +move 1 from 7 to 5 +move 2 from 5 to 7 +move 2 from 9 to 2 +move 6 from 7 to 6 +move 3 from 6 to 7 +move 1 from 8 to 9 +move 1 from 9 to 3 +move 4 from 2 to 5 +move 17 from 2 to 3 +move 3 from 7 to 5 +move 1 from 5 to 3 +move 7 from 2 to 3 +move 2 from 2 to 4 +move 1 from 7 to 1 +move 1 from 1 to 5 +move 2 from 5 to 3 +move 1 from 4 to 5 +move 1 from 4 to 3 +move 14 from 3 to 5 +move 17 from 8 to 7 +move 2 from 6 to 2 +move 12 from 3 to 5 +move 15 from 5 to 9 +move 7 from 7 to 3 +move 7 from 7 to 6 +move 1 from 2 to 3 +move 11 from 9 to 6 +move 13 from 5 to 7 +move 10 from 6 to 8 +move 6 from 8 to 3 +move 2 from 5 to 8 +move 1 from 2 to 9 +move 10 from 7 to 6 +move 9 from 6 to 8 +move 1 from 5 to 1 +move 10 from 6 to 4 +move 8 from 4 to 5 +move 1 from 1 to 2 +move 3 from 9 to 1 +move 10 from 3 to 7 +move 1 from 4 to 7 +move 12 from 7 to 9 +move 7 from 3 to 5 +move 13 from 8 to 7 +move 3 from 9 to 5 +move 5 from 5 to 6 +move 3 from 1 to 9 +move 5 from 9 to 6 +move 10 from 6 to 4 +move 15 from 7 to 5 +move 3 from 9 to 4 +move 1 from 4 to 3 +move 3 from 8 to 9 +move 6 from 9 to 6 +move 2 from 5 to 1 +move 1 from 2 to 7 +move 12 from 5 to 8 +move 3 from 9 to 5 +move 11 from 5 to 6 +move 1 from 1 to 2 +move 1 from 2 to 8 +move 3 from 7 to 8 +move 10 from 8 to 3 +move 1 from 1 to 7 +move 10 from 4 to 9 +move 1 from 7 to 8 +move 5 from 5 to 3 +move 15 from 6 to 5 +move 8 from 3 to 9 +move 3 from 4 to 5 +move 1 from 7 to 8 +move 8 from 8 to 9 +move 1 from 6 to 5 +move 5 from 3 to 2 +move 5 from 2 to 3 +move 5 from 9 to 8 +move 1 from 6 to 8 +move 2 from 5 to 1 +move 4 from 3 to 2 +move 16 from 5 to 6 +move 3 from 5 to 9 +move 4 from 8 to 5 +move 8 from 6 to 4 +move 4 from 2 to 3 +move 1 from 1 to 4 +move 6 from 3 to 6 +move 24 from 9 to 2 +move 1 from 1 to 9 +move 1 from 9 to 4 +move 2 from 4 to 5 +move 1 from 3 to 2 +move 10 from 6 to 8 +move 22 from 2 to 6 +move 1 from 2 to 7 +move 1 from 7 to 5 +move 10 from 8 to 9 +move 7 from 9 to 3 +move 6 from 4 to 8 +move 3 from 9 to 2 +move 5 from 8 to 3 +move 1 from 4 to 1 +move 1 from 8 to 3 +move 3 from 6 to 2 +move 5 from 5 to 1 +move 1 from 5 to 3 +move 5 from 6 to 3 +move 1 from 2 to 7 +move 16 from 3 to 2 +move 1 from 8 to 1 +move 1 from 4 to 7 +move 1 from 5 to 3 +move 6 from 6 to 4 +move 14 from 2 to 8 +move 3 from 3 to 5 +move 2 from 3 to 6 +move 3 from 5 to 6 +move 4 from 6 to 4 +move 3 from 4 to 8 +move 7 from 2 to 9 +move 2 from 2 to 1 +move 9 from 8 to 4 +move 7 from 1 to 7 +move 8 from 7 to 5 +move 2 from 8 to 4 +move 3 from 9 to 6 +move 4 from 4 to 6 +move 1 from 7 to 3 +move 4 from 8 to 2 +move 2 from 9 to 8 +move 9 from 6 to 7 +move 1 from 9 to 8 +move 1 from 1 to 5 +move 3 from 4 to 5 +move 1 from 3 to 2 +move 5 from 8 to 2 +move 9 from 2 to 7 +move 1 from 6 to 7 +move 1 from 6 to 2 +move 9 from 7 to 4 +move 2 from 5 to 9 +move 10 from 4 to 6 +move 1 from 8 to 6 +move 5 from 4 to 3 +move 5 from 4 to 9 +move 5 from 9 to 5 +move 1 from 1 to 7 +move 4 from 7 to 8 +move 8 from 5 to 3 +move 3 from 3 to 8 +move 6 from 7 to 6 +move 3 from 3 to 1 +move 5 from 3 to 7 +move 1 from 9 to 6 +move 2 from 7 to 6 +move 1 from 9 to 3 +move 4 from 6 to 9 +move 2 from 2 to 6 +move 1 from 7 to 3 +move 6 from 5 to 4 +move 7 from 6 to 9 +move 6 from 6 to 8 +move 2 from 1 to 2 +move 1 from 5 to 1 +move 5 from 8 to 5 +move 1 from 3 to 9 +move 4 from 4 to 5 +move 10 from 9 to 2 +move 14 from 6 to 4 +move 1 from 3 to 8 +move 1 from 8 to 5 +move 2 from 7 to 9 +move 1 from 1 to 2 +move 14 from 4 to 7 +move 1 from 1 to 4 +move 3 from 4 to 1 +move 3 from 5 to 1 +move 6 from 5 to 1 +move 10 from 7 to 3 +move 6 from 1 to 5 +move 6 from 1 to 7 +move 3 from 8 to 3 +move 1 from 5 to 1 +move 3 from 9 to 6 +move 1 from 9 to 3 +move 6 from 5 to 9 +move 2 from 6 to 1 +move 9 from 2 to 1 +move 6 from 9 to 6 +move 2 from 8 to 7 +move 5 from 7 to 3 +move 7 from 7 to 5 +move 4 from 2 to 8 +move 6 from 8 to 3 +move 1 from 9 to 4 +move 1 from 7 to 3 +move 2 from 5 to 3 +move 7 from 6 to 4 +move 28 from 3 to 4 +move 1 from 3 to 8 +move 1 from 5 to 9 +move 9 from 4 to 5 +move 12 from 4 to 5 +move 2 from 4 to 6 +move 5 from 4 to 6 +move 1 from 3 to 8 +move 10 from 5 to 8 +move 10 from 5 to 4 +move 5 from 5 to 9 +move 3 from 4 to 1 +move 5 from 6 to 9 +move 2 from 6 to 7 +move 2 from 7 to 5 +move 10 from 9 to 4 +move 1 from 8 to 5 +move 5 from 1 to 5 +move 8 from 8 to 7 +move 8 from 5 to 3 +move 8 from 7 to 8 +move 2 from 8 to 2 +move 7 from 3 to 2 +move 21 from 4 to 7 +move 10 from 1 to 9 +move 3 from 4 to 5 +move 1 from 4 to 8 +move 1 from 8 to 3 +move 7 from 8 to 5 +move 2 from 3 to 1 +move 7 from 7 to 2 +move 1 from 1 to 4 +move 1 from 1 to 6 +move 8 from 9 to 3 +move 2 from 8 to 4 +move 3 from 3 to 1 +move 3 from 4 to 7 +move 1 from 6 to 7 +move 5 from 2 to 4 +move 2 from 1 to 6 diff --git a/2022/day5.py b/2022/day5.py new file mode 100755 index 0000000..5931179 --- /dev/null +++ b/2022/day5.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 + +def parse_stacks(stacks, line): + for box in range(9): + contents = line[box*4+1] + if contents != ' ': + match box: + case 0: + stacks[0].append(contents) + case 1: + stacks[1].append(contents) + case 2: + stacks[2].append(contents) + case 3: + stacks[3].append(contents) + case 4: + stacks[4].append(contents) + case 5: + stacks[5].append(contents) + case 6: + stacks[6].append(contents) + case 7: + stacks[7].append(contents) + case 8: + stacks[8].append(contents) + + +def parse_line(line): + line = line.strip().split() + count = int(line[1]) + from_stack = int(line[3]) - 1 + to_stack = int(line[5]) - 1 + return count, from_stack, to_stack + + +def move_single(stacks, line): + count, from_stack, to_stack = parse_line(line) + + for _ in range(count): + stacks[to_stack].append(stacks[from_stack].pop()) + + +def move_multiple(stacks, line): + count, from_stack, to_stack = parse_line(line) + count = int(count) + + temp_stack = stacks[from_stack][-count:] + for _ in range(count): + stacks[from_stack].pop() + stacks[to_stack].extend(temp_stack) + + +def create_and_parse_stacks(): + stacks = [[] for _ in range(9)] + + with open('day5', 'r') as file: + lines = file.readlines() + + for line in lines[7::-1]: + parse_stacks(stacks, line[:-1]) + + return stacks, lines[10:] + + +def print_stacks(stacks): + for stack in stacks: + print(stack[-1], end='') + print() + + +def main(): + stacks, lines = create_and_parse_stacks() + + for line in lines: + move_single(stacks, line) + + print_stacks(stacks) + + stacks, lines = create_and_parse_stacks() + + for line in lines: + move_multiple(stacks, line) + + print_stacks(stacks) + + +if __name__ == '__main__': + main() diff --git a/2022/day6 b/2022/day6 new file mode 100644 index 0000000..d02d3ff --- /dev/null +++ b/2022/day6 @@ -0,0 +1 @@ +rvnvzvhzzjgjgffclllnhhtltptgptgpttjhttsllmbbphbpbzpbpjjcwjwqwccnrrtvrtrfrwffnqffsggwzzhtzhthqhffmrrzsrrnrtrqqbllhrlrjrvvrvvgdgjgfjjtzznffrfvfggswgssccpcwpccstcsstwssgzssswsgwsgsnsshcsscsffcwcmmhmsmrsrddwhhszsfsjfsfccwssvdssmzzwrzzjfzzvzzfsfsvshschhvlhhvmvpvhhstsdtstgtrrtjjcssgfssnsnfsnscnsslvvqbbhthqtqzqmzmjjfmmbdmmzdmdpmpnnfjnnrwnwbwrrwjrrttfzzlwwfmmnhhqlhqqbnqnqznncmmhfmfftsfszssftstggppfddtztltctqcqjcqcmclcnccdgcggvmvvcsstztbzttsccmgcghcczfzszbzmbmjjggsqgghbhjjhhrrjljmllczlzzqssjfjqfjfmfdfgffczfzwwpfwpwbbftbffplphhfcftctlcclhlnlhnhlhnhqnhhjbjmmtpmmlsmllvhhjghhmzzwpzprrjrzzvrvcvqvssgssnccmgmppfhfwhhczhhprhrffpvvqrqvqccdhdvvvssvdvwdwwzggfvfnvvqvwwzwmzzvttgzzwjjfvvpvffqpqhqrrwccjbjppbzbrbrrphrhgrhhzbbhrrblbjjznnlccsffpcfpcfpfddfwddbffczztzsttzsstddrqdqqchqccrlccfcwwghwhnhbhjbhhzrrgprrftrffqlljlslggzdzvvrgvgcgnnngtnggdcgddhjhchqcqfqwfwjffqppblbddgmdgmddrnddjtdjttgzgpzggwvwjvwwhdwwbvvtftcfttpftpfpzfznnchnhrrdtdbtdbdppsjsgsttptsptssnwntwnnsshqqgnnqnddhjjtqqjhhmghmhmsstrrhmmwvvlssprsrbbswsddbnntmtbmtbmmtmrrffvjffdrffnttbffbccgchghjgjwwshwswdswdsdsrdsdjdvjjgbjbssptpddzbdddqdpdspswssjrjwwcbbvsspnspslpplzlqlccvlvfllntlntnqnrqnqpqlqflfrfsfgsfswwptwwgqggrhghzghhrthtzhzsswhhzffpsffhnnrvnrvvhmmlvvqsslddhcddsllpmpggrhrcrbbmnmjmqmlmpmrrqwqhqrqhrrgrqqsrrpjpdjppzhphthddlzdzhddjvdjdcjcncnvnzzvwzvzgzjggcllvpllgdgqqdvvwnvwvwqqvwvvrbbtqqwhdztqfzzcqrshjzwqnpdsshmpjzwqdptbvfqzmfnbtlgbbsjbqgnblhbbpsfdzvcmpzfwczcnbdndsjzccjcqnrdglwfrvwtnjwpvpvvgwtmnpzhbwnbqwznmdvdrsjnlsfrpcnhlbmlgmrcjbbvhqnvbrmlnfttjllstqnqqnhqrzrhfqjbfbwfhhjzwtwzjmszzhjnjbhrlbnnpfvdmlftjnfsfnvddqfhqqlljrthptvmhbqrdmdcmljwgbrqrjwcrtmvjgqtblnslgbjmdsrrpgfsctrhwlwnszpljhrfnsfpcsgczzltgsztclhgcqljrcmbbpdlztncnrnrmgrttplcnldfqddqhznmcczbmwvsztmwmcqnrzmlmqchnhnhrrhhfntjzqcbnttspptqwvphlbtpfcbhdqzbhsbvhmsqbsdntwpcrnzvmbgqsgttbqhhblfjpmvfcrzhfnzwrzbzgsdfqndzzhfdnrvsnvfbptthjnhgljhrvwwrlbnfpvvjdjchcgbhfrqvszhrhqvtzplwsptvdhqwlzhcjpclmmrlccvgvtgsfpnjhqhrbqglznpdhmsqwwsbmhmlsmmvvghsmplqjchrfctltmnqnddzqjfpljwljbdqjcqdqzwsbcclqsmsmlstvljwwtfmpnhqzqfjghjfchjccqrchsvngvrnwfwttsnvrdlfvwfptsjcpslvvpmjclfcpljqjszptsgsmntzrdjbgrzmgvzddqrlsndjzzqbznqnphbnwfhtjjlwjpsvffrdrbsbttpgrvmqrdndqvlgzcpfbttvqdgvrmtvfclcbcwllthmdzjcflwpnrsqzrjdzbvqgzsqvjjpjjpnjtcjqhcfbjdqndlcwzhcbjtgtlvtdwctdnqcbcgsmrcrmwjntdwbjdbzmshbvlspjfdbvmlrbdzlmlggthvphnrqlrcdsqpsgqcmpgmgdzvdqlmcldvztpsbmpwjgjfhswplwrvwpbwbsgsvlhdvmpzwnnbwjwmshwcnqfqjdpchfjjcbdnslqchhnznpqpnnctznbtccclgjhmnngdjlmqnzpsdptqqcrblmrlnnpgvrfrtmbjnmspfrbwpclhgtbsghndrjfbggsplvcjnhjjbqzsfdpfnvchzjgbhdqgddfgddvzdcrjlntnsmscqwmpptqgbnvtsvpjvmhcfpbfrpzqbpfhlbjrmbmvdvvnvfqsndglvhfrqcsbsbbprscrbfthzcwcdrprqrwjzwrpblfllpwzlhmqvltjgpcjzpzwbltgwsrgrrhzcqfpvhcprdhnzcfphqrwcvtpcbppjwzmmwjhbvwbblnbwvcqzvlfzjhgmlnhlhrbsplfctggfbhbgwpncznvtmdtqqmjsvsnrlqswzvflrfsncgpdcndlwrfrqwqnqtjmsphwsgzhdjpnsdgrbrfhbfdrntwvgvbwnvwnrmdbhqgrglbfwprflnrljrwsgwtpgtmfhvvghtzndvwlzjchhmlwcncmpvrslrglzjcnhfdqhcrljhgbzpssvdnmfwzstmvrztgpsscfswltnbwrrtcnvbswmmjbmnnnvqwjzhprfnvlbvzzdvbwlwchrvqnwwpbnttbhfdvjjvzsznhczjcncmcrmwtrlsvbwpsrcwqdvgcfjsbqnwmjmtcgpnmcbfbcqhzrjbtlpvwzhjqqprbdnbgzfwlprlcspwjwnfftldqzbcgqnjtglvbpqffdvjbpslqcdzwdnmncvcwfshdhsmssttqfrsbnjgmhfqzlgrbpdfqtfdwslsgphfzzgbzjssfbgnwztzmczplqwjmhtlflpvqqqmrvlllhngtfgsvbbnvhzqbcgpmnlsmpwqwgqfjpzplzjhrslwzrsrgjgpppjlnhrnggcdzvspsztnschnqftgffbtvrpzndzpqmtsfmwgnrvpmtgpvnmqfmwgcvlznwqnjnjwpgnqfjwtdhhmztlvlcvrlzmlpmjdvdnzwbfsshfsvbbhqsmphjhqtlnvlsmvwlqvfqpnjnzlgmdvwzzrllmcgwtqdwphhbwmlrqhqrfmdvtqswvsllqvwmfbbpllsbjbvgsmrcgqvfgsnszfrdlcjbtfgcbclhmzlmqlnhmslcmgrcvjjlbpsjjcznzqwmztcgdgbmrlgwzjzzjrpndfrdzztzzgmsrcnwrvqrdcczrbhdpfjwvqsmbrcvllvjrrbrsqnzldltdgzscjrssvdhzhnvltpgfdfcvfbtqmphdzhpzgjhjbwsmdlbqqgcrhjrwhgvfgdllmmlnpsbtvdrrzmltfwgrcsfrrsdbdmjtrwhnlgcrgjgmbzvzvqbflvbrsqcssjgsvpjmlhtcggzwbvddmwwtfdrlltjqcpwnthczzlzdszvtmrmhbpcgstvrsnmbdcmjzsvnncmgmlnrzzhfvmblgptwwwbrmtcczjwcqmvdrsvfjgqqvghnhbntqcdrppfmvdzbcjvztrnpdhmdpmnvsnzzldvdfqbdrwqqqqsmswthwpjwdrflszbspqhpfwztjjcbdsrftdsrsfdltnfztcslmbsghgrtcscrfmptqplwpmtqdzthgfjhbqdnsffrpjmgczmrlfvzcjttwtmtqfbtlqrttvjdwhfgcgcclrlswmzhzbfhjrggnhwtnffnqqcvldlttvvgrbcqbmqzvtflfmdblhdbzphrqtbshvp diff --git a/2022/day6.py b/2022/day6.py new file mode 100755 index 0000000..e45d834 --- /dev/null +++ b/2022/day6.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +def find_signal(line): + letters = [line[x] for x in range(4)] + for index, letter in enumerate(line[4:]): + if len(set(letters)) == 4: + return(index + 4) + letters[index % 4] = letter + + +def find_signal_two(line): + letters = [line[x] for x in range(14)] + for index, letter in enumerate(line[14:]): + if len(set(letters)) == 14: + return(index + 14) + letters[index % 14] = letter + + +def main(): + with open('day6', 'r') as file: + line = file.readlines() + + line = line[0].strip() + + print(find_signal(line)) + print(find_signal_two(line)) + + +if __name__ == '__main__': + main() diff --git a/2022/day7 b/2022/day7 new file mode 100644 index 0000000..ee7f22f --- /dev/null +++ b/2022/day7 @@ -0,0 +1,1063 @@ +$ cd / +$ ls +dir bcfwbq +14779 cmss +dir ctctt +101350 gpbswq.njr +270744 mglrchsr +260405 qtvftbl +dir rbsrpg +dir rzgnbgv +dir svsgnbs +dir wqctlzz +71582 wrqbm +$ cd bcfwbq +$ ls +dir bsbpc +dir gpbswq +172204 lpn.qjd +269121 lts.zjd +dir pfps +dir phvgmv +dir pjcrwh +dir pvf +dir rthpbmhr +dir sjnvdz +$ cd bsbpc +$ ls +191305 hlqptq.nrj +15627 lts.zjd +$ cd .. +$ cd gpbswq +$ ls +dir ctctt +dir jcw +dir jnh +53143 lts.zjd +dir qrrjgdbd +dir tnsjg +$ cd ctctt +$ ls +dir hhmm +$ cd hhmm +$ ls +89761 brfjczv.lmr +226384 gwqfwwp.ctl +174778 pgsdmfj +$ cd .. +$ cd .. +$ cd jcw +$ ls +149585 gpbswq.lbv +$ cd .. +$ cd jnh +$ ls +10840 ctctt +dir fzplg +dir jvpc +dir lpn +dir mcz +48063 nczc +8024 rthpbmhr.qwq +65222 vqgbgm +$ cd fzplg +$ ls +34828 lpn.vcl +dir svsgnbs +$ cd svsgnbs +$ ls +216427 bvtl +242012 gpbswq.qlg +dir gsmltmw +11388 lpn.trp +dir lrr +dir vwqlvj +$ cd gsmltmw +$ ls +66467 pldhhjch +$ cd .. +$ cd lrr +$ ls +dir ctctt +dir lpn +16831 lts.zjd +dir svsgnbs +dir tdpmdfgd +177469 wct.njp +$ cd ctctt +$ ls +145394 phd.tvj +$ cd .. +$ cd lpn +$ ls +dir svsgnbs +$ cd svsgnbs +$ ls +148504 ctctt.vjd +$ cd .. +$ cd .. +$ cd svsgnbs +$ ls +245750 ggbhsgz.snc +$ cd .. +$ cd tdpmdfgd +$ ls +dir cghfclv +dir mcfzvlvw +dir mdgvcgbc +$ cd cghfclv +$ ls +49162 shwslwsf.lww +$ cd .. +$ cd mcfzvlvw +$ ls +dir bsbswh +$ cd bsbswh +$ ls +dir hqsdsp +$ cd hqsdsp +$ ls +70065 pldhhjch +$ cd .. +$ cd .. +$ cd .. +$ cd mdgvcgbc +$ ls +235514 dhfms.nwl +$ cd .. +$ cd .. +$ cd .. +$ cd vwqlvj +$ ls +269473 jwv.dqh +90324 mglrchsr +194977 rwgsvszh.jbf +$ cd .. +$ cd .. +$ cd .. +$ cd jvpc +$ ls +dir rdgqr +dir sspn +$ cd rdgqr +$ ls +dir qcjccsth +$ cd qcjccsth +$ ls +dir rqwvslc +$ cd rqwvslc +$ ls +275985 pgqph.lcn +$ cd .. +$ cd .. +$ cd .. +$ cd sspn +$ ls +200316 gpbswq +162820 pldhhjch +$ cd .. +$ cd .. +$ cd lpn +$ ls +277995 hlqptq.nrj +$ cd .. +$ cd mcz +$ ls +dir fjtj +157693 gqfgrfqw.wtc +dir jqbpcd +206235 lpn +54229 mglrchsr +238506 rthpbmhr +dir snr +dir ztlrtgjl +$ cd fjtj +$ ls +240610 fbwzn +207688 hlqptq.nrj +150032 lts.zjd +48060 mcrgn +265551 zqrnt.srf +$ cd .. +$ cd jqbpcd +$ ls +256141 ctctt.nbp +dir gpbswq +78480 hmddcjdd.bmc +31403 lpn +120619 mvdfjzdr +dir nqgvl +$ cd gpbswq +$ ls +125791 ctctt +$ cd .. +$ cd nqgvl +$ ls +174465 jrbfcvf.rqr +144210 lts.zjd +258976 rthpbmhr +$ cd .. +$ cd .. +$ cd snr +$ ls +185943 rthpbmhr.jhb +$ cd .. +$ cd ztlrtgjl +$ ls +232309 ntlzfsz.vjd +254942 zhrds.nbp +$ cd .. +$ cd .. +$ cd .. +$ cd qrrjgdbd +$ ls +dir gpbswq +$ cd gpbswq +$ ls +170768 rthpbmhr.qwf +$ cd .. +$ cd .. +$ cd tnsjg +$ ls +242206 bjmgvmp.hht +245356 frtdp +dir jrflhz +128115 lpn +120081 rfhs +dir sfplvt +dir tts +114165 zfl.ccr +$ cd jrflhz +$ ls +dir gpbswq +dir nnlzjwts +dir sctf +$ cd gpbswq +$ ls +121401 mglrchsr +$ cd .. +$ cd nnlzjwts +$ ls +dir gljnss +165011 lts.zjd +69364 svsgnbs.bqm +$ cd gljnss +$ ls +181850 cfjbd.fmj +$ cd .. +$ cd .. +$ cd sctf +$ ls +109435 gqfgrfqw.wtc +146343 lpn.mbs +255948 svsgnbs.hbf +231472 vdrfwqwv.pzf +263352 zgzj +$ cd .. +$ cd .. +$ cd sfplvt +$ ls +51580 hlqptq.nrj +dir mldph +$ cd mldph +$ ls +163815 hsnw +$ cd .. +$ cd .. +$ cd tts +$ ls +dir ctctt +211239 rpm +dir rthpbmhr +dir wpnnrzb +$ cd ctctt +$ ls +dir ctctt +137333 hshpfwl +183146 srd +$ cd ctctt +$ ls +89470 hlqptq.nrj +$ cd .. +$ cd .. +$ cd rthpbmhr +$ ls +139569 fhjlbrmp.phd +223589 jvrs.bpj +198566 rthpbmhr.qdr +$ cd .. +$ cd wpnnrzb +$ ls +dir ctctt +158058 fjtcc +dir jqqhgjv +dir qvbvvb +16429 wds.hpj +$ cd ctctt +$ ls +166551 gcjt.wld +233189 gpbswq.mls +193694 rthpbmhr.rvz +dir svsgnbs +$ cd svsgnbs +$ ls +248185 fpssfvd.zft +215781 rwtg.gch +$ cd .. +$ cd .. +$ cd jqqhgjv +$ ls +dir gpbswq +14842 lts.zjd +dir mqp +258342 pldhhjch +103492 sddj.sbq +248024 svsgnbs +$ cd gpbswq +$ ls +dir sqchbqc +176209 vdq.jbz +$ cd sqchbqc +$ ls +dir cphf +$ cd cphf +$ ls +253613 snzbgfs.rjf +$ cd .. +$ cd .. +$ cd .. +$ cd mqp +$ ls +10090 mfw +$ cd .. +$ cd .. +$ cd qvbvvb +$ ls +dir mzw +dir svsgnbs +$ cd mzw +$ ls +98994 mmv.hcl +$ cd .. +$ cd svsgnbs +$ ls +108748 lts.zjd +10351 mglrchsr +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd pfps +$ ls +dir cpp +110535 mglrchsr +120669 qvh.fbm +$ cd cpp +$ ls +dir htnmrjpq +$ cd htnmrjpq +$ ls +120225 bdjmsbg.wfz +$ cd .. +$ cd .. +$ cd .. +$ cd phvgmv +$ ls +113550 pldhhjch +31171 zcfm +$ cd .. +$ cd pjcrwh +$ ls +265625 snbjdmg.jtn +$ cd .. +$ cd pvf +$ ls +91010 ctctt +dir hdz +dir qtwfpmvz +$ cd hdz +$ ls +103787 rlnrs +$ cd .. +$ cd qtwfpmvz +$ ls +244905 lts.zjd +$ cd .. +$ cd .. +$ cd rthpbmhr +$ ls +dir phq +dir svsgnbs +dir wzwfz +dir zpwfj +$ cd phq +$ ls +91709 bzfnqh +dir ccwqrjn +dir gpbswq +dir svsgnbs +$ cd ccwqrjn +$ ls +8953 fffqzmqp +dir ftnb +dir svsgnbs +$ cd ftnb +$ ls +226615 rthpbmhr +$ cd .. +$ cd svsgnbs +$ ls +dir bhnnm +dir tjrqtmd +$ cd bhnnm +$ ls +dir prfqw +$ cd prfqw +$ ls +dir hzsjlq +$ cd hzsjlq +$ ls +99285 cfpwbvp +$ cd .. +$ cd .. +$ cd .. +$ cd tjrqtmd +$ ls +237461 cqr.wfj +149955 zchnb +$ cd .. +$ cd .. +$ cd .. +$ cd gpbswq +$ ls +dir bqqtnfb +dir ctctt +261108 gpbswq +135193 hnrflng +264503 jrp.bls +224864 mghhgrj.tgp +dir pljbtbn +dir rthpbmhr +244222 svsgnbs.rzp +$ cd bqqtnfb +$ ls +dir jnzfr +$ cd jnzfr +$ ls +dir bdrqmr +168907 pldhhjch +$ cd bdrqmr +$ ls +151767 vfw.jjc +$ cd .. +$ cd .. +$ cd .. +$ cd ctctt +$ ls +dir zdsshmr +$ cd zdsshmr +$ ls +77208 hlqptq.nrj +$ cd .. +$ cd .. +$ cd pljbtbn +$ ls +63719 hlqptq.nrj +103719 jjctg.dhw +547 tljz.wnv +$ cd .. +$ cd rthpbmhr +$ ls +dir sjbfhcpc +$ cd sjbfhcpc +$ ls +184946 sgpgszw +$ cd .. +$ cd .. +$ cd .. +$ cd svsgnbs +$ ls +dir ctctt +dir flzsvb +dir pbw +23408 qprlnvwv.jmz +dir wjhplc +$ cd ctctt +$ ls +11507 cnf +dir gpbswq +87778 rthpbmhr.wzv +dir slmbb +dir sqc +75556 wsbzwn.mpf +$ cd gpbswq +$ ls +173498 dsg +202811 msvs.szd +208419 pldhhjch +$ cd .. +$ cd slmbb +$ ls +dir jcth +dir njldhbln +$ cd jcth +$ ls +6106 hlqptq.nrj +$ cd .. +$ cd njldhbln +$ ls +241153 mvnvzqfc.rtn +$ cd .. +$ cd .. +$ cd sqc +$ ls +dir zhrc +$ cd zhrc +$ ls +dir qswqqzb +$ cd qswqqzb +$ ls +264937 btqmqn.hqv +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd flzsvb +$ ls +58735 hlqptq.nrj +$ cd .. +$ cd pbw +$ ls +80787 bgfmdg +234807 gqfgrfqw.wtc +44816 pldhhjch +dir qjjpmq +dir rthpbmhr +153500 ssmdz +$ cd qjjpmq +$ ls +155209 ctghhsdh +182544 fprdp.ffs +$ cd .. +$ cd rthpbmhr +$ ls +136673 lts.zjd +$ cd .. +$ cd .. +$ cd wjhplc +$ ls +246593 hhcgnfjb.nbl +29266 hlqptq.nrj +246096 lts.zjd +40242 rrfgvvhg +$ cd .. +$ cd .. +$ cd .. +$ cd svsgnbs +$ ls +215743 fwm +236816 gqfgrfqw.wtc +235185 sjdlr.rzj +dir ztsgb +$ cd ztsgb +$ ls +265998 rthpbmhr.pdp +275979 zqfcprz.wtd +$ cd .. +$ cd .. +$ cd wzwfz +$ ls +dir bsqwtf +dir ctctt +dir lpng +dir svsgnbs +$ cd bsqwtf +$ ls +dir rhjb +dir sgzvb +$ cd rhjb +$ ls +166599 rthpbmhr.msg +$ cd .. +$ cd sgzvb +$ ls +185594 zmnb.bcq +$ cd .. +$ cd .. +$ cd ctctt +$ ls +130367 svsgnbs +17459 tdsztr.fsn +242273 wfs +$ cd .. +$ cd lpng +$ ls +145778 snmcwfg.hjz +$ cd .. +$ cd svsgnbs +$ ls +dir ctctt +dir nqrlzg +dir qczmdfm +54814 wtmjh.jdv +$ cd ctctt +$ ls +244171 pldhhjch +$ cd .. +$ cd nqrlzg +$ ls +dir qjhlj +$ cd qjhlj +$ ls +dir gncct +$ cd gncct +$ ls +141943 wsdgmdd.ctz +$ cd .. +$ cd .. +$ cd .. +$ cd qczmdfm +$ ls +4482 lpn.fmp +$ cd .. +$ cd .. +$ cd .. +$ cd zpwfj +$ ls +226995 lts.zjd +dir sflcgdm +$ cd sflcgdm +$ ls +199168 bjrjrrm.bfw +dir fpcq +24906 gdzfmhz.jhp +7267 hdpzvh.ngg +dir jjsgqb +137796 psws.hvp +$ cd fpcq +$ ls +195792 nghcc.wps +$ cd .. +$ cd jjsgqb +$ ls +18774 ctctt +106399 jvbgfhs +208035 rthpbmhr +dir zptz +$ cd zptz +$ ls +278792 gqfgrfqw.wtc +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd sjnvdz +$ ls +dir fchgggp +dir gldg +40164 gnh.gmv +dir lpn +dir njtgjt +81415 qqfm.grb +dir vvcbjct +$ cd fchgggp +$ ls +dir fjcclj +dir lpn +145291 lts.zjd +7288 mglrchsr +dir pmhdzvfn +dir qtpdfwh +dir vjwtvb +$ cd fjcclj +$ ls +28333 gpbswq.vtg +258676 lts.zjd +$ cd .. +$ cd lpn +$ ls +197797 pldhhjch +$ cd .. +$ cd pmhdzvfn +$ ls +21538 gpbswq.pwq +5451 hqjg +dir llhp +220717 lzqmh.stl +123800 pldhhjch +dir pmv +dir rzs +dir tztv +160018 zfvgjtzr.qth +$ cd llhp +$ ls +dir lsft +dir pfjmphs +$ cd lsft +$ ls +78424 gpbswq.ddb +101497 gqfgrfqw.wtc +137686 hlqptq.nrj +122325 mglrchsr +$ cd .. +$ cd pfjmphs +$ ls +185141 mbw.gnd +$ cd .. +$ cd .. +$ cd pmv +$ ls +139255 gqfgrfqw.wtc +272882 hlqptq.nrj +$ cd .. +$ cd rzs +$ ls +dir gpbswq +89153 gpbswq.vcv +81882 gqfgrfqw.wtc +39252 hlqptq.nrj +dir tmcm +$ cd gpbswq +$ ls +205674 ctctt.gqd +$ cd .. +$ cd tmcm +$ ls +156591 gmjvzj.wzl +199254 lts.zjd +dir vzhbsdd +dir zfs +$ cd vzhbsdd +$ ls +70059 gsgzqgn.fhf +43456 hrttvrqc +$ cd .. +$ cd zfs +$ ls +223726 hlqptq.nrj +$ cd .. +$ cd .. +$ cd .. +$ cd tztv +$ ls +200126 lpn.bns +dir wfjwmbj +$ cd wfjwmbj +$ ls +120344 gdqgml.gdn +$ cd .. +$ cd .. +$ cd .. +$ cd qtpdfwh +$ ls +dir qszjt +$ cd qszjt +$ ls +7207 rthpbmhr.rpv +20452 ztdnfmgp.dsb +$ cd .. +$ cd .. +$ cd vjwtvb +$ ls +dir scswlmn +$ cd scswlmn +$ ls +207195 svsgnbs.jqq +$ cd .. +$ cd .. +$ cd .. +$ cd gldg +$ ls +119560 ctctt.wbc +203041 gqfgrfqw.wtc +dir hrp +274270 lts.zjd +25081 mhsfdhjr.ndw +dir svsgnbs +$ cd hrp +$ ls +dir lpn +$ cd lpn +$ ls +dir gpbswq +dir wvrzhdb +$ cd gpbswq +$ ls +dir vtgc +$ cd vtgc +$ ls +231107 hlqptq.nrj +$ cd .. +$ cd .. +$ cd wvrzhdb +$ ls +83303 lts.zjd +$ cd .. +$ cd .. +$ cd .. +$ cd svsgnbs +$ ls +dir fhfqlv +13446 frn.hzg +126475 wmjjjl.cjr +$ cd fhfqlv +$ ls +243574 hjn.jzb +$ cd .. +$ cd .. +$ cd .. +$ cd lpn +$ ls +dir mqglznd +$ cd mqglznd +$ ls +dir gpbswq +177654 gpbswq.zhv +128217 gqfgrfqw.wtc +66750 hlqptq.nrj +136018 hvphz +dir pswvwtf +113363 rthpbmhr.gwz +dir twddrn +$ cd gpbswq +$ ls +244278 lts.zjd +dir pfrjwbvl +dir qlrfw +222491 rthpbmhr +$ cd pfrjwbvl +$ ls +46802 cfl.ljt +dir ctctt +dir dfqzmd +110525 gshdhsfm +dir jcbw +dir lpn +237385 pldhhjch +15812 prcwhhq.jjh +dir rthpbmhr +260693 zmgq +$ cd ctctt +$ ls +6529 hctcg.dpw +188655 lpn.qjf +202221 wjnb +$ cd .. +$ cd dfqzmd +$ ls +197980 ctctt +$ cd .. +$ cd jcbw +$ ls +1281 gpbswq +15778 jfgjlcd.mqh +38803 mdtcrb.dbj +dir qtjbpbs +$ cd qtjbpbs +$ ls +59348 mglrchsr +$ cd .. +$ cd .. +$ cd lpn +$ ls +dir ctctt +dir hsjjp +260465 mglrchsr +$ cd ctctt +$ ls +dir wvbrsb +$ cd wvbrsb +$ ls +135584 lts.zjd +$ cd .. +$ cd .. +$ cd hsjjp +$ ls +249448 ddfqnwgf +164051 dsnhsbp.wvv +dir fmzgm +dir gpbswq +113907 gqfgrfqw.wtc +$ cd fmzgm +$ ls +150025 ngnqjcj.tbf +$ cd .. +$ cd gpbswq +$ ls +33139 dmgqhf.nzd +dir gpbswq +dir rwd +$ cd gpbswq +$ ls +148820 lnqqds.rpg +$ cd .. +$ cd rwd +$ ls +133433 pldhhjch +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd rthpbmhr +$ ls +262342 fdnr.svq +dir nbpsdm +161791 pldhhjch +6835 qvclr +228110 whf +$ cd nbpsdm +$ ls +dir rthpbmhr +dir svsgnbs +$ cd rthpbmhr +$ ls +267109 chb +$ cd .. +$ cd svsgnbs +$ ls +150446 rlv.vcc +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd qlrfw +$ ls +dir sgcpwst +$ cd sgcpwst +$ ls +dir fss +$ cd fss +$ ls +244165 gpbswq.qtz +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd pswvwtf +$ ls +162099 jhdrnv.zrd +54856 mglrchsr +dir psdz +169053 qhq +$ cd psdz +$ ls +dir lbcf +$ cd lbcf +$ ls +218770 ctctt.chv +95266 pldhhjch +$ cd .. +$ cd .. +$ cd .. +$ cd twddrn +$ ls +120791 hlqptq.nrj +212213 vffj +$ cd .. +$ cd .. +$ cd .. +$ cd njtgjt +$ ls +dir mzwdb +$ cd mzwdb +$ ls +108520 lts.zjd +$ cd .. +$ cd .. +$ cd vvcbjct +$ ls +155890 ctctt.fbw +$ cd .. +$ cd .. +$ cd .. +$ cd ctctt +$ ls +5656 mpftwp.nds +8998 pldhhjch +185601 snrng.qsv +$ cd .. +$ cd rbsrpg +$ ls +113129 cpwmjw.rbj +dir jdhmlzr +114254 sqj.fzp +120708 svsgnbs.hpn +$ cd jdhmlzr +$ ls +dir cdnmflmm +248055 hlqptq.nrj +247942 pldhhjch +dir qrwsnzdv +80053 svsgnbs +219309 zhqgvd.bhw +$ cd cdnmflmm +$ ls +83138 lpn.wtg +$ cd .. +$ cd qrwsnzdv +$ ls +197145 zspfb.sbd +$ cd .. +$ cd .. +$ cd .. +$ cd rzgnbgv +$ ls +208692 clz +dir tmcqcpfc +dir twlnjr +$ cd tmcqcpfc +$ ls +dir jtnf +$ cd jtnf +$ ls +242978 fhvtvdff.swr +21748 lwcplzmw +$ cd .. +$ cd .. +$ cd twlnjr +$ ls +dir ctctt +dir gpbswq +98435 rthpbmhr.pcr +dir snpm +dir svsgnbs +104969 zzd +$ cd ctctt +$ ls +200382 pqswsnhp +$ cd .. +$ cd gpbswq +$ ls +90380 qqrfbwn +$ cd .. +$ cd snpm +$ ls +57996 swfjlfh.qft +$ cd .. +$ cd svsgnbs +$ ls +86028 clcfrnr.jwl +199666 ctctt.ftr +200949 ctctt.mrh +23594 dhlmbh.gjt +278047 mbchg +dir pgfhp +$ cd pgfhp +$ ls +21555 rlblnvsd +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd svsgnbs +$ ls +155183 jgjj.sgs +28150 pldhhjch +$ cd .. +$ cd wqctlzz +$ ls +23662 mglrchsr +60923 pldhhjch diff --git a/2022/day7.py b/2022/day7.py new file mode 100755 index 0000000..73c7358 --- /dev/null +++ b/2022/day7.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python3 + +class File: + def __init__(self, name, size): + self.name = name + self.size = size + + +class Directory: + def __init__(self, name, parent): + self.parent = parent + self.name = name + self.directories = [] + self.files = [] + + def addFile(self, file): + self.files.append(file) + + def addDirectory(self, directory): + self.directories.append(directory) + + def getSize(self): + self.size = 0 + for file in self.files: + self.size += int(file.size) + for directory in self.directories: + self.size += int(directory.getSize()) + return self.size + + def __str__(self): + return self.name + + +class FileSystem: + def __init__(self): + self.root = Directory('/', '') + self.root.parent = self.root + self.current_directory = self.root + self.all_directories = [] + + def addFile(self, file): + self.root.files.append(file) + + def addDirectory(self, directory): + self.root.directories.append(directory) + + def getSize(self): + return self.root.getSize() + + +def change_directory(line, fs): + match line[2]: + case '..': + fs.current_directory = fs.current_directory.parent + case '/': + fs.current_directory = fs.root + case _: + for directory in fs.current_directory.directories: + if directory.name == line[2]: + fs.current_directory = directory + return + new_directory = Directory(line[2], fs.current_directory) + fs.all_directories.append(new_directory) + fs.current_directory.addDirectory(new_directory) + fs.current_directory = new_directory + + +def process_command(line, fs): + match line[1]: + case 'cd': + change_directory(line, fs) + case 'ls': + pass + + +def process_line(line, fs): + line = line.split() + match line[0]: + case '$': + process_command(line, fs) + case 'dir': + for directory in fs.current_directory.directories: + if directory.name == line[1]: + return + new_directory = Directory(line[1], fs.current_directory) + fs.all_directories.append(new_directory) + fs.current_directory.addDirectory(new_directory) + case _: + for file in fs.current_directory.files: + if file.name == line[1]: + file.size == line[0] + return + new_file = File(line[1], line[0]) + fs.current_directory.addFile(new_file) + + +def main(): + with open('day7', 'r') as file: + lines = file.readlines() + + fs = FileSystem() + fs.current_directory = fs + + for line in lines: + line = line.strip() + process_line(line, fs) + + root_size = fs.getSize() + print(f'{fs.root.name} : {root_size}') + max_size = 30_000_000 - (70_000_000 - root_size) + smallest = 30_000_000 + total_size = 0 + for directory in fs.all_directories: + size = directory.getSize() + if size <= 100_000: + total_size += directory.getSize() + if size >= max_size: + if size < smallest: + smallest = size + print(total_size) + print(smallest) + + +if __name__ == '__main__': + main() diff --git a/2022/day7.sample b/2022/day7.sample new file mode 100644 index 0000000..09a921e --- /dev/null +++ b/2022/day7.sample @@ -0,0 +1,23 @@ +$ cd / +$ ls +dir a +14848514 b.txt +8504156 c.dat +dir d +$ cd a +$ ls +dir e +29116 f +2557 g +62596 h.lst +$ cd e +$ ls +584 i +$ cd .. +$ cd .. +$ cd d +$ ls +4060174 j +8033020 d.log +5626152 d.ext +7214296 k diff --git a/2022/day8 b/2022/day8 new file mode 100644 index 0000000..e67c61c --- /dev/null +++ b/2022/day8 @@ -0,0 +1,99 @@ +200120010031113332213034140102430141241124321111512323442304040044220141342121012210022220211111200 +111021120230012003124233312003010303204555454332453445353125225214221214442214301113012111020220220 +010000112330232223210123331341111021455213441355415452453433542411022110033014112420103200010200112 +210220131023203033023421012411405531115123145115445215311422135252541100222231431331003220231121021 +020112210133112114444340100410411231114131452544155151415233415312511222041221113442132231003203100 +121210122332301142321211440441113455552434332511455325315545354524142541534411112013143013120333022 +002022223332143323320030004111431434153352153321414154453442552321332341355132444030442110103203212 +212130023213100232130230411132244242133251435525323326611211534441513532233340420321144212221332012 +112201210213131241203033341411115513233426453426433653356253533133113511115222441140433214102332200 +212012000101044144022321521321444445566546646625625665232323663631331412343532242340023204432003233 +101233132121222100241254211542133266356326564552445466322626353633223221135151311240430411433022011 +200132020222314334333551152431232424524623645555522366665322366466545513112135535223102441334310202 +023113000020114221524122422222662645435544455234636242322656464245462233555511334411233402112203303 +323212301014434412315252233452332225554646452654545433445553336343544664455435323243510303023142200 +310022200424121333144123222262332322343322244646667564465544426245466232342143412141451122001041322 +212301111322001335441132334525635254352425553354565445643472236236266635446421522132452121404230333 +222212444300345211222512256444456624535343536756355746664436374344346652444335121144422222340114403 +133103420101433344253425324366444265345745457464444766674564476573243345254266312555221132304022243 +104024111323421413115464433455553477333456354575666765646757774776752425462423244113225443242031103 +102001244212344453145353232652647556546465453563544776667356374453675332254663444121345213131024201 +224444241243433331136646422564367344447534333336573546336576477746463642222264422255444411444213332 +111102440221143134255523244546456346745346547453543465664363545634575433436342252431313443241200434 +134231321331555233423635635366465473563535535586445888474374535544636375425246452265522242444124430 +234112414314111344422243544643454775656784865866884848444877466476364476356322553554245224411411221 +034400114351525345222546546744637535635657575787587675474664764764736443646462322222525151425423322 +200214241324215322354446653764777674587466544685754678446567884767437556756324542252661541311422130 +343144113253113264625454456777333344687566876677476786864558645875776364454562645333232242321313142 +343024121143435322432236376444777668467756646886688564457885758774655565674476525265433235351133020 +403402124545255442342535445764457654765745674556784877787445455686478773563733543423236235255444144 +103322531152132266562676355566367676848756788886766967585484486646776553753344443262466623351341241 +310355244513624552353465735465555764667556575665597778969594858667646774744555337236256442514154340 +023311451112523462333545544537465688645559988688956997665697964748587858337347363225646321434554144 +320135522136342345436443367666564847488558589757575579796688785767645678467555334323622425311134113 +302355525243323546577736555686874886486985688686888898966978978668487864787645754566534465541511251 +334125312126266532347576536548547584696886997768569758698995755875465674754333433642553345425533431 +341111335132225635365534457665748575977867585959997886979957965558787465664637533766462255534332423 +332515314534343636736373478687676678865555895657977886779567677978977887466835476754353523355412552 +223554423243256435734467677444784886576856669787898778968956989875566754875777467667635224535114135 +155522522343322534364735656868875656687568869667769697877887796866975856457447636733764232364431215 +242345244424435673345476658556448689589759768689899966877768987857579874745884637474453634352133231 +415255446645436567674735664645455855996887768879976678686967768687868985856885736776326622253351232 +345511155426334655353457846578475998667966669787979667866969678557875668566464436456435236255355314 +142554534636264637437346664558867877978687978689679869967766679569789677485678377367342526223134543 +445152112563265336347774464854776998568899676687677797996796877777879786686845577654534235322155423 +333311452256452445537757558677965658888896678979799998788899698785896978877575444547572432544335251 +153342523322435374455644657476596955598987666997999878876686677879688676464687476363732553363413554 +144335145664565566437454557675966795686769969779977988878679878778787789465465637576634655354532332 +152415343652336664567566647557776598677998979889877998977867798897785759685544636646555455665423232 +233452324356364643433768554555595977968766779897887998898666688775789556775758843355374525244243434 +415514136342636535455644448567857957878867697988999887897878896698589669784466744746433345345355353 +232342145445335734443368474877857768999979889789879797978786868766697957448687837436437246435352325 +423142134652644455355368647749855698998886897798977997799867788779868756865564445675347463653623132 +221215125542657466763755887857659858677696867997877899797779899996787779754784846775376254442211254 +154531463524644747547747455647685566769977767978799879788898879798999996758665537564563322242224125 +114543323332546776763457675777969696978788779877889799879998997975759878686666834757774555334611241 +353441154256436766664748544445957885788777978878979877989798876799786999466647747557553324526153313 +433233236244364537664567776764977668967888876787887977898978679686668778764647857553662664333221513 +112335142543334473565677774456986769698869989679787999966877889796668798648474667745633463364123315 +113555236654542657737447854474695576987788777767987976776779677896568655666568777374452626625515123 +335535115334436455537766485588496998559679678997888767666867796988758985466776445675326242423551222 +113534446446435634464566878474597579966586699697988866966997787776788976778774466655756463456235323 +432234422656545375357656547448457656589888789768979867898878979959955468888683644466555336562315155 +313344415452422533675445775845665999956589788887986877769867786689888565577764433373633363624515141 +222432351346446453465663784584875977688789959977876966969658866777886544775874577535665532224311252 +225114233145352533344653757488874695566977756698769768695668575699668757584555454357642544414312222 +033415322244643242337557674678486867575857998965787859688788778777887745544746656765646262354135222 +244444135424622245536477356767676647596876888859989597677576756885858547856577434533266366252341111 +043422441154553466473376764757644888596669857975585975898957778585855575867574554436566563342243533 +331142132342425642446677456357664865566895568659588999997598897847485545576757377726563624233332331 +023252542543632422666654576368776445864568889675685656595757555564576478356355573264462564525315531 +401013153355343645357335364463874854866687865999886679877556446867474565563474773455256232432344241 +021145311524153334266573666344586785645787666877957988698886547444446737764473344255436645355133043 +343022114235145422524664767447348848745548778464684486768568675765556575337775543626443412212441440 +111402455441135334663624565477563468586767564584754776865658486876757446535673333342623334312243002 +300312451335434322222245676775746358685854756547745674447587647487533473336654232544332431554454412 +433111155454541556355524273356653577688858857767884847858548544877576457444762553325524214215402141 +131233333423335563265232427676636343767667757678865557657665545337553674363435662333422331253432142 +424110224332255444554444426563344537343587775787775766858448446366677553432226234426335534235001312 +333412002215124441543424366273747763767633456777658554454464446357566564765333524264253113145112300 +101110030515255434456252656567734365435643756543777575374763565634563366532624443621453215143234300 +303322412424455315323623364345353365376676743654344676735433644466637676342646445331232331222232310 +323112211415542144152522545435246756534467755554567676637543357465766366552324534423444455001240332 +104010010231221552145233456226456635564775656444567465773637433733444632663325561451234351230241312 +121411232340543435321316435636242655564355535365574763633547465475523553325562122152444444042300041 +131012210332331125512334254246234345354543573744464635755354544666345534262435114123351541032131413 +320204021134412321515435566234224352423426577577364457356445435455454244243342521425351312003010221 +323114214132034241313542544555435465334424654666346364554655422236635456436354122354410044244241323 +013302120424301452153353441245652435266525344656664634425626224355262362255351231351513443132401213 +320030122021334215313244242334523262333453263233364243362363226452453421344311524253311414201210001 +232000301112410134252124412414346224626463252363536262245565624425334453135542241232142142113023001 +023101113421202000305251552134255163452646652324334242436543224522235515444445314014323100240020120 +320223110031202012323335553432231212252653563665545464422324656333443431535442453303001103202231020 +102033222010100142203435155413125314311166645446465322244546532441244154143433143443342400201012012 +103310002120123402241302221241151441435355114335344522434421453552354154135223134443030043002000021 +112323110033212002113322411233332355223342424233213123445224135331545115152043042400020200022133330 +022111301200101044211214231433231311322554214331413543414521424255241531111410022413003020200231110 +012022111212202121003233141343155411314255551134343533133453252153433344441013011221420230021203220 +221101122202110034040022441212441254112211113355531534335143125434435312222200311411322330203331100 +210122210200133032213341213111433213432513121525124133544144433541201142230241123430213303001122221 diff --git a/2022/day8.py b/2022/day8.py new file mode 100755 index 0000000..08cad1b --- /dev/null +++ b/2022/day8.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +def main(): + with open('day8.sample', 'r') as file: + lines = file.readlines() + + matrix = [list(line.strip()) for line in lines] + last_column = len(matrix[0]) -1 + last_row = len(matrix) -1 + print(last_column, last_row) + visible = 0 + for row_index, row in enumerate(matrix): + for column_index, column in enumerate(row): + try: + if (column > matrix[row_index + 1][column_index] or + column > matrix[row_index - 1][column_index] or + column > matrix[row_index][column_index + 1] or + column > matrix[row_index][column_index - 1]): + visible += 1 + elif (row_index == 0 or column_index == 0 or + row_index == last_row or column_index == last_column): + visible += 1 + else: + print(f'not visible {column_index}x{row_index}', column) + except IndexError: + visible += 1 + print(visible) + + + +if __name__ == '__main__': + main() diff --git a/2022/day8.sample b/2022/day8.sample new file mode 100644 index 0000000..16d6fbd --- /dev/null +++ b/2022/day8.sample @@ -0,0 +1,5 @@ +30373 +25512 +65332 +33549 +35390