File size: 1,345 Bytes
b27bfb3 | 1 2 3 4 5 | {"type": "session", "harness": "opencode", "id": "math-0060", "name": "combinatorics"}
{"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}}
{"type": "message", "message": {"role": "user", "content": "Explain the key concepts of combinatorics in math, with concrete details and common pitfalls. Include a runnable code example with its expected output."}}
{"type": "message", "message": {"role": "assistant", "content": "**Permutations** P(n,r) = n!/(n−r)! — order matters.\n**Combinations** C(n,r) = n!/(r!(n−r)!) — order doesn't matter.\n\n```python\nfrom math import perm, comb, factorial\n\n# How many ways to pick 3 books from 5 and arrange them?\nprint(perm(5, 3)) # 60\n\n# How many ways to pick 3 books from 5 (no order)?\nprint(comb(5, 3)) # 10\n\n# Verify: 60 = 10 × 3!\nprint(comb(5,3) * factorial(3)) # 60\n```\n\n**Applications:**\n- Permutations: passwords, rankings, scheduling\n- Combinations: lottery, committee selection, subsets"}}
|