Code Monkey home page Code Monkey logo

advent-of-code-2022's Introduction

advent of code banner

Advent of Code - 2022

Installation

Recommended python version: 3.10

  • Day 3, 5 and 21 use the walrus operator := introduced in Python 3.8.
  • Day 7 solution leverages the match statement introduced in Python 3.10.
  • Day 11 and 20 need Python 3.9 for type annotations.
virtualenv -p python3 .venv --prompt aoc-2022
source .venv/bin/activate
pip install -r requirements.txt

Usage

python dayXX/main.py

Code Golf

Code golf is a type of recreational computer programming competition in which participants strive to achieve the shortest possible source code that solves a certain problem - Wikipedia

Instruction

Move into the folder: cd dayXX. For the shortest solution, open a python shell and copy the code snippet. You can also run python golfing.py. The benefit of the python shell is that you don't need to call print() to display the computed values.

Do you know you can encode your code in UTF-16? The solution is a bit less readable but way shorter. As this is controversal in the code golfing community I reported the length of both the raw code and the encoded version.

Solutions

  • Day 1 - 94/76 chars:
    c=sorted([sum(map(int,e.split("\n")))for e in open("i").read().split("\n\n")])
    c[0],sum(c[:3])
    exec(bytes('㵣潳瑲摥嬨畳⡭慭⡰湩ⱴ⹥灳楬⡴尢≮⤩昩牯攠椠灯湥∨≩⸩敲摡⤨献汰瑩∨湜湜⤢⥝瀊楲瑮挨せⱝ畳⡭季㌺⥝
','u16')[2:])
  • Day 2 - 122/90 chars
    [*map(sum,zip(*[[b+1+(b-a+1)%3*3,b*3+(a+b-1)%3+1]for a,b in[[ord(l[0])-65,ord(l[2])-88]for l in open("i").readlines()]]))]
    exec(bytes('牰湩⡴⩛慭⡰畳Ɑ楺⡰嬪扛ㄫ⠫ⵢ⭡⤱㌥㌪戬㌪⠫⭡ⵢ⤱㌥ㄫ晝牯愠戬椠孮潛摲氨せ⥝㘭ⰵ牯⡤孬崲⴩㠸晝牯氠椠灯湥∨≩⸩敲摡楬敮⡳崩⥝崩
','u16')[2:])
  • Day 3 - 196/127 chars
    d=open("i").readlines()
    [sum([c-38-58*(c>97)for c in map(ord,map(max,b))])for b in[[set(r[:len(r)//2])&set(r[len(r)//2:])for r in d],[set(d[i])&set(d[i+1])&set(d[i+2])for i in range(0,len(d),3)]]]
    exec(bytes('㵤灯湥∨≩⸩敲摡楬敮⡳਩牰湩⡴獛浵嬨ⵣ㠳㔭⨸挨㤾⤷潦⁲⁣湩洠灡漨摲洬灡洨硡戬⤩⥝潦⁲⁢湩孛敳⡴孲氺湥爨⼩㈯⥝猦瑥爨汛湥爨⼩㈯崺昩牯爠椠嵤嬬敳⡴孤嵩☩敳⡴孤⭩崱☩敳⡴孤⭩崲昩牯椠椠慲杮⡥ⰰ敬⡮⥤㌬崩嵝
','u16')[2:])
  • Day 4 - 218/138 chars
    import re
    [*map(sum,zip(*[[r[0]<=r[2]<=r[3]<=r[1]or r[2]<=r[0]<=r[1]<=r[3],r[0]<=r[2]<=r[1]or r[2]<=r[0]<=r[3]]for r in[list(map(int,re.search(r"(\d+)-(\d+),(\d+)-(\d+)",l).groups()))for l in open("i").readlines()]]))]
    exec(bytes('浩潰瑲爠੥牰湩⡴⩛慭⡰畳Ɑ楺⡰嬪牛せ㱝爽㉛㱝爽㍛㱝爽ㅛ潝⁲孲崲㴼孲崰㴼孲崱㴼孲崳爬せ㱝爽㉛㱝爽ㅛ潝⁲孲崲㴼孲崰㴼孲崳晝牯爠椠孮楬瑳洨灡椨瑮爬⹥敳牡档爨⠢摜⤫⠭摜⤫⠬摜⤫⠭摜⤫Ⱒ⥬朮潲灵⡳⤩昩牯氠椠灯湥∨≩⸩敲摡楬敮⡳崩⥝崩
','u16')[2:])
  • Day 6 - 114/86 chars
    f=lambda d,m:min(i+m for i in range(len(d))if len(d[i:i+m])==len(set(d[i:i+m])))
    d=open("i").read()
    f(d,4),f(d,14)
    exec(bytes('㵦慬扭慤搠洬洺湩椨洫映牯椠椠慲杮⡥敬⡮⥤椩⁦敬⡮孤㩩⭩嵭㴩氽湥猨瑥搨楛椺洫⥝⤩搊漽数⡮椢⤢爮慥⡤਩牰湩⡴⡦Ɽ⤴昬搨ㄬ⤴
','u16')[2:])
  • Day 10 - 218/134 chars
    from itertools import*
    a,b=zip(*[[(i+1)*x*(i%40==19),"\n"*(i%40==0)+".#"[x-2<i%40<x+2]]for i,x in enumerate(accumulate([1]+[int(x)if x[-1].isdigit()else 0 for x in open("i").read().split()]))])
    print(sum(a),"".join(b))
    exec(bytes('牦浯椠整瑲潯獬椠灭牯⩴愊戬氽獩⡴楺⡰嬪⡛⭩⤱砪⠪╩〴㴽㤱Ⱙ尢≮⠪╩〴㴽⤰∫⌮嬢⵸㰲╩〴砼㈫嵝潦⁲Ⱪ⁸湩攠畮敭慲整愨捣浵汵瑡⡥ㅛ⭝楛瑮砨椩⁦學ㄭ⹝獩楤楧⡴攩獬⁥‰潦⁲⁸湩漠数⡮椢⤢爮慥⡤⸩灳楬⡴崩⤩⥝਩牰湩⡴畳⡭⥡∬⸢潪湩戨⤩','u16')[2:])

advent-of-code-2022's People

Contributors

antoinebrl avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.