From 2938bac2a3c08ba9f79baa9ae8441e168579d1fc Mon Sep 17 00:00:00 2001 From: majestic-owl448 <26656284+majestic-owl448@users.noreply.github.com> Date: Thu, 18 Dec 2025 15:47:00 +0100 Subject: [PATCH] improve permutation generator description (#64723) Co-authored-by: Dario <105294544+Dario-DC@users.noreply.github.com> --- .../66fe4f33a2cc9b33f4d5cd9b.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/curriculum/challenges/english/blocks/lab-permutation-generator/66fe4f33a2cc9b33f4d5cd9b.md b/curriculum/challenges/english/blocks/lab-permutation-generator/66fe4f33a2cc9b33f4d5cd9b.md index 5cbf30db7cc..dc9fb6a7324 100644 --- a/curriculum/challenges/english/blocks/lab-permutation-generator/66fe4f33a2cc9b33f4d5cd9b.md +++ b/curriculum/challenges/english/blocks/lab-permutation-generator/66fe4f33a2cc9b33f4d5cd9b.md @@ -9,12 +9,20 @@ dashedName: build-a-permutation-generator In this lab, you will build a permutation generator that will take a string and return all possible permutations of the characters in the string. For example, the possible permutations of the string `cat` are `cat`, `cta`, `act`, `atc`, `tac`, and `tca`. +The recursive way of creating permutations of a string works by storing the fixed starting part of the string (prefix), and creating permutations of the rest. + +For example, let's consider the word `machine`. The first round of creating permutations would be made fixing the `m` as the prefix of the string, and then creating permutations of the rest of the string, `achine`. + +For the rest of the string, permutations continue in the same way. One letter is added to the prefix, maybe the `c`, so the prefix becomes `mc`. Then, each of the permutations of `ahine` is concatenated to the prefix. + +This continues until the prefix has all the letters, and the rest of the string is empty, that means one permutation has been created. + **Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab. **User Stories:** 1. You should create a function named `permuteString`. -2. The `permuteString` function should take three parameters- a string, a prefix value and an empty array for storing and returning the results. The prefix value would accumulate characters to form a permutation. +2. The `permuteString` function should take three parameters: a string, a prefix value and an empty array for storing and returning the results. The prefix value should be a string used to accumulate characters to form a permutation. 3. Inside the function, you should check if the length of the passed string is `0`. If it is, push the current prefix to the results and return the results. 4. Iterate over each character in the input string and for each iteration, remove the current character from the string and call the `permuteString` function recursively with updated arguments to build the remaining permutations. 5. You should return the final results array.