Finished 2023-12-04 part 2. had to get help
This commit is contained in:
parent
e0a188f7c8
commit
4f0bb12164
3
2023/day4/exp
Normal file
3
2023/day4/exp
Normal file
@ -0,0 +1,3 @@
|
||||
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
|
||||
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
|
||||
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
|
@ -20,6 +20,58 @@ def calc_double(x):
|
||||
tmp = tmp*2
|
||||
return tmp
|
||||
|
||||
def find_match(x):
|
||||
return len(list(set(x[1]) & set(x[2])))
|
||||
|
||||
def total_cards_won(x):
|
||||
input()
|
||||
new = []
|
||||
print(x)
|
||||
global result
|
||||
matches = find_match(x)
|
||||
result += matches
|
||||
#print(x[0][1])
|
||||
for i in range(int(x[0][1]),matches+int(x[0][1])):
|
||||
if i < len(cards):
|
||||
new.append(cards[i])
|
||||
else:
|
||||
print('error')
|
||||
print("Won the following cards (" + str(matches) + " matches) ")
|
||||
#pprint(new)
|
||||
#print("getting cards in range: " + str(x[0][1]) + ' to ' + str(int(x[0][1]) + matches))
|
||||
#print("result: "+ str(result))
|
||||
pprint(new)
|
||||
for i in new:
|
||||
return total_cards_won(i)
|
||||
|
||||
"""
|
||||
for i in new:
|
||||
print('printing card nr ' + str(i+1) + " at spot " + str(i))
|
||||
if (i+1) >= len(cards):
|
||||
return
|
||||
print(cards[i])
|
||||
#print(cards[i+int(x[0][1])][0][1])
|
||||
tmp = find_match(cards[i])
|
||||
print(i+tmp,len(cards))
|
||||
print("^ card has " + str(tmp) + " matches")
|
||||
if tmp != 0:
|
||||
#card_nr = int(cards[i][0][1])
|
||||
print(len(cards))
|
||||
#if 1 + tmp + i >= len(cards):
|
||||
# print('error')
|
||||
# return
|
||||
#else
|
||||
print("^^ has matches in range " + str(i+1) + " to " + str(i+tmp+1))
|
||||
for j in range(i+1, i+ tmp + 1):
|
||||
print(cards[j])
|
||||
return total_cards_won(cards[j])
|
||||
else:
|
||||
return
|
||||
"""
|
||||
from collections import defaultdict
|
||||
|
||||
val = defaultdict(int)
|
||||
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
tmp = line.replace(':','|').rstrip()
|
||||
@ -30,9 +82,33 @@ with open(input_f) as file:
|
||||
for jdx,j in enumerate(i):
|
||||
cards[idx].append(j.split())
|
||||
|
||||
for x in cards:
|
||||
match = list(set(x[1]) & set(x[2]))
|
||||
if len(match) != 0:
|
||||
result = result + int(calc_double(match))
|
||||
for xdx,x in enumerate(cards):
|
||||
val[xdx] += 1
|
||||
print("====Original====")
|
||||
#tmp = find_match(x)
|
||||
#print("Found " + str(tmp) + " matches in ",end="")
|
||||
#print(cards[xdx][0])
|
||||
#print(">>")
|
||||
#result += 1
|
||||
#if tmp != 0:
|
||||
#total_cards_won(x)
|
||||
#print("index " + str(xdx))
|
||||
for i in range(find_match(x)):
|
||||
#print("match nr " + str(i) + " in " + str(xdx))
|
||||
#print(val[xdx])
|
||||
#print(val)
|
||||
val[xdx+i+1] += val[xdx]
|
||||
"""
|
||||
for y in range(0,tmp):
|
||||
if (xdx + int(cards[xdx][0][1])+y) < len(cards):
|
||||
print(cards[xdx+int(cards[xdx][0][1])+y])
|
||||
|
||||
result += 1
|
||||
"""
|
||||
|
||||
|
||||
|
||||
|
||||
print(sum(val.values()))
|
||||
#print(find_match(x))
|
||||
|
||||
print(result)
|
||||
|
Loading…
Reference in New Issue
Block a user