Freecodecamp: No repeats please: permutation issues

Created on 30 Jul 2015  Â·  12Comments  Â·  Source: freeCodeCamp/freeCodeCamp

In the bonfire problem, it states:

Return the number of total permutations of the provided string that don't have repeated consecutive letters.
For example, 'aab' should return 2 because it has 6 total permutations, but only 2 of them don't have the same letter (in this case 'a') repeating.

I believe this is incorrect.

The possible permutations of 'aab' are 'aab' 'aba' and 'baa' which should be calculated as 3! / 2! (= 3), not 3! (= 6) as what was done in the description. The total number of permutations should be 3 not 6. Then you want to eliminate cases wherein identical letters are adjacent, namely, 'aab' and 'baa'. This leaves 'aba' which means the answer ought to be 1, not 2.

Let me give another example. For the string 'aabb', the possible permutations ought not be calculated as 4! (=24) then eliminate the ones with adjacent identical characters. This leads to an incorrect answer of 8.

The possible permutations of 'aabb' is actually just 6, namely 'aabb', 'abab', 'baba', 'bbaa', 'abba', 'baab'. This can also be calculated 4! / (2! * 2!) (=6). Then when the strings wherein there are adjacent identical characters are eliminated, this leaves 'abab' and 'baba' which means the answer is 2 (not 8 as the test case indicates).

Please advise. Apologies if this is deemed a spam

Most helpful comment

What is the status on this? I am currently attempting to solve this, and agree "aba" and "aba" are the same permutation. This inconsistency makes what could be a mathematically beautiful solution a mess.

All 12 comments

@rcitaliano , I believe a permutation is a type of combination, i.e. an ordered
combination. In the link provided in the bonfire description, you can read
the difference between them.
On Jul 30, 2015 4:09 AM, "rcitaliano" [email protected] wrote:

what you are describing is "combination" and not "permutation"

—
Reply to this email directly or view it on GitHub
https://github.com/FreeCodeCamp/freecodecamp/issues/1418#issuecomment-126341315
.

I think the test cases are considering each of the repeated letters as individual instances that just happen to be equal to the same value. So a more accurate description would be the number of permutations of instances that don't have same consecutive values. For example:
"aab" really equals a(1), a(2), b. Possible combinations would be:
a(1) a(2) b
a(2) a(1) b
a(1) b a(2)
a(2) b a(1)
b a(1) a(2)
b a(2) a(1)

Substitute objects with identical values: the objects values are the same, but in memory, each object is its own unique instance.

I agree, however, that this is confusing and may not be the intention. Or maybe it is, just to increase the difficulty of the exercise.

It'll be less confusing for the students if FCC just says n! (n factorial) rather than pointing them to a not-so-good article about permutations and combinations. I had to research this and found a much better article from MIT called the fine art of counting. It's a combinatorics paper written for high school students.

Anyway, I'm closing this issue since I now actually know what FCC is trying to describe. It seems strange that a(1) a(2) are considered identical (in spite of using a subscript) when they're adjacent, but different when they're not adjacent, as in the sequence [a b a] -- inconsistent. Incidentally, anyone can go to wolframalpha.com and put in these commands: Permutations[{a, a, b, b}] or Permutations[{a, a, b}]. Examine the results.

I agree with alf808. no one is calculating it the way FCC is. the lecture notes from MIT show how to do this a very simplified manner. There are severeal examples of this on the web and none of them follow FCC. I think this should be re-opened.

Agreeing here. I figured it out only after banging my head against the wall and reading multiple math arictles on the subject... and then this thread. The question is simply worded poorly and makes the assertion statements even more confusing. Even with all of that, no one is going to want to refactor/rewrite their properly working code for permutations into this thingy without hacking and napkin math.

I don't _think_ that was intended. But I could be wrong. Who knows?

This is really disappointing as nobody has updated the questions and more and more people are wasting a lot time on something very confusing and misleading...

@alf808 @jaybot7 @stt106 @HexORSist I am not sure why the issue was closed (no explanation was given by the camper who closed it). It sounds like many people agree that the wording on this challenge is a problem.

I apologize that this issue was closed. We should absolutely reword it.

What should the new wording be? Would anyone like to create a pull request with suggested edits? The challenge is located here: https://github.com/FreeCodeCamp/FreeCodeCamp/blob/staging/seed/challenges/01-front-end-development-certification/advanced-bonfires.json

I originally opened this issue in July 2015. After having posted, I received petulant emails that I was spamming them or being impertinent. I personally closed the case the day after I posted in order to avoid abuse. Some posters who commented on this issue have deleted their posts. alf

Mmm I think I've fixed this with #6798 a while ago. I added clarification on duplicate letters each being unique and gave an example of where those numbers like 2 and 6 come from. Closing this issue unless someone else thinks this isn't resolved.

this statement in your rewording solution: Assume that duplicate characters
are each unique. is oxymoronic -- duplicate and unique. It's the opposite
of a clarification.

On Wed, Apr 6, 2016 at 8:11 AM, Eric Leung [email protected] wrote:

Mmm I think I've fixed this with #6798
https://github.com/FreeCodeCamp/FreeCodeCamp/pull/6798 a while ago. I
added clarification on duplicate letters each being unique and gave an
example of where those numbers like 2 and 6 come from. Closing this issue
unless someone else thinks this isn't resolved.

—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/FreeCodeCamp/FreeCodeCamp/issues/1418#issuecomment-206496552

@alf808 fair enough. It does appear to be an oxymoron. I'll change make a change. Hopefully this'll clear up any future confusion.

What is the status on this? I am currently attempting to solve this, and agree "aba" and "aba" are the same permutation. This inconsistency makes what could be a mathematically beautiful solution a mess.

Was this page helpful?
0 / 5 - 0 ratings