GAP_MAX)))\n return gap.mean(), gap.std(), fail\nmc_mean, mc_sd, mc_fail = monte_carlo()\nprint(f'MC: mean={mc_mean:.3f} sigma={mc_sd:.3f} out-of-spec={mc_fail:.4%}')","label":"3 — Monte-Carlo 5000 (seed 303)"},{"code":"# Your typed predictions (EDIT to match what you computed):\ntyped_wc_sum = HOUSING[1] + sum(p[1] for p in PARTS.values())\ntyped_rss = float(np.sqrt(HOUSING[1]**2 + sum(p[1]**2 for p in PARTS.values())))\nref_wc = HOUSING[1] + sum(p[1] for p in PARTS.values())\nref_rss = float(np.sqrt(HOUSING[1]**2 + sum(p[1]**2 for p in PARTS.values())))\n\nproblems = []\nguaranteed = (wc[0] >= GAP_MIN) and (wc[1] <= GAP_MAX)\nif not guaranteed:\n problems.append(f'worst-case gap [{wc[0]:.3f},{wc[1]:.3f}] leaves the {GAP_MIN}-{GAP_MAX} window - tighten the largest contributor (spacer) until worst-case low >= 0.10.')\nif abs(typed_wc_sum-ref_wc) > 0.005:\n problems.append('typed worst-case sum is off - it is the LINEAR sum of tolerances.')\nif abs(typed_rss-ref_rss) > 0.005:\n problems.append('typed RSS is off - square each tol, add, then square-root.')\ncheapest = (1/0.06) # tightening spacer alone reference cost share\n\nif guaranteed and abs(typed_wc_sum-ref_wc)<=0.005 and abs(typed_rss-ref_rss)<=0.005:\n print(f'PASS - worst-case gap guaranteed in [{GAP_MIN},{GAP_MAX}], wc_sum={ref_wc:.3f}, '\n f'rss={ref_rss:.3f}. RSS < worst-case because independent errors rarely all hit extreme together.')\nelse:\n print('FAIL - ' + ' '.join(problems[:2]))","label":"4 — Autograder (seed 303)"}],"intro":"Both stack methods plus a deterministic 5000-draw Monte-Carlo, exactly as the autograder uses. Edit the tolerances to guarantee the fit.","key":"manufacturing/tolerance-stack-up","kind":"python","title":"Tolerance stack-up"}">
PYTHON · NUMPY · IN-BROWSER
Tolerance stack-up
Both stack methods plus a deterministic 5000-draw Monte-Carlo, exactly as the autograder uses. Edit the tolerances to guarantee the fit.