EX_03/level-2/permutations/README.md

1.1 KiB

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

./permutations a

Output: a

Why? There's only one letter, so there's only one way to arrange it!

Example 2: Two Letters

./permutations ab

Output:

ab
ba

Why? We can put 'a' first or 'b' first. That's it!

Example 3: Three Letters

./permutations abc

Output:

abc
acb
bac
bca
cab
cba