8
1
yOu wiLl bE giVen A sTriNg wHich cOnsiSts oF pRintAble asCii cHarActErs.
yOu iTeraTe tHrougH thE sTrIng tHen chAnge rAndOM(uNifoRm, 50% cHanCe uPPercAse) lEtteRs to uPPercAse aNd eVerytHing elSe tO lOwercAse.
tHat'S iT.
(sorry for the punctuation, it was for the concept of the question)
Readable version:
You will be given a string which consists of printable ASCII characters.
You iterate through the string and change random(uniform, 50% chance uppercase) letters to uppercase, and everything else to lowercase.
that's it.
exaMplEs
iNpuT => pOssiBle oUtPUt
Programming puzzles and Code Golf => pRogRaMMiNg pUzzlEs aNd coDe goLf
dErpity deRp derP => deRpiTy dErp DerP
CAAAPSLOOOCK => cAAapslOoocK
_#$^&^&* => _#$^&^&*
2What does "randomly" mean exactly? Can there be two consecutive capital letters (your test cases don't have any such configurations)? I'd say this question is underspecified in its current state, but I'm not going to vote on it yet. Please specify these two things. – HyperNeutrino – 2017-04-07T16:02:20.170
Is time%2 allowed for pseudorandomness? – fəˈnɛtɪk – 2017-04-07T16:06:51.787
@fəˈnɛtɪk Sure (if it is uniform) – Matthew Roh – 2017-04-07T16:08:21.383
Does the code have to lowercase it first, if doing so has zero effect because of how the following code works? – Brad Gilbert b2gills – 2017-04-07T16:12:46.483
@BradGilbertb2gills it has to. – Matthew Roh – 2017-04-07T16:15:21.273
@SIGSEGV Don't contradict yourself. If you pass an all-uppercase string as input, you should still come out with a string that's derpified, right? Make that an example. – mbomb007 – 2017-04-07T16:18:22.627
@mbomb007 added. – Matthew Roh – 2017-04-07T16:20:46.753
2you say printable ASCII, but your test cases only include alphabetic characters. Should the program be able to deal with non-alphabetic characters, or can we expect the input to be purely alphabetic? – MildlyMilquetoast – 2017-04-07T16:59:09.547
5I think most of the existing answers also assume that the decision is independent for each letter, but that's nowhere in the question. At present I think it would technically be compatible with the spec to write something along the lines of (pseudocode)
s=>rand()%2?s.upper():s.lower()
– Peter Taylor – 2017-04-07T21:02:10.200@PeterTaylor I disagree with that. The challenge explicitly states to iterate through the string and change random letters, uniformly, to either uppercase or lowercase. Your pseudocode doesn't do that. – AdmBorkBork – 2017-04-10T13:01:54.070
@AdmBorkBork, I don't think the sentence which mentions randomness actually makes sense, so while I agree that your interpretation is the most likely to be the intended one I think that mine is also possible. – Peter Taylor – 2017-04-10T13:24:40.920