tinycodinglm / math /math-0060.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 15)
b27bfb3 verified
|
Raw History Blame Contribute Delete
1.35 kB
opencode trace
System 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 c...

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.

User

Explain the key concepts of combinatorics in math, with concrete details and common pitfalls. Include a runnable code example with its expected output.

Assistant

Permutations P(n,r) = n!/(n−r)! — order matters.
Combinations C(n,r) = n!/(r!(n−r)!) — order doesn't matter.

python
from math import perm, comb, factorial

# How many ways to pick 3 books from 5 and arrange them?
print(perm(5, 3))  # 60

# How many ways to pick 3 books from 5 (no order)?
print(comb(5, 3))  # 10

# Verify: 60 = 10 × 3!
print(comb(5,3) * factorial(3))  # 60

Applications:

  • Permutations: passwords, rankings, scheduling
  • Combinations: lottery, committee selection, subsets