Code Monkey home page Code Monkey logo

advent_of_code_2022's Introduction

Solutions

In the end around 14 challenges were solved with 27 gold stars gained!

Day 1

First part:

max([sum(map(int, elf.split('\n'))) for elf in elves.split('\n\n')])

Second part:

sum(sorted([sum(map(int, elf.split('\n'))) for elf in elves.split('\n\n')])[-3:])

Day 2

First part:

sum([{'A X':4,'A Y':8,'A Z':3,'B X': 1,'B Y':5,'B Z':9,'C X':7,'C Y':2,'C Z':6}[row] for row in text.split('\n')])

Second part:

sum([{'A X':3,'A Y':4,'A Z':8,'B X':1,'B Y':5,'B Z':9,'C X': 2,'C Y':6,'C Z':7}[row] for row in text.split('\n')])

Day 3

First part:

sum([ord(item) - 38 if item.isupper() else ord(item) - 96  for item in [list(set(line[:len(line)//2]) & set(line[len(line)//2:]))[0] for line in text.split('\n')]])

Second part:

# I did not find a one line solution  (aka. was too lazy to find it)

Day 3

First part:

sum([1 for (a,b),(c,d) in [(list(map(int, a.split('-'))), list(map(int, b.split('-')))) for a,b in [abc.split(',') for abc in text.split('\n')]] if (set(range(a,b+1)).issubset(set(range(c,d+1)))) or (set(range(c,d+1)).issubset(set(range(a,b+1))))])

Second part:

sum([1 for (a,b),(c,d) in [(list(map(int, a.split('-'))), list(map(int, b.split('-')))) for a,b in [abc.split(',') for abc in text.split('\n')]] if (len(set(range(a,b+1)) & set(range(c,d+1)))) > 0])

Day 4

First part & second part:

# I solved it using class MyStack and for loop.

Day 5

First part:

min([i+3 for i in range(len(text) - 3) if len(text[i:i+3]) == len(set(text[i:i+3]))])

Second part:

min([i+14 for i in range(len(text) - 14) if len(text[i:i+14]) == len(set(text[i:i+14]))])

Day 6 and follwoings:

Challenges starting on day 6 are much harder and doing them using one line does not seem feasible. I might update this review when some challenge in future become feasible, otherwise not. Keep coding!

advent_of_code_2022's People

Contributors

kidal5 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.