18
2
Challenge
For each character of the string except for the last one, do the following:
Output the current character.
Followed by randomly outputting from the following list a random number of times between 1 - 5 (inclusive):
- The current character
- The next character of the string
- The switchcase version of the character that you are currently on
- The switchcase version of the next character of the string.
Test Cases
String
--> SSSTSStrTrIiinIIngn
, . , . , . Hello world!
--> ,,, .. , ,, .... , , .. .. . HHH HHEeelLlLllooO wwOworOOrrrRllDd!!D
Programming Puzzles and Code Golf
--> PrPPrRrOooooogggRgGraAraaaMMMmmmimMIiininGGgG PPPPuZzZZzZzzZzllLLEEeEsEsssS a aANnNddD C COCoooOOdeDe E GGGoOllFFf
Notes
- You only need to apply the switchcase version of a character if the character is part of the alphabet (A-Z and a-z).
- Your random function does not need to be uniform but it still needs to have a chance of returning any element in the list given.
- You are allowed to use any standard I/O format.
- You may assume that the length of the input is greater than or equal to two.
- You may assume that the input only consists of ASCII characters.
- The title is not a test case (it is unintentional if it is a valid test case).
- Switchcase means to turn the char to lowercase if it is uppercase and to turn it to uppercase if it is lowercase.
In addition to '... does not need to be uniform', I think you probably want to specify that given some input, all finite legal outputs should in principle be possible to generate (otherwise, my non-uniform random integer in [1,2,3,4,5] is always going to be 2, and I'll just output the original string). – Chas Brown – 2019-04-03T01:21:25.347
@ChasBrown Yeah, I'll edit the question – MilkyWay90 – 2019-04-03T01:39:45.283
What options do we have as source of randomness, can we use the input string? – Expired Data – 2019-04-03T07:38:35.263
2I find the specification confusing. Can you be more explicit? For example, work out how
String
producesSSSTSStrTrIiinIIngn
– Luis Mendo – 2019-04-03T09:02:55.4677@LuisMendo I'm not OP, but I think:
[S]SSTSS [t]rT, [r]I, [i]inII, [n]gn
, where the characters between the blocks are the first bullet points ("Output the current character"), and the other characters are 1-5 times randomly one of the four choices for that character. But I agree, some more explicit explanations would be appropriate. Apart from the test case it wasn't particularly clear we have to pick a random choice 1-5 times. Instead of picking a random choice repeated 1-5 times (as the Gaia answer currently does). – Kevin Cruijssen – 2019-04-03T11:09:44.9503@KevinCruijssen Thanks, Your explanation fits the example, and is clear. The OP should confirm and edit that into the text – Luis Mendo – 2019-04-03T11:19:15.937
It took me several minutes to figure out what you meant by "switchcase version". Google didn't turn up anything. Might help to show an example on the line. – Daniel – 2019-04-03T15:05:21.953
@KevinCruijssen I will change "1 and 5" to "1 - 5" – MilkyWay90 – 2019-04-03T22:52:22.880
@LuisMendo What are you confused about? Do you have any suggestion on how to be more explicit? – MilkyWay90 – 2019-04-03T22:53:53.540
I think it's clear now. I removed my vote to close – Luis Mendo – 2019-04-04T06:23:49.923