Skip to content

Commit cd40d6d

Browse files
DarDar
authored andcommitted
Updated solution.py
1 parent 365d32f commit cd40d6d

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

rounds/1_histogram/solution.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44
passes out of the box. Replace the body of ``compute_histogram`` with your
55
own faster implementation.
66
"""
7+
from collections import defaultdict
78

89

910
def compute_histogram(path: str) -> dict[bytes, int]:
11+
1012
"""Frequency of every 2-byte bigram in the file at ``path``."""
11-
# TODO: remove this delegation and write your own implementation here.
12-
from .baseline import compute_histogram as _baseline
13+
counts: dict[bytes, int] = defaultdict(int)
14+
15+
with open(path, "rb") as f:
16+
data = f.read()
17+
18+
for i in range(len(data) - 1):
19+
counts[data[i:i + 2]] += 1
1320

14-
return _baseline(path)
21+
return dict(counts)

0 commit comments

Comments
 (0)