Selaa lähdekoodia

Delete 04a-jpaul.py

Not my code, added accidentally
master
Noëlle Anthony 6 vuotta sitten
vanhempi
commit
47dac2846c
No account linked to committer's email address
1 muutettua tiedostoa jossa 0 lisäystä ja 38 poistoa
  1. 0
    38
      04a-jpaul.py

+ 0
- 38
04a-jpaul.py Näytä tiedosto

@@ -1,38 +0,0 @@
from collections import defaultdict
lines = open('04in.txt').read().split('\n')
lines.sort()

def parseTime(line):
words = line.split()
date, time = words[0][1:], words[1][:-1]
return int(time.split(':')[1])

C = defaultdict(int)
CM = defaultdict(int)
guard = None
asleep = None
for line in lines:
if line:
time = parseTime(line)
if 'begins shift' in line:
guard = int(line.split()[3][1:])
asleep = None
elif 'falls asleep' in line:
asleep = time
elif 'wakes up' in line:
for t in range(asleep, time):
CM[(guard, t)] += 1
C[guard] += 1

def argmax(d):
best = None
for k,v in d.items():
print("{}: {}".format(k,v))
if best is None or v > d[best]:
best = k
return best

best_guard, best_min = argmax(CM)
print (best_guard, best_min)

print (best_guard * best_min)

Loading…
Peruuta
Tallenna