Bug or limitation? Returns same result after a while.
Closed this issue · 4 comments
I tried out the library through your blog post:
https://fasiha.github.io/post/mudder/
Using the second live code box, the one that starts with:
console.log(mudder.alphabet.mudder('anhui', 'azazel', 3))
// [ 'aq', 'at', 'aw' ]
I tried beginning with:
console.log(mudder.alphabet.mudder('a', 'z', 1))
which gives:
Array [
"m",
]
I then try replacing the 'z' with 'm':
console.log(mudder.alphabet.mudder('a', 'm', 1))
which then gives:
Array [
"g",
]
I then I replace the 'm' with 'g', and I keep doing this. Finally I will get
console.log(mudder.alphabet.mudder('a', 'aaa', 1))
which gives:
Array [
"aaa",
]
which is the same as the input !?
So I can not go any further. This is only after about 9-10 iterations.
I'm guessing you need to tweak the algorithm to not allow consecutive aa characters or something as m69 said here:
https://stackoverflow.com/questions/38923376/return-a-new-string-that-sorts-between-two-given-strings/38927158#comment65214144_38924120
Starting with
console.log(mudder.alphabet.mudder('m', 'y', 1))
and replacing the result into 'y' will also end at:
console.log(mudder.alphabet.mudder('m', 'maa', 1))
giving
Array [
"maa",
]
Thank you so much for this!!! I'm so sorry, this bug was so stupid. I fixed it, if you now run the following
let r = 'z';
for (let i = 0; i < 50; i++) {
r = mudder.alphabet.mudder('a', r)[0];
console.log(r);
}
at https://fasiha.github.io/post/mudder/ you should get the expected behavior.
Thanks especially for digging into this so much, even going so far as to check out m69's original post 😲🙌! Sorry the code is a little tricky to understand, the bug was caused by a micro-optimization I added at the last minute before publishing the code, and failed to realize that it would have a huge impact. That optimization can probably be massaged into working again but I just removed it since the library doesn't really need it (currently 😶).
Thanks for the fix!