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

Latest commit

 

History

History
67 lines (54 loc) · 1.94 KB

README.md

File metadata and controls

67 lines (54 loc) · 1.94 KB

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!