-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday2prog1.py
More file actions
61 lines (52 loc) · 1.95 KB
/
Copy pathday2prog1.py
File metadata and controls
61 lines (52 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
##creating a checksum of all the boxes in santa's warehouse
##data contains 250 inputs and we are checking if each letter contains two identical letters or three identical letters or both and adding those sums together.
def checksum(id):
length = len(id)
#for every char
sum = 0
foundthree = 0
foundtwo = 0
for char in id:
found = 0
i = 0
while i < length - 1:
if char == id[i]:
found = found + 1
# print(str(found) + " " + str(char) + "'s")
i = i + 1
else:
i = i + 1
if found == 3 and foundthree == 0:
print("found three "+char)
foundthree = 1
elif found == 2 and foundtwo == 0:
print("found two " + char)
print("adding to triples : " +str(triples))
foundtwo = 1
sum=foundthree + foundtwo
print("the checksum for " + str(id) + "is " + str(sum))
return(foundtwo, foundthree)
##initial idea is to have a function that takes in the line, identifies if it matches none, one, or both criteria, and then outputs a checksum of 0-2 based on matches. for efficiency it should check if a match has been found before evaling the if statements to avoid checking for 2x match after finding one
##TODO: read in file
boxes = open("day2input",'r')
##TODO: loop through lines
boxids = boxes.readlines()
#keep track of the total checksum
checksumTotal = 0
triples = 0
doubles = 0
for ids in boxids:
#list of previous chars catagorized into a list of lists
tally = []
double = 0
#has it hit three?
triple = 0
print("triples : " + str(triples))
# for chars in ids:
tempdoubles,temptriples = checksum(ids)
triples = triples+temptriples
doubles = doubles + tempdoubles
checksumTotal = triples * doubles
print("the total should be 12")
print("the total is " + str(checksumTotal))
##TODO: evaluate lines char for char against the rest of the line.