diff --git a/2015/day5/part1.py b/2015/day5/part1.py new file mode 100644 index 0000000..218a731 --- /dev/null +++ b/2015/day5/part1.py @@ -0,0 +1,34 @@ +#!/bin/python3 + +import sys +from pprint import pprint + +input_f = sys.argv[1] + +result = 0 + +with open(input_f) as file: + for line in file: + tmp = line.rstrip() + print(tmp) + vowel_count = 0 + t = ['ab','cd','pq','xy'] + for i in t: + if tmp.find(i) != -1: + print(tmp + " is naughty because it contains " + i) + break + f = 'aeiou' + go_on = False + for idx,i in enumerate(tmp): + if idx+1 < len(tmp): + #print(idx,idx+1,len(tmp)) + if i == tmp[idx+1]: + go_on = True + if f.find(i) != -1: + vowel_count += 1 + if vowel_count == 3: + print(tmp + " is nice because it contains " + str(vowel_count) + " vowels and " + i + tmp[idx+1]) + + #cd, pq, or xy + print() +print(result) diff --git a/2015/day5/test b/2015/day5/test new file mode 100644 index 0000000..6402f21 --- /dev/null +++ b/2015/day5/test @@ -0,0 +1,5 @@ +ugknbfddgicrmopn +aaa +jchzalrnumimnmhp +haegwjzuvuyypxyu +dvszwmarrgswjxmb diff --git a/2023/day5/part2.py b/2023/day5/part2.py index 6f01ba7..3f57d4a 100644 --- a/2023/day5/part2.py +++ b/2023/day5/part2.py @@ -11,8 +11,8 @@ seeds, *maps = open(input_f).read().split('\n\n') seeds = seeds.split(':')[1].split() -pprint(seeds) -pprint(maps) +#pprint(seeds) +#pprint(maps) tmp_seeds = [] @@ -22,20 +22,23 @@ for i in range(0,len(seeds)-1,2): tmp_seeds.append(j) seeds = tmp_seeds -#print(seeds) + +total=len(seeds)*7 +count = 0 for i in maps: tmp = [] i = i.split() #print(i) - for ldx,l in enumerate(seeds): l = int(l) + count += 1 for x in range(2,len(i)-2,3): d = int(i[x]) s = int(i[x+1]) r = int(i[x+2]) #print('Looking for ' + str(l) + ' in range ' + str(s) + ' > ' + str((s+r)),end='') + print(str(round(count/total*100,2))) if s <= l and l < s + r: seeds[ldx] = d + (l - s) #print('. Found!')