10
Purpose
The idea is to provide the code necessary to map a 32-bit integer to/from a pronouncable word of 9 characters maximum. That could be useful, for example, to make a serial number easier to remember, or type in a form.
Both the method for translating an integer to the corresponding word and for translating back a word to the corresponding integer are required.
Rules
There must be a one-to-one mapping between integers and words, and the whole set of 32-bit integers (or, put in another way, any integer from 0 to 4294967295) must be mappable. Although, obviously, not all words will be meaningful, and inputting words that don't map to an integer may have unspecified behavior.
You are free to decide on exactly which set of "pronouncable" words is meaningful, and how the mapping is done, but words must at least follow these rules:
- Only the basic 26 letters (A...Z) should be used as characters. Accents, casing, etc... should not be used to extend the possible combinations.
- 9 characters maximum per word.
- two consonants (BCDFGHJKLMNPQRSTVWXZ - 20 possiblities) should not be placed next to each other (they must be surrounded by vowels).
- two vowels (AEIOUY - 6 possibilities) should not be placed next to each other (they must be surrounded by consonants).
Note: the simplest scheme where you have all words constructed as CVCVCVCVC
(C
being a consonant and V
a vowel) gives 4147200000 combinations, and a 32 bit integer has 4294967296 possible values, so it is not enough. You need to expand the number of combinations, either by allowing shorter words, or by allowing VCVCVCVCV
combinations, as well.
Other standard rules apply, and standard loopholes are forbidden.
Inputs/Outputs
For each submission, two pieces of code must be provided:
- One that takes an integer as argument/input and returns/prints the corresponding word
- One that takes a word as argument/input and returns/prints the corresponding integer
Alternatively, you can choose to submit a single piece of code that handles both operations:
- When given an integer as an input, it outputs the corresponding word
- When given a string as an input, it outputs the corresponding integer
Winning condition
This is a code-golf, the answer which has the fewest bytes (when summing both pieces of code, for solutions opting for the separated pieces of code) wins.
Are there any space or time constraints? Do we have to fit within 32GB of memory? – John Dvorak – 2017-04-06T07:47:58.743
@JanDvorak Well, we should be able to test your program on a "standard" computer. But the algorithm should be simple, what do you have in mind that requires such a massive amount of memory? – dim lost faith in SE – 2017-04-06T07:49:55.157
I could just generate all possible nine-letter words that match your formula and then index into the set or do a binary search. – John Dvorak – 2017-04-06T07:51:22.530
@JanDvorak I must admit I didn't think of that. I was more thinking about solutions that were basically doing base-26 conversions, with some adjustments to satisfy the vowel/consonant constraint. But I somehow doubt the "brutal" way you had in mind can be code-golf efficient. Anyway, if I must really clarify this, let's say you are not allowed to allocate more than 4GB of memory. – dim lost faith in SE – 2017-04-06T08:00:19.607
You could require the answerers to run their code for some predetermined values (0,1,10,2**32-1 and such) and then back and to include the results in the answer. – John Dvorak – 2017-04-06T08:03:21.910
I can't provide test sets with corresponding integers and words, since you are free to choose the mapping method. – dim lost faith in SE – 2017-04-06T08:03:38.387
Related – Peter Taylor – 2017-04-06T09:40:25.880
Am I allowed to map only a specific subset of the words, e.g. all
VCVCVCVCV
andCVCVCVCVC
words that do not start withA
? – ETHproductions – 2017-04-07T22:14:56.577@eth yes, and you are even allowed to crash if ever the input word provided is not mapped. – dim lost faith in SE – 2017-04-08T04:10:01.633