mirror of
https://github.com/thib8956/advent-of-code.git
synced 2025-08-24 00:11:57 +00:00
chore: create new project structure and aoc.py runner script
This commit is contained in:
24
adventofcode/2020/day2/part1.py
Normal file
24
adventofcode/2020/day2/part1.py
Normal file
@@ -0,0 +1,24 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
|
||||
def parse_line(line):
|
||||
repeat_range, letter, pwd = line.split(' ')
|
||||
letter = letter[0]
|
||||
repeat_min, repeat_max = repeat_range.split('-')
|
||||
repeat_min, repeat_max = int(repeat_min), int(repeat_max)
|
||||
return letter, range(repeat_min, repeat_max + 1), pwd
|
||||
|
||||
|
||||
def test_password(line):
|
||||
letter, repeat_range, pwd = parse_line(line)
|
||||
count = pwd.count(letter)
|
||||
return count in repeat_range
|
||||
|
||||
|
||||
def main(passwds):
|
||||
valid_counter = 0
|
||||
for l in passwds:
|
||||
if test_password(l):
|
||||
valid_counter += 1
|
||||
print(f"Number of valid password in input : {valid_counter}")
|
||||
|
Reference in New Issue
Block a user