Compare commits
No commits in common. "2aa9a6fcdcc3a328a4d41f8594c3291fc655d585" and "d88f3742d19fd50cf4806a79a8d30e1ecbc6386f" have entirely different histories.
2aa9a6fcdc
...
d88f3742d1
@ -1,6 +0,0 @@
|
|||||||
vJrwpWtwJgWrhcsFMMfFFhFp
|
|
||||||
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
|
|
||||||
PmmdzqPrVvPwwTWBwg
|
|
||||||
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
|
|
||||||
ttgJtRGJQctTZtZT
|
|
||||||
CrZsJsPPZsGzwwsLwLmpwMDw
|
|
@ -1,46 +0,0 @@
|
|||||||
|
|
||||||
import fileinput
|
|
||||||
|
|
||||||
from typing import Iterable
|
|
||||||
|
|
||||||
def letter_to_priority(i: str) -> int:
|
|
||||||
i = ord(i)
|
|
||||||
return (i & 0b11111) + (~((i & 0b00100000) >> 5) & 1) * 26
|
|
||||||
|
|
||||||
def compartment(items: str) -> int:
|
|
||||||
field = 0
|
|
||||||
for item in items:
|
|
||||||
field |= 1 << (letter_to_priority(item) - 1)
|
|
||||||
return field
|
|
||||||
|
|
||||||
def bitmap_to_priority(field: int) -> int:
|
|
||||||
for idx in range(52):
|
|
||||||
if field & 0b1:
|
|
||||||
return idx + 1
|
|
||||||
else:
|
|
||||||
field >>= 1
|
|
||||||
|
|
||||||
def solve(lines: Iterable[str]) -> int:
|
|
||||||
score = 0
|
|
||||||
for line in map(lambda x: x.strip(), lines):
|
|
||||||
items = len(line)
|
|
||||||
lh = compartment(line[:items//2])
|
|
||||||
rh = compartment(line[items//2:])
|
|
||||||
score += bitmap_to_priority(lh & rh)
|
|
||||||
return score
|
|
||||||
|
|
||||||
def solveb(lines: Iterable[str]) -> int:
|
|
||||||
score = 0
|
|
||||||
iterator = map(lambda x: x.strip(), lines.__iter__())
|
|
||||||
for first in iterator:
|
|
||||||
second = next(iterator)
|
|
||||||
third = next(iterator)
|
|
||||||
score += bitmap_to_priority(compartment(first) & compartment(second) & compartment(third))
|
|
||||||
return score
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
print(solve(fileinput.input()))
|
|
||||||
print(solveb(fileinput.input()))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
|||||||
|
|
||||||
import fileinput
|
|
||||||
from typing import Iterable
|
|
||||||
|
|
||||||
class Range:
|
|
||||||
|
|
||||||
rmin: int
|
|
||||||
rmax: int
|
|
||||||
length: int
|
|
||||||
|
|
||||||
def __init__(self, rang: str):
|
|
||||||
self.rmin,self.rmax = map(lambda x: int(x), rang.strip().split('-'))
|
|
||||||
self.length = self.rmax - self.rmin + 1
|
|
||||||
|
|
||||||
|
|
||||||
def solve(lines: Iterable[str]) -> int:
|
|
||||||
score = 0
|
|
||||||
for line in lines:
|
|
||||||
elf1, elf2 = map(lambda x: Range(x), line.strip().split(','))
|
|
||||||
if elf2.length > elf1.length:
|
|
||||||
elf2,elf1 = (elf1, elf2)
|
|
||||||
if elf1.rmin <= elf2.rmin and elf1.rmax >= elf2.rmax:
|
|
||||||
score += 1
|
|
||||||
return score
|
|
||||||
|
|
||||||
def solveb(lines: Iterable[str]) -> int:
|
|
||||||
score = 0
|
|
||||||
for line in lines:
|
|
||||||
elf1, elf2 = map(lambda x: Range(x), line.strip().split(','))
|
|
||||||
if elf2.length > elf1.length:
|
|
||||||
elf2,elf1 = (elf1, elf2)
|
|
||||||
if elf1.rmin <= elf2.rmax and elf1.rmax >= elf2.rmin:
|
|
||||||
score += 1
|
|
||||||
return score
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
print(solve(fileinput.input()))
|
|
||||||
print(solveb(fileinput.input()))
|
|
@ -1,6 +0,0 @@
|
|||||||
2-4,6-8
|
|
||||||
2-3,4-5
|
|
||||||
5-7,7-9
|
|
||||||
2-8,3-7
|
|
||||||
6-6,4-6
|
|
||||||
2-6,4-8
|
|
Loading…
Reference in New Issue
Block a user