Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
/ advent_of_code_2022 Public archive

Solutions to Advent of Code 2022 using python, using mostly oneliners

Notifications You must be signed in to change notification settings

kidal5/advent_of_code_2022

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 

Repository files navigation

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!

About

Solutions to Advent of Code 2022 using python, using mostly oneliners

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published