17
2
In one of our projects at work, we recently discovered a particularly large method for generating a 6 character string from a 15 character alphabet. A few of us claimed "I bet we can get that in one line" which started a little internal game of code golf.
Your task is to beat us, which I have no doubt won't take long!
The original algorithm used the alphabet 0-9A-E, but we've experimented with other alphabets. There are therefore three subtasks.
- Generate a
6
character string randomly selecting from an arbitrary hardcoded15
character alphabet likeABC123!@TPOI098
. (This is just an example, and should be customizable without affecting the byte count.) - Generate a
6
character string randomly selecting from a15
character alphabet0123456789ABCDE
. - Generate a
6
character string randomly selecting from a15
character alphabet of your choice (printable characters only please).
Each character should have equal chance of selection and repetition should be possible.
The best we have been able to manage for each of the subtasks is:
- "ABC123!@TPOI098" -
24 bytes
- "0123456789ABCDE" -
21 bytes
- Custom alphabet -
13 bytes
Your score is the sum of the bytes in each subtask's solution. i.e. our score is currently 58.
We've attempted using among others, CJam and Ruby. The original was in C#. Use any language you like, but we'll be interested to see solutions in these languages particularly
5Regarding multi-part challenges. Unfortunately, I don't have a good solution in this case, since these three subtasks are way too similar for it to make sense to split them up into multiple challenges. I've also been considering proposing an exception to that policy for multi-part challenges where the subtasks are just minor variations of the same challenge. (Although that still has the problem that sub-solutions can be taken from other answers.) So I won't mod-hammer this, and see what the community thinks. – Martin Ender – 2016-10-15T13:51:20.870
"Your score is the sum of the bytes..." so my first example is unfortunate. I'll amend to another potential example – James Webster – 2016-10-15T14:11:03.277
2
@MartinEnder My 2 cents: I think it's OK and will not VTC. Sure, I generally think a challenge with a single interesting task is better, but since these tasks are very similar, it's a lot better than a "golf-course" that says "do these 8 random unrelated tasks." Even though there is no interaction between tasks, in my eyes this challenge is not very different than say Golf all 16 logic gates.
– James – 2016-10-15T14:41:37.440Are there any time or memory limits? Do the subtasks have to be independent or are they allowed to share code? – Dennis – 2016-10-15T14:41:55.980
@DJMcMayhem Yes, that is actually the challenge which made me consider the exception I mentioned. I just didn't get around to sorting out my thoughts on the matter yet. – Martin Ender – 2016-10-15T14:43:31.017
Borderline dupe – Peter Taylor – 2016-10-15T14:45:56.370
2Does "generate a string" mean the code has to actually generate a string value with the appropriate characters in it, or is outputting the six characters (not separated by space or newlines) acceptable? – DLosc – 2016-10-15T19:17:19.477
Maybe I’m being dense here, but how can the character alphabet possibly be customisable without affecting the byte count? Wouldn’t changing the character set from
0123456789ABCDE
to0123456789x̃ᾖत्रुँֆ齉
increase the byte count by definition (unless the encoding uses 4 bytes for all characters)? Or is ‘character’ here to be taken to refer to single-byte ASCII characters only? – Janus Bahs Jacquet – 2016-10-16T13:19:49.493