Skip to content

Commit c7deed3

Browse files
committed
Changed to byte.split
1 parent e9e4a8d commit c7deed3

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

pyconus-2026-tutorial

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 349122da821fd0f69f7fc330af0a938d92b58ecb

rounds/1_histogram/solution.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@
44
passes out of the box. Replace the body of ``compute_histogram`` with your
55
own faster implementation.
66
"""
7-
8-
7+
import numpy as np
8+
99
def compute_histogram(path: str) -> dict[bytes, int]:
10+
1011
"""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
1312

14-
return _baseline(path)
13+
data = np.fromfile(path, dtype=np.uint8)
14+
15+
if len(data) < 2:
16+
17+
return {}
18+
19+
bigrams = (data[:-1].astype(np.uint16) << 8) | data[1:]
20+
21+
counts = np.bincount(bigrams, minlength=65536)
22+
23+
return {bytes([idx >> 8, idx & 0xFF]): int(count) for idx, count in enumerate(counts) if count > 0}
24+
25+

rounds/3_dna/solution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .baseline import find_matches as _baseline
99

1010

11-
def find_matches(fasta_path: str, pattern: bytes) -> list[tuple[str, list[int]]]:
11+
def find_matches(fasta_path: str, pattern: bytes.split) -> list[tuple[str, list[int]]]:
1212
"""Find every FASTA record whose sequence contains ``pattern``.
1313
1414
Returns ``[(record_id, [positions...]), ...]`` in file order.

0 commit comments

Comments
 (0)