Ver código fonte

Delete 04a-jpaul.py

Not my code, added accidentally
master
Noëlle Anthony 6 anos atrás
pai
commit
47dac2846c
Nenhuma conta vinculada ao e-mail do autor do commit
1 arquivos alterados com 0 adições e 38 exclusões
  1. 0
    38
      04a-jpaul.py

+ 0
- 38
04a-jpaul.py Ver arquivo

@@ -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)

Carregando…
Cancelar
Salvar