44
6
For today's challenge, you must write a program or function that alternates the case of a string. However, you must ignore non-alphabetic characters. This means that every alphabetic character must have a different case than the preceding and following alphabetic character. This is slightly more complex than uppercasing every other letter for example. If you take a string such as
hello world
and convert every other character to uppercase, you'll get:
hElLo wOrLd
As you can see, the lowercase o
is followed by a lowercase w
. This is invalid. Instead, you must ignore the space, giving us this result:
hElLo WoRlD
All non-alphabetic characters must be left the same. The output can start with upper or lowercase, as long as it consistently alternates. This means the following would also be an acceptable output:
HeLlO wOrLd
Your program should work regardless of the case of the input.
The input string will only ever contain printable ASCII, so you don't have to worry about unprintable characters, newlines or unicode. Your submission can be either a full program or a function, and you may take the input and output in any reasonable format. For example, function arguments/return value, STDIN/STDOUT, reading/writing a file, etc.
Examples:
ASCII -> AsCiI
42 -> 42
#include <iostream> -> #InClUdE <iOsTrEaM>
LEAVE_my_symbols#!#&^%_ALONE!!! -> lEaVe_My_SyMbOlS#!#&^%_aLoNe!!!
PPCG Rocks!!! For realz. -> PpCg RoCkS!!! fOr ReAlZ.
This example will start with lowercase -> tHiS eXaMpLe WiLl StArT wItH lOwErCaSe
This example will start with uppercase -> ThIs ExAmPlE wIlL sTaRt WiTh UpPeRcAsE
A1B2 -> A1b2
Since this is code-golf, standard loopholes apply and the shortest answer in bytes wins!
35Ugh, I've only just realised this was that meme xD – Beta Decay – 2017-05-25T17:26:22.780
@BetaDecay Hahaha, that was not my intention. More just unfortunate timing. I though of it as a chat-mini-challenge, and I like the idea behind it because it's subtly harder than it seems.
– James – 2017-05-25T17:28:14.3834The next challenge is to print an ascii spongebob à la
cowsay
– Frambot – 2017-05-25T19:41:59.3871Darn it! I just wrote a CJam script for this (as in yesterday) and deleted it. – Esolanging Fruit – 2017-05-26T01:58:14.147
2There is some missed potential for the title or at least the examples using either penguin of doom or sporks. – Ian – 2017-05-26T06:00:06.993
Random test cases: https://tio.run/##RY9BSwMxEIXPya8Ie0qwZEERpNKTLnqQFWzBQykSs1M3kk3CJEvtr1@Tbqs5zTzy3vcmHFPv3c00rZt207QPzZqt2O09e2nap81znu9ofmYIHhND5To/XDaTAJP3NlL6/vr2WIw@gONVPUasY68Q6s7oVB88drESEkF1XMgYrEnWOIhc0L1H9sGMK9lfwGesWFKCEEebcmZVUeLG4RMwL39MqY/aAp9d10JQontvNMTiYJX89sbxua@Magj576nk4nxZcRS2zjUL/uzOYGL2J1WaqGzoFRdLltVLoasV28aE0voD4IKVcQwBcLd18JP43FTseInIDAI2wpL9m4tOSUDjEp9VQek0/QI
– connectyourcharger – 2019-07-16T15:08:13.933