0

So I have an array that looks like this

[1, 2, 3, 4, 5, 6, 7, 8]

It can be shuffled in any way like so

[6, 3, 4, 7, 1, 2, 8, 5]

How do I make a function that has a unique index for every possible configuration of these 8 elements? emphasized text(kind of like generating hashes) I've been trying to think of a way, and I can't seem to find it. Thanks for any advice!

5
  • I means, you could just concatenate the digits. 63471285. Commented Aug 17, 2023 at 3:51
  • @RaymondChen what happens on a list like [1, 11]? Commented Aug 17, 2023 at 6:01
  • @derpirscher I assumed the starting array was always "the numbers 1 through N". If it could be an arbitrary set of distinct numbers, you can rename the values so the smallest value is called 1, the next-smallest value is called 2, etc. Commented Aug 17, 2023 at 13:31
  • @RaymondChen what if you have more than 10 values? Commented Aug 17, 2023 at 14:12
  • @derpirscher use two digits! Commented Aug 17, 2023 at 14:25

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.