aoc

My solutions for the Advent of Code
git clone https://git.tronto.net/aoc
Download | Log | Files | Refs | README

b.py (422B)


      1 import fileinput
      2 
      3 def invk(n, k):
      4 	for i in range(0, len(n)-k, k):
      5 		if n[i:i+k] != n[i+k:i+2*k]:
      6 			return False
      7 	return True
      8 
      9 def invalid(n):
     10 	for k in range(1, len(n)//2 + 1):
     11 		if invk(n, k):
     12 			return True
     13 	return False
     14 
     15 s = 0
     16 with fileinput.input() as lines:
     17 	for line in lines:
     18 		for r in line.split(","):
     19 			l = r.split("-");
     20 			for n in range(int(l[0]), int(l[1])+1):
     21 				if invalid(str(n)):
     22 					s += n
     23 print(s)