sourcelibs/Combinatorics/demos/lottery.xtl

1⍝!/usr/bin/env xetal 2⍝# Lottery odds and a tiny tournament. Run with "just demo Combinatorics lottery". 3 4ᶜᵇ⁼u̲se< "Combinatorics" 5ᵗ⁼u̲se< "Strings" 6 7⍝ Choose 6 of 49: how many tickets, and the chance of matching k. 8tickets ← 6 ᶜᵇc̲hoose 49 9tickets 10k ← o̲ffsets 7 11ways ← (k ᶜᵇc̲hoose 6) × (6 − k) ᶜᵇc̲hoose 43 12ways 13(f̲loat ways) ÷ f̲loat tickets 14 15⍝ Four teams, every match once: the pairs of 4 choose 2. 16teams ← "ABCD" 17m ← 2 ᶜᵇc̲ombinations 4 18" " ᵗj̲oin '{ i → (i s̲elect m) s̲elect teams } m̲ap r̲ange t̲ally m