I'm searching for an algorithm but struggle to find anything, as I'm not sure how to formulate it correctly. I created a simple survey app in Angular with 24 questions and each has 2-5 answers. When the user answered all the questions I'd like to give him a token (as short as possible) on the result page that he can note down, so the next time he can enter the token instead of having to answer all the questions again.
My thought process so far:
- I can store the information in an array with 24 entries
[1, 4, 2, ..., 2, 3]
- As all values have 1 digit I can remove everything but the numbers
This still leaves me with a 24 digits long number. Nothing one would like to note down and type out by hand. So next I tried to convert this number (with ().toString(2)) to a binary with the goal to turned that binary into a human readable string with String.fromCharCode. But all I got was the rather not so human readable
æ\u000f\u0000³KH\u0000\u0000\u0000 for my test input.
I could break down the number into digit pairs (e.g. 120422... -> [12, 04, 22, ...]) and map each of these to a character (00 -> A, 01 -> B, ...), but I think there must be something more elegant and efficient, as it would only half the original size. Although using 3 digits for mapping would result in 125 combinations which is rather hard to map to the alphabet, even with upper/lowercases and special characters. But I'd be very happy to hear your ideas. Many thanks in advance!