URGENT: modify character substitution code to dedup and have distance
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

we have this code
https://repl.it/repls/CompatibleZanyScience

we would like to get it modified to have a distance value next to each computed outcome that tells us how many substitutions were needed to calculate it.

next we want to dedup the list - the item that should remain is the one with the fewest transforms needed. for example

suppose we have these outcomes

abc: 1

abe: 2

abc: 3

abe: 4

we would want the final output to just have

abc: 1

abe: 2

to make things easier i think the order of operations should be

  • compute variants as it does today
  • include transform distance when coming up with the value
  • dedup as a final operation

note: we think representing the distance and value should be like this

"distance:value" whereas today we just have "value"

Please fork my repl.it codebase.

Hey, any chance that my previous solution to this does the job already? https://jsfiddle.net/Wuddrum/ypjhcm3e/7/
getPermutations function already accepts maxDistance argument. And the output can be remapped to whichever format you like.
Wuddrum 12 days ago
Which is the distance between, for example, 'go' and '6o'? Is it 1 (because the number of symbols changed is 1) or 2 (because the number of operations needed to change this symbol is 2 - g->G and G->6)?
TheOsch 12 days ago
awarded to Wuddrum
Tags
javascript

Crowdsource coding tasks.

1 Solution

Winning solution

Here's your current solution with distance and deduping: https://repl.it/repls/InbornVapidMetric

Excuse me please, but I've found a mistake in this solution. It doesn't produce all permutations. To fix it, you should change
const len = Math.pow(arr.length, 2);
to
const len = Math.pow(2, arr.length);
at line 54.
TheOsch 12 days ago
You're right, thank you for commenting!
The mistake originates from the original solution.
Wuddrum 12 days ago