Atelier des rouesLab FR
Objects/Documentation

experience.py

Runnable starter-kit experiment with an enumeration check.

Download ↓
"""Exact weighted configurations. Compare a residual-mask DP with enumeration."""
from collections import Counter
from functools import lru_cache
from itertools import product
from math import prod
import json


def compile_counter(options, bits, prune):
    full = (1 << bits) - 1
    future = [0] * (len(options) + 1)
    for i in reversed(range(len(options))):
        future[i] = future[i+1]
        for mask, weight in options[i]:
            if weight < 0 or mask < 0 or mask > full:
                raise ValueError("invalid option")

Read in context

Comments

Comments from both language editions appear here.

The discussion is open for reading. I’ll enable submissions once spam protection is configured.