Share your repls and programming experiences

← Back to all posts
#WEEKLY 18 word order
AIDENSANDBAKKEN (2)

The easy way to do this is listing out all combinations and searching through them all.
That works fine when the input has 3 letters and 15 combinations, but not so well when it has 26 letters and 1096259850353149530222034276 combinations, so I used a mathematical approach so the code can efficiently calculate the results so long as the input is less than 32 letters long. Note: the code assumes a valid input. An invalid input will most likely, but not definitely cause it to panic.

Commentshotnewtop
TheDrone7 (1504)

Doesn't seem to be working properly. When entered the key abc and subset ac, index comes out to be 7 while the desired result is 4

AIDENSANDBAKKEN (2)

@TheDrone7 dang it, I thought I had all the bugs worked out.

Coder100 (12439)

Wait why isn't ad inside pad?

The permutations are

0. a
>> 1. ad <<
2. adp
3. ap
4. apd
5. d
6. da
7. dap
8. dp
9. dpa
10. p
11. pa
12. pad
13. pd
14. pda

(I totally hand-wrote that)

AIDENSANDBAKKEN (2)

@Coder100 I don't know, it's working when I do it and correctly coming up with 2 (it's 1 indexed). You must have mistyped the key. Also, you do have to retype the key after getting an answer.