diff --git a/README.md b/README.md index 44e0723..1d3c3e4 100644 --- a/README.md +++ b/README.md @@ -91,3 +91,4 @@ scripts/ ``` Each round's `data/` directory is generated locally and gitignored. +This is mlv's PR diff --git a/rounds/1_histogram/solution.py b/rounds/1_histogram/solution.py index dffbee5..71b99e6 100644 --- a/rounds/1_histogram/solution.py +++ b/rounds/1_histogram/solution.py @@ -9,6 +9,21 @@ def compute_histogram(path: str) -> dict[bytes, int]: """Frequency of every 2-byte bigram in the file at ``path``.""" # TODO: remove this delegation and write your own implementation here. - from .baseline import compute_histogram as _baseline + with open(path, "rb") as f: + data = f.read() - return _baseline(path) + counts = [] + for ii in range(256): + counts.append([]) + for jj in range(256): + counts[ii].append(0) + + for ii in range(len(data) - 1): + counts[data[ii]][data[ii+1]] += 1 + + d = {} + for rr in range(256): + for cc in range(256): + if counts[rr][cc] > 0: + d[bytes((rr,cc))] = counts[rr][cc] + return d