

be directly shown as pixels in the display. On the specified emulator, this is in video memory, so tbe results will Based on BASIC QB64 unoptimized version: NMOS version of the 6502, but should work with any version. Written for the original MOS Technology, Inc. 100 DOORS in 6502 assembly language for: You have fewer combinations than permutations. Combinations sound simpler than permutations, and they are. P(10,3) = 720.ĭon’t memorize the formulas, understand why they work. Permutation: Listing your 3 favorite desserts, in order, from a menu of 10. Permutation: Picking a President, VP and Waterboy from a group of 10. Here’s a few examples of combinations (order doesn’t matter) from permutations (order matters).Ĭombination: Picking a team of 3 people from a group of 10. Writing this out, we get our combination formula, or the number of ways to combine k items from a set of n: Which means “Find all the ways to pick k people from n, and divide by the k! variants”. In our case, we get 336 permutations (from above), and we divide by the 6 redundancies for each permutation and get 336/6 = 56. If we want to figure out how many combinations we have, we just create all the permutations and divide by all the redundancies. So, if we have 3 tin cans to give away, there are 3! or 6 variations for every choice we pick. If you have N people and you want to know how many arrangements there are for all of them, it’s just N factorial or N! Wait a minute… this is looking a bit like a permutation! You tricked me! So we have $3 * 2 * 1$ ways to re-arrange 3 people. Well, we have 3 choices for the first person, 2 for the second, and only 1 for the last. For a moment, let’s just figure out how many ways we can rearrange 3 people. This raises an interesting point - we’ve got some redundancies here. Either way, they’re equally disappointed. If I give a can to Alice, Bob and then Charlie, it’s the same as giving to Charlie, Alice and then Bob. Well, in this case, the order we pick people doesn’t matter. How many ways can I give 3 tin cans to 8 people? In fact, I can only afford empty tin cans. Let’s say I’m a cheapskate and can’t afford separate Gold, Silver and Bronze medals. If we have n items total and want to pick k in a certain order, we get:Īnd this is the fancy permutation formula: You have n items and want to find the number of ways k items can be ordered:Ĭombinations are easy going. Where 8!/(8-3)! is just a fancy way of saying “Use the first 3 numbers of 8!”. What’s another name for this? 5 factorial!Īnd why did we use the number 5? Because it was left over after we picked 3 medals from 8. This is where permutations get cool: notice how we want to get rid of $5 * 4 * 3 * 2 * 1$. Unfortunately, that does too much! We only want $8 * 7 * 6$. To do this, we started with all options (8) then took them away one at a time (7, then 6) until we ran out of medals. The total number of options was $8 * 7 * 6 = 336$. We picked certain people to win, but the details don’t matter: we had 8 choices at first, then 7, then 6. Silver medal: 7 choices: B C D E F G H.Gold medal: 8 choices: A B C D E F G H (Clever how I made the names match up with letters, eh?).We’re going to use permutations since the order we hand out these medals matters. How many ways can we award a 1st, 2nd and 3rd place prize among eight contestants? (Gold / Silver / Bronze) We’re using the fancy-pants term “permutation”, so we’re going to care about every last detail, including the order of each item. Let’s start with permutations, or all possible ways of doing something.
