EX_03/level-2/permutations/README.md

57 lines
1.1 KiB
Markdown

# Permutations
## What is a Permutation?
Imagine you have some letters, like the letters in your name. A **permutation** is just a fancy word for "all the different ways you can arrange those letters."
Think of it like this:
- If you have the letters **A** and **B**, you can arrange them as **AB** or **BA**
- If you have **A**, **B**, and **C**, you can make **ABC**, **ACB**, **BAC**, **BCA**, **CAB**, **CBA**
It's like having alphabet blocks and seeing how many different words you can spell by changing the order!
## The Challenge
Your mission is to write a program that:
1. Takes a word (like "abc")
2. Shows ALL possible ways to rearrange the letters
3. Shows them in **alphabetical order** (like in a dictionary)
## Real Examples
Let's see what our program does:
### Example 1: Single Letter
```bash
./permutations a
```
**Output:** `a`
*Why?* There's only one letter, so there's only one way to arrange it!
### Example 2: Two Letters
```bash
./permutations ab
```
**Output:**
```
ab
ba
```
*Why?* We can put 'a' first or 'b' first. That's it!
### Example 3: Three Letters
```bash
./permutations abc
```
**Output:**
```
abc
acb
bac
bca
cab
cba
```