Skip to content

Commit 8b3c68e

Browse files
committed
test 1
1 parent bf2bf4b commit 8b3c68e

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

rounds/1_histogram/solution.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
passes out of the box. Replace the body of ``compute_histogram`` with your
55
own faster implementation.
66
"""
7+
import numpy as np
78

89

910
def compute_histogram(path: str) -> dict[bytes, int]:
@@ -15,11 +16,16 @@ def compute_histogram(path: str) -> dict[bytes, int]:
1516
# Step 2: slide a 2-byte window across the buffer. For ``b"ABCD"`` the
1617
# iterations produce ``b"AB"``, ``b"BC"``, then ``b"CD"``. For each window,
1718
# bump the matching bucket in a ``dict`` keyed by the bigram itself.
18-
counts: dict[bytes, int] = {}
19+
counts= [[0] * 256 for _ in range(256)]
20+
1921
for i in range(len(data) - 1):
20-
bigram = data[i : i + 2]
21-
if bigram in counts:
22-
counts[bigram] += 1
23-
else:
24-
counts[bigram] = 1
25-
return counts
22+
a, b = data[i], data[i + 1]
23+
counts[a][b] += 1
24+
25+
result = {}
26+
for i, row in enumerate(counts):
27+
for j, count in enumerate(row):
28+
if count > 0:
29+
bigram = bytes([i, j])
30+
result[bigram] = count
31+
return result

0 commit comments

Comments
 (0)