# Question
Title: DON'T... do NOT lowercase UPPERCASE this!
Write a program that outputs its input unchanged. However:

* If all uppercase characters are removed from the program, it lowercases all uppercase letters.
* If all lowercase characters are removed from the program, it uppercases all lowercase letters.

Transforming characters beyond the basic Latin `[A-Za-z]` range is optional, but any character with both uppercase and lowercase counterparts within Unicode (`Ñ`/`ñ`, `Ω`/`ω`, etc.) qualifies for "removal" from your program.

In your answer, please specify the character encoding used along with the language name if it might be ambiguous.

This is . The less bytes, the better.

---

Here's an example in a hypothetical programming language, with input `"Hello, world!"`:

```
DONT_do_NOT_lowercase_UPPERCASE_this(_MY_input_STRING_)

```

`Hello, world!`

With uppercase characters removed:

```
_do__lowercase__this(__input__)

```

`hello, world!`

With lowercase characters removed:

```
DONT__NOT__UPPERCASE_(_MY__STRING_)

```

`HELLO, WORLD!`

---

To be complete, here are the characters/Unicode codepoints that can be removed:

### Uppercase Characters

```
ABCDEFGHIIJKLMNOPQRSTUVWXYZµÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮİİĲĴĶĹĻĽĿŁŃŅŇŉŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŸŹŻŽſƁƂƄƆƇƉƊƋƎƏƐƑƓƔƖƗƘƜƝƟƠƢƤƦƧƩƬƮƯƱƲƳƵƷƸƼǄǅǇǈǊǋǍǏǑǓǕǗǙǛǞǠǢǤǦǨǪǬǮǰǱǲǴǶǷǸǺǼǾȀȂȄȆȈȊȌȎȐȒȔȖȘȚȜȞȠȢȤȦȨȪȬȮȰȲȺȻȽȾɁɃɄɅɆɈɊɌɎͅͰͲͶͿΆΈΉΊΌΎΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΪΫΰςϏϐϑϕϖϘϚϜϞϠϢϤϦϨϪϬϮϰϱϴϵϷϹϺϽϾϿЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯѠѢѤѦѨѪѬѮѰѲѴѶѸѺѼѾҀҊҌҎҐҒҔҖҘҚҜҞҠҢҤҦҨҪҬҮҰҲҴҶҸҺҼҾӀӁӃӅӇӉӋӍӐӒӔӖӘӚӜӞӠӢӤӦӨӪӬӮӰӲӴӶӸӺӼӾԀԂԄԆԈԊԌԎԐԒԔԖԘԚԜԞԠԢԤԦԨԪԬԮԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՒՓՔՕՖևႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀჁჂჃჄჅჇჍᏸᏹᏺᏻᏼᏽᲀᲁᲂᲃᲄᲅᲆᲇᲈᲐᲑᲒᲓᲔᲕᲖᲗᲘᲙᲚᲛᲜᲝᲞᲟᲠᲡᲢᲣᲤᲥᲦᲧᲨᲩᲪᲫᲬᲭᲮᲯᲰᲱᲲᲳᲴᲵᲶᲷᲸᲹᲺᲽᲾᲿḀḂḄḆḈḊḌḎḐḒḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀṂṄṆṈṊṌṎṐṒṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾẀẂẄẆẈẊẌẎẐẒẔẖẗẘẙẚẛẞẞẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾỀỂỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸỺỼỾἈἉἊἋἌἍἎἏἘἙἚἛἜἝἨἩἪἫἬἭἮἯἸἹἺἻἼἽἾἿὈὉὊὋὌὍὐὒὔὖὙὛὝὟὨὩὪὫὬὭὮὯᾀᾁᾂᾃᾄᾅᾆᾇᾈᾈᾉᾉᾊᾊᾋᾋᾌᾌᾍᾍᾎᾎᾏᾏᾐᾑᾒᾓᾔᾕᾖᾗᾘᾘᾙᾙᾚᾚᾛᾛᾜᾜᾝᾝᾞᾞᾟᾟᾠᾡᾢᾣᾤᾥᾦᾧᾨᾨᾩᾩᾪᾪᾫᾫᾬᾬᾭᾭᾮᾮᾯᾯᾲᾳᾴᾶᾷᾸᾹᾺΆᾼᾼιῂῃῄῆῇῈΈῊΉῌῌῒΐῖῗῘῙῚΊῢΰῤῦῧῨῩῪΎῬῲῳῴῶῷῸΌῺΏῼῼΩKÅℲⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯↃⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⰀⰁⰂⰃⰄⰅⰆⰇⰈⰉⰊⰋⰌⰍⰎⰏⰐⰑⰒⰓⰔⰕⰖⰗⰘⰙⰚⰛⰜⰝⰞⰟⰠⰡⰢⰣⰤⰥⰦⰧⰨⰩⰪⰫⰬⰭⰮⱠⱢⱣⱤⱧⱩⱫⱭⱮⱯⱰⱲⱵⱾⱿⲀⲂⲄⲆⲈⲊⲌⲎⲐⲒⲔⲖⲘⲚⲜⲞⲠⲢⲤⲦⲨⲪⲬⲮⲰⲲⲴⲶⲸⲺⲼⲾⳀⳂⳄⳆⳈⳊⳌⳎⳐⳒⳔⳖⳘⳚⳜⳞⳠⳢⳫⳭⳲ

```

### Lowercase Characters

```
abcdefghiıjklmnopqrstuvwxyzμàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþssāăąćĉċčďđēĕėęěĝğġģĥħĩīĭįi̇iĳĵķĺļľŀłńņňʼnŋōŏőœŕŗřśŝşšţťŧũūŭůűųŵŷÿźżžsɓƃƅɔƈɖɗƌǝəɛƒɠɣɩɨƙɯɲɵơƣƥʀƨʃƭʈưʊʋƴƶʒƹƽǆǆǉǉǌǌǎǐǒǔǖǘǚǜǟǡǣǥǧǩǫǭǯǰǳǳǵƕƿǹǻǽǿȁȃȅȇȉȋȍȏȑȓȕȗșțȝȟƞȣȥȧȩȫȭȯȱȳⱥȼƚⱦɂƀʉʌɇɉɋɍɏιͱͳͷϳάέήίόύώΐαβγδεζηθικλμνξοπρστυφχψωϊϋΰσϗβθφπϙϛϝϟϡϣϥϧϩϫϭϯκρθεϸϲϻͻͼͽѐёђѓєѕіїјљњћќѝўџабвгдежзийклмнопрстуфхцчшщъыьэюяѡѣѥѧѩѫѭѯѱѳѵѷѹѻѽѿҁҋҍҏґғҕҗҙқҝҟҡңҥҧҩҫҭүұҳҵҷҹһҽҿӏӂӄӆӈӊӌӎӑӓӕӗәӛӝӟӡӣӥӧөӫӭӯӱӳӵӷӹӻӽӿԁԃԅԇԉԋԍԏԑԓԕԗԙԛԝԟԡԣԥԧԩԫԭԯաբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆեւⴀⴁⴂⴃⴄⴅⴆⴇⴈⴉⴊⴋⴌⴍⴎⴏⴐⴑⴒⴓⴔⴕⴖⴗⴘⴙⴚⴛⴜⴝⴞⴟⴠⴡⴢⴣⴤⴥⴧⴭᏰᏱᏲᏳᏴᏵвдосттъѣꙋაბგდევზთიკლმნოპჟრსტუფქღყშჩცძწჭხჯჰჱჲჳჴჵჶჷჸჹჺჽჾჿḁḃḅḇḉḋḍḏḑḓḕḗḙḛḝḟḡḣḥḧḩḫḭḯḱḳḵḷḹḻḽḿṁṃṅṇṉṋṍṏṑṓṕṗṙṛṝṟṡṣṥṧṩṫṭṯṱṳṵṷṹṻṽṿẁẃẅẇẉẋẍẏẑẓẕẖẗẘẙaʾṡssßạảấầẩẫậắằẳẵặẹẻẽếềểễệỉịọỏốồổỗộớờởỡợụủứừửữựỳỵỷỹỻỽỿἀἁἂἃἄἅἆἇἐἑἒἓἔἕἠἡἢἣἤἥἦἧἰἱἲἳἴἵἶἷὀὁὂὃὄὅὐὒὔὖὑὓὕὗὠὡὢὣὤὥὦὧἀιἁιἂιἃιἄιἅιἆιἇιἀιᾀἁιᾁἂιᾂἃιᾃἄιᾄἅιᾅἆιᾆἇιᾇἠιἡιἢιἣιἤιἥιἦιἧιἠιᾐἡιᾑἢιᾒἣιᾓἤιᾔἥιᾕἦιᾖἧιᾗὠιὡιὢιὣιὤιὥιὦιὧιὠιᾠὡιᾡὢιᾢὣιᾣὤιᾤὥιᾥὦιᾦὧιᾧὰιαιάιᾶᾶιᾰᾱὰάαιᾳιὴιηιήιῆῆιὲέὴήηιῃῒΐῖῗῐῑὶίῢΰῤῦῧῠῡὺύῥὼιωιώιῶῶιὸόὼώωιῳωkåⅎⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽⅾⅿↄⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩⰰⰱⰲⰳⰴⰵⰶⰷⰸⰹⰺⰻⰼⰽⰾⰿⱀⱁⱂⱃⱄⱅⱆⱇⱈⱉⱊⱋⱌⱍⱎⱏⱐⱑⱒⱓⱔⱕⱖⱗⱘⱙⱚⱛⱜⱝⱞⱡɫᵽɽⱨⱪⱬɑɱɐɒⱳⱶȿɀⲁⲃⲅⲇⲉⲋⲍⲏⲑⲓⲕⲗⲙⲛⲝⲟⲡⲣⲥⲧⲩⲫⲭⲯⲱⲳⲵⲷⲹⲻⲽⲿⳁⳃⳅⳇⳉⳋⳍⳏⳑⳓⳕⳗⳙⳛⳝⳟⳡⳣⳬⳮⳳ

```

### Uppercase Codepoints

```
0041, 0042, 0043, 0044, 0045, 0046, 0047, 0048, 0049, 0049, 004A, 004B, 004C, 004D, 004E, 004F, 0050, 0051, 0052, 0053, 0054, 0055, 0056, 0057, 0058, 0059, 005A, 00B5, 00C0, 00C1, 00C2, 00C3, 00C4, 00C5, 00C6, 00C7, 00C8, 00C9, 00CA, 00CB, 00CC, 00CD, 00CE, 00CF, 00D0, 00D1, 00D2, 00D3, 00D4, 00D5, 00D6, 00D8, 00D9, 00DA, 00DB, 00DC, 00DD, 00DE, 00DF, 0100, 0102, 0104, 0106, 0108, 010A, 010C, 010E, 0110, 0112, 0114, 0116, 0118, 011A, 011C, 011E, 0120, 0122, 0124, 0126, 0128, 012A, 012C, 012E, 0130, 0130, 0132, 0134, 0136, 0139, 013B, 013D, 013F, 0141, 0143, 0145, 0147, 0149, 014A, 014C, 014E, 0150, 0152, 0154, 0156, 0158, 015A, 015C, 015E, 0160, 0162, 0164, 0166, 0168, 016A, 016C, 016E, 0170, 0172, 0174, 0176, 0178, 0179, 017B, 017D, 017F, 0181, 0182, 0184, 0186, 0187, 0189, 018A, 018B, 018E, 018F, 0190, 0191, 0193, 0194, 0196, 0197, 0198, 019C, 019D, 019F, 01A0, 01A2, 01A4, 01A6, 01A7, 01A9, 01AC, 01AE, 01AF, 01B1, 01B2, 01B3, 01B5, 01B7, 01B8, 01BC, 01C4, 01C5, 01C7, 01C8, 01CA, 01CB, 01CD, 01CF, 01D1, 01D3, 01D5, 01D7, 01D9, 01DB, 01DE, 01E0, 01E2, 01E4, 01E6, 01E8, 01EA, 01EC, 01EE, 01F0, 01F1, 01F2, 01F4, 01F6, 01F7, 01F8, 01FA, 01FC, 01FE, 0200, 0202, 0204, 0206, 0208, 020A, 020C, 020E, 0210, 0212, 0214, 0216, 0218, 021A, 021C, 021E, 0220, 0222, 0224, 0226, 0228, 022A, 022C, 022E, 0230, 0232, 023A, 023B, 023D, 023E, 0241, 0243, 0244, 0245, 0246, 0248, 024A, 024C, 024E, 0345, 0370, 0372, 0376, 037F, 0386, 0388, 0389, 038A, 038C, 038E, 038F, 0390, 0391, 0392, 0393, 0394, 0395, 0396, 0397, 0398, 0399, 039A, 039B, 039C, 039D, 039E, 039F, 03A0, 03A1, 03A3, 03A4, 03A5, 03A6, 03A7, 03A8, 03A9, 03AA, 03AB, 03B0, 03C2, 03CF, 03D0, 03D1, 03D5, 03D6, 03D8, 03DA, 03DC, 03DE, 03E0, 03E2, 03E4, 03E6, 03E8, 03EA, 03EC, 03EE, 03F0, 03F1, 03F4, 03F5, 03F7, 03F9, 03FA, 03FD, 03FE, 03FF, 0400, 0401, 0402, 0403, 0404, 0405, 0406, 0407, 0408, 0409, 040A, 040B, 040C, 040D, 040E, 040F, 0410, 0411, 0412, 0413, 0414, 0415, 0416, 0417, 0418, 0419, 041A, 041B, 041C, 041D, 041E, 041F, 0420, 0421, 0422, 0423, 0424, 0425, 0426, 0427, 0428, 0429, 042A, 042B, 042C, 042D, 042E, 042F, 0460, 0462, 0464, 0466, 0468, 046A, 046C, 046E, 0470, 0472, 0474, 0476, 0478, 047A, 047C, 047E, 0480, 048A, 048C, 048E, 0490, 0492, 0494, 0496, 0498, 049A, 049C, 049E, 04A0, 04A2, 04A4, 04A6, 04A8, 04AA, 04AC, 04AE, 04B0, 04B2, 04B4, 04B6, 04B8, 04BA, 04BC, 04BE, 04C0, 04C1, 04C3, 04C5, 04C7, 04C9, 04CB, 04CD, 04D0, 04D2, 04D4, 04D6, 04D8, 04DA, 04DC, 04DE, 04E0, 04E2, 04E4, 04E6, 04E8, 04EA, 04EC, 04EE, 04F0, 04F2, 04F4, 04F6, 04F8, 04FA, 04FC, 04FE, 0500, 0502, 0504, 0506, 0508, 050A, 050C, 050E, 0510, 0512, 0514, 0516, 0518, 051A, 051C, 051E, 0520, 0522, 0524, 0526, 0528, 052A, 052C, 052E, 0531, 0532, 0533, 0534, 0535, 0536, 0537, 0538, 0539, 053A, 053B, 053C, 053D, 053E, 053F, 0540, 0541, 0542, 0543, 0544, 0545, 0546, 0547, 0548, 0549, 054A, 054B, 054C, 054D, 054E, 054F, 0550, 0551, 0552, 0553, 0554, 0555, 0556, 0587, 10A0, 10A1, 10A2, 10A3, 10A4, 10A5, 10A6, 10A7, 10A8, 10A9, 10AA, 10AB, 10AC, 10AD, 10AE, 10AF, 10B0, 10B1, 10B2, 10B3, 10B4, 10B5, 10B6, 10B7, 10B8, 10B9, 10BA, 10BB, 10BC, 10BD, 10BE, 10BF, 10C0, 10C1, 10C2, 10C3, 10C4, 10C5, 10C7, 10CD, 13F8, 13F9, 13FA, 13FB, 13FC, 13FD, 1C80, 1C81, 1C82, 1C83, 1C84, 1C85, 1C86, 1C87, 1C88, 1C90, 1C91, 1C92, 1C93, 1C94, 1C95, 1C96, 1C97, 1C98, 1C99, 1C9A, 1C9B, 1C9C, 1C9D, 1C9E, 1C9F, 1CA0, 1CA1, 1CA2, 1CA3, 1CA4, 1CA5, 1CA6, 1CA7, 1CA8, 1CA9, 1CAA, 1CAB, 1CAC, 1CAD, 1CAE, 1CAF, 1CB0, 1CB1, 1CB2, 1CB3, 1CB4, 1CB5, 1CB6, 1CB7, 1CB8, 1CB9, 1CBA, 1CBD, 1CBE, 1CBF, 1E00, 1E02, 1E04, 1E06, 1E08, 1E0A, 1E0C, 1E0E, 1E10, 1E12, 1E14, 1E16, 1E18, 1E1A, 1E1C, 1E1E, 1E20, 1E22, 1E24, 1E26, 1E28, 1E2A, 1E2C, 1E2E, 1E30, 1E32, 1E34, 1E36, 1E38, 1E3A, 1E3C, 1E3E, 1E40, 1E42, 1E44, 1E46, 1E48, 1E4A, 1E4C, 1E4E, 1E50, 1E52, 1E54, 1E56, 1E58, 1E5A, 1E5C, 1E5E, 1E60, 1E62, 1E64, 1E66, 1E68, 1E6A, 1E6C, 1E6E, 1E70, 1E72, 1E74, 1E76, 1E78, 1E7A, 1E7C, 1E7E, 1E80, 1E82, 1E84, 1E86, 1E88, 1E8A, 1E8C, 1E8E, 1E90, 1E92, 1E94, 1E96, 1E97, 1E98, 1E99, 1E9A, 1E9B, 1E9E, 1E9E, 1EA0, 1EA2, 1EA4, 1EA6, 1EA8, 1EAA, 1EAC, 1EAE, 1EB0, 1EB2, 1EB4, 1EB6, 1EB8, 1EBA, 1EBC, 1EBE, 1EC0, 1EC2, 1EC4, 1EC6, 1EC8, 1ECA, 1ECC, 1ECE, 1ED0, 1ED2, 1ED4, 1ED6, 1ED8, 1EDA, 1EDC, 1EDE, 1EE0, 1EE2, 1EE4, 1EE6, 1EE8, 1EEA, 1EEC, 1EEE, 1EF0, 1EF2, 1EF4, 1EF6, 1EF8, 1EFA, 1EFC, 1EFE, 1F08, 1F09, 1F0A, 1F0B, 1F0C, 1F0D, 1F0E, 1F0F, 1F18, 1F19, 1F1A, 1F1B, 1F1C, 1F1D, 1F28, 1F29, 1F2A, 1F2B, 1F2C, 1F2D, 1F2E, 1F2F, 1F38, 1F39, 1F3A, 1F3B, 1F3C, 1F3D, 1F3E, 1F3F, 1F48, 1F49, 1F4A, 1F4B, 1F4C, 1F4D, 1F50, 1F52, 1F54, 1F56, 1F59, 1F5B, 1F5D, 1F5F, 1F68, 1F69, 1F6A, 1F6B, 1F6C, 1F6D, 1F6E, 1F6F, 1F80, 1F81, 1F82, 1F83, 1F84, 1F85, 1F86, 1F87, 1F88, 1F88, 1F89, 1F89, 1F8A, 1F8A, 1F8B, 1F8B, 1F8C, 1F8C, 1F8D, 1F8D, 1F8E, 1F8E, 1F8F, 1F8F, 1F90, 1F91, 1F92, 1F93, 1F94, 1F95, 1F96, 1F97, 1F98, 1F98, 1F99, 1F99, 1F9A, 1F9A, 1F9B, 1F9B, 1F9C, 1F9C, 1F9D, 1F9D, 1F9E, 1F9E, 1F9F, 1F9F, 1FA0, 1FA1, 1FA2, 1FA3, 1FA4, 1FA5, 1FA6, 1FA7, 1FA8, 1FA8, 1FA9, 1FA9, 1FAA, 1FAA, 1FAB, 1FAB, 1FAC, 1FAC, 1FAD, 1FAD, 1FAE, 1FAE, 1FAF, 1FAF, 1FB2, 1FB3, 1FB4, 1FB6, 1FB7, 1FB8, 1FB9, 1FBA, 1FBB, 1FBC, 1FBC, 1FBE, 1FC2, 1FC3, 1FC4, 1FC6, 1FC7, 1FC8, 1FC9, 1FCA, 1FCB, 1FCC, 1FCC, 1FD2, 1FD3, 1FD6, 1FD7, 1FD8, 1FD9, 1FDA, 1FDB, 1FE2, 1FE3, 1FE4, 1FE6, 1FE7, 1FE8, 1FE9, 1FEA, 1FEB, 1FEC, 1FF2, 1FF3, 1FF4, 1FF6, 1FF7, 1FF8, 1FF9, 1FFA, 1FFB, 1FFC, 1FFC, 2126, 212A, 212B, 2132, 2160, 2161, 2162, 2163, 2164, 2165, 2166, 2167, 2168, 2169, 216A, 216B, 216C, 216D, 216E, 216F, 2183, 24B6, 24B7, 24B8, 24B9, 24BA, 24BB, 24BC, 24BD, 24BE, 24BF, 24C0, 24C1, 24C2, 24C3, 24C4, 24C5, 24C6, 24C7, 24C8, 24C9, 24CA, 24CB, 24CC, 24CD, 24CE, 24CF, 2C00, 2C01, 2C02, 2C03, 2C04, 2C05, 2C06, 2C07, 2C08, 2C09, 2C0A, 2C0B, 2C0C, 2C0D, 2C0E, 2C0F, 2C10, 2C11, 2C12, 2C13, 2C14, 2C15, 2C16, 2C17, 2C18, 2C19, 2C1A, 2C1B, 2C1C, 2C1D, 2C1E, 2C1F, 2C20, 2C21, 2C22, 2C23, 2C24, 2C25, 2C26, 2C27, 2C28, 2C29, 2C2A, 2C2B, 2C2C, 2C2D, 2C2E, 2C60, 2C62, 2C63, 2C64, 2C67, 2C69, 2C6B, 2C6D, 2C6E, 2C6F, 2C70, 2C72, 2C75, 2C7E, 2C7F, 2C80, 2C82, 2C84, 2C86, 2C88, 2C8A, 2C8C, 2C8E, 2C90, 2C92, 2C94, 2C96, 2C98, 2C9A, 2C9C, 2C9E, 2CA0, 2CA2, 2CA4, 2CA6, 2CA8, 2CAA, 2CAC, 2CAE, 2CB0, 2CB2, 2CB4, 2CB6, 2CB8, 2CBA, 2CBC, 2CBE, 2CC0, 2CC2, 2CC4, 2CC6, 2CC8, 2CCA, 2CCC, 2CCE, 2CD0, 2CD2, 2CD4, 2CD6, 2CD8, 2CDA, 2CDC, 2CDE, 2CE0, 2CE2, 2CEB, 2CED, 2CF2, 10400, 10401, 10402, 10403, 10404, 10405, 10406, 10407, 10408, 10409, 1040A, 1040B, 1040C, 1040D, 1040E, 1040F, 10410, 10411, 10412, 10413, 10414, 10415, 10416, 10417, 10418, 10419, 1041A, 1041B, 1041C, 1041D, 1041E, 1041F, 10420, 10421, 10422, 10423, 10424, 10425, 10426, 10427, 104B0, 104B1, 104B2, 104B3, 104B4, 104B5, 104B6, 104B7, 104B8, 104B9, 104BA, 104BB, 104BC, 104BD, 104BE, 104BF, 104C0, 104C1, 104C2, 104C3, 104C4, 104C5, 104C6, 104C7, 104C8, 104C9, 104CA, 104CB, 104CC, 104CD, 104CE, 104CF, 104D0, 104D1, 104D2, 104D3, 10C80, 10C81, 10C82, 10C83, 10C84, 10C85, 10C86, 10C87, 10C88, 10C89, 10C8A, 10C8B, 10C8C, 10C8D, 10C8E, 10C8F, 10C90, 10C91, 10C92, 10C93, 10C94, 10C95, 10C96, 10C97, 10C98, 10C99, 10C9A, 10C9B, 10C9C, 10C9D, 10C9E, 10C9F, 10CA0, 10CA1, 10CA2, 10CA3, 10CA4, 10CA5, 10CA6, 10CA7, 10CA8, 10CA9, 10CAA, 10CAB, 10CAC, 10CAD, 10CAE, 10CAF, 10CB0, 10CB1, 10CB2, 118A0, 118A1, 118A2, 118A3, 118A4, 118A5, 118A6, 118A7, 118A8, 118A9, 118AA, 118AB, 118AC, 118AD, 118AE, 118AF, 118B0, 118B1, 118B2, 118B3, 118B4, 118B5, 118B6, 118B7, 118B8, 118B9, 118BA, 118BB, 118BC, 118BD, 118BE, 118BF, 16E40, 16E41, 16E42, 16E43, 16E44, 16E45, 16E46, 16E47, 16E48, 16E49, 16E4A, 16E4B, 16E4C, 16E4D, 16E4E, 16E4F, 16E50, 16E51, 16E52, 16E53, 16E54, 16E55, 16E56, 16E57, 16E58, 16E59, 16E5A, 16E5B, 16E5C, 16E5D, 16E5E, 16E5F, 1E900, 1E901, 1E902, 1E903, 1E904, 1E905, 1E906, 1E907, 1E908, 1E909, 1E90A, 1E90B, 1E90C, 1E90D, 1E90E, 1E90F, 1E910, 1E911, 1E912, 1E913, 1E914, 1E915, 1E916, 1E917, 1E918, 1E919, 1E91A, 1E91B, 1E91C, 1E91D, 1E91E, 1E91F, 1E920, 1E921

```

### Lowercase Codepoints

```
0061, 0062, 0063, 0064, 0065, 0066, 0067, 0068, 0069, 0131, 006A, 006B, 006C, 006D, 006E, 006F, 0070, 0071, 0072, 0073, 0074, 0075, 0076, 0077, 0078, 0079, 007A, 03BC, 00E0, 00E1, 00E2, 00E3, 00E4, 00E5, 00E6, 00E7, 00E8, 00E9, 00EA, 00EB, 00EC, 00ED, 00EE, 00EF, 00F0, 00F1, 00F2, 00F3, 00F4, 00F5, 00F6, 00F8, 00F9, 00FA, 00FB, 00FC, 00FD, 00FE, 0073 0073, 0101, 0103, 0105, 0107, 0109, 010B, 010D, 010F, 0111, 0113, 0115, 0117, 0119, 011B, 011D, 011F, 0121, 0123, 0125, 0127, 0129, 012B, 012D, 012F, 0069 0307, 0069, 0133, 0135, 0137, 013A, 013C, 013E, 0140, 0142, 0144, 0146, 0148, 02BC 006E, 014B, 014D, 014F, 0151, 0153, 0155, 0157, 0159, 015B, 015D, 015F, 0161, 0163, 0165, 0167, 0169, 016B, 016D, 016F, 0171, 0173, 0175, 0177, 00FF, 017A, 017C, 017E, 0073, 0253, 0183, 0185, 0254, 0188, 0256, 0257, 018C, 01DD, 0259, 025B, 0192, 0260, 0263, 0269, 0268, 0199, 026F, 0272, 0275, 01A1, 01A3, 01A5, 0280, 01A8, 0283, 01AD, 0288, 01B0, 028A, 028B, 01B4, 01B6, 0292, 01B9, 01BD, 01C6, 01C6, 01C9, 01C9, 01CC, 01CC, 01CE, 01D0, 01D2, 01D4, 01D6, 01D8, 01DA, 01DC, 01DF, 01E1, 01E3, 01E5, 01E7, 01E9, 01EB, 01ED, 01EF, 006A 030C, 01F3, 01F3, 01F5, 0195, 01BF, 01F9, 01FB, 01FD, 01FF, 0201, 0203, 0205, 0207, 0209, 020B, 020D, 020F, 0211, 0213, 0215, 0217, 0219, 021B, 021D, 021F, 019E, 0223, 0225, 0227, 0229, 022B, 022D, 022F, 0231, 0233, 2C65, 023C, 019A, 2C66, 0242, 0180, 0289, 028C, 0247, 0249, 024B, 024D, 024F, 03B9, 0371, 0373, 0377, 03F3, 03AC, 03AD, 03AE, 03AF, 03CC, 03CD, 03CE, 03B9 0308 0301, 03B1, 03B2, 03B3, 03B4, 03B5, 03B6, 03B7, 03B8, 03B9, 03BA, 03BB, 03BC, 03BD, 03BE, 03BF, 03C0, 03C1, 03C3, 03C4, 03C5, 03C6, 03C7, 03C8, 03C9, 03CA, 03CB, 03C5 0308 0301, 03C3, 03D7, 03B2, 03B8, 03C6, 03C0, 03D9, 03DB, 03DD, 03DF, 03E1, 03E3, 03E5, 03E7, 03E9, 03EB, 03ED, 03EF, 03BA, 03C1, 03B8, 03B5, 03F8, 03F2, 03FB, 037B, 037C, 037D, 0450, 0451, 0452, 0453, 0454, 0455, 0456, 0457, 0458, 0459, 045A, 045B, 045C, 045D, 045E, 045F, 0430, 0431, 0432, 0433, 0434, 0435, 0436, 0437, 0438, 0439, 043A, 043B, 043C, 043D, 043E, 043F, 0440, 0441, 0442, 0443, 0444, 0445, 0446, 0447, 0448, 0449, 044A, 044B, 044C, 044D, 044E, 044F, 0461, 0463, 0465, 0467, 0469, 046B, 046D, 046F, 0471, 0473, 0475, 0477, 0479, 047B, 047D, 047F, 0481, 048B, 048D, 048F, 0491, 0493, 0495, 0497, 0499, 049B, 049D, 049F, 04A1, 04A3, 04A5, 04A7, 04A9, 04AB, 04AD, 04AF, 04B1, 04B3, 04B5, 04B7, 04B9, 04BB, 04BD, 04BF, 04CF, 04C2, 04C4, 04C6, 04C8, 04CA, 04CC, 04CE, 04D1, 04D3, 04D5, 04D7, 04D9, 04DB, 04DD, 04DF, 04E1, 04E3, 04E5, 04E7, 04E9, 04EB, 04ED, 04EF, 04F1, 04F3, 04F5, 04F7, 04F9, 04FB, 04FD, 04FF, 0501, 0503, 0505, 0507, 0509, 050B, 050D, 050F, 0511, 0513, 0515, 0517, 0519, 051B, 051D, 051F, 0521, 0523, 0525, 0527, 0529, 052B, 052D, 052F, 0561, 0562, 0563, 0564, 0565, 0566, 0567, 0568, 0569, 056A, 056B, 056C, 056D, 056E, 056F, 0570, 0571, 0572, 0573, 0574, 0575, 0576, 0577, 0578, 0579, 057A, 057B, 057C, 057D, 057E, 057F, 0580, 0581, 0582, 0583, 0584, 0585, 0586, 0565 0582, 2D00, 2D01, 2D02, 2D03, 2D04, 2D05, 2D06, 2D07, 2D08, 2D09, 2D0A, 2D0B, 2D0C, 2D0D, 2D0E, 2D0F, 2D10, 2D11, 2D12, 2D13, 2D14, 2D15, 2D16, 2D17, 2D18, 2D19, 2D1A, 2D1B, 2D1C, 2D1D, 2D1E, 2D1F, 2D20, 2D21, 2D22, 2D23, 2D24, 2D25, 2D27, 2D2D, 13F0, 13F1, 13F2, 13F3, 13F4, 13F5, 0432, 0434, 043E, 0441, 0442, 0442, 044A, 0463, A64B, 10D0, 10D1, 10D2, 10D3, 10D4, 10D5, 10D6, 10D7, 10D8, 10D9, 10DA, 10DB, 10DC, 10DD, 10DE, 10DF, 10E0, 10E1, 10E2, 10E3, 10E4, 10E5, 10E6, 10E7, 10E8, 10E9, 10EA, 10EB, 10EC, 10ED, 10EE, 10EF, 10F0, 10F1, 10F2, 10F3, 10F4, 10F5, 10F6, 10F7, 10F8, 10F9, 10FA, 10FD, 10FE, 10FF, 1E01, 1E03, 1E05, 1E07, 1E09, 1E0B, 1E0D, 1E0F, 1E11, 1E13, 1E15, 1E17, 1E19, 1E1B, 1E1D, 1E1F, 1E21, 1E23, 1E25, 1E27, 1E29, 1E2B, 1E2D, 1E2F, 1E31, 1E33, 1E35, 1E37, 1E39, 1E3B, 1E3D, 1E3F, 1E41, 1E43, 1E45, 1E47, 1E49, 1E4B, 1E4D, 1E4F, 1E51, 1E53, 1E55, 1E57, 1E59, 1E5B, 1E5D, 1E5F, 1E61, 1E63, 1E65, 1E67, 1E69, 1E6B, 1E6D, 1E6F, 1E71, 1E73, 1E75, 1E77, 1E79, 1E7B, 1E7D, 1E7F, 1E81, 1E83, 1E85, 1E87, 1E89, 1E8B, 1E8D, 1E8F, 1E91, 1E93, 1E95, 0068 0331, 0074 0308, 0077 030A, 0079 030A, 0061 02BE, 1E61, 0073 0073, 00DF, 1EA1, 1EA3, 1EA5, 1EA7, 1EA9, 1EAB, 1EAD, 1EAF, 1EB1, 1EB3, 1EB5, 1EB7, 1EB9, 1EBB, 1EBD, 1EBF, 1EC1, 1EC3, 1EC5, 1EC7, 1EC9, 1ECB, 1ECD, 1ECF, 1ED1, 1ED3, 1ED5, 1ED7, 1ED9, 1EDB, 1EDD, 1EDF, 1EE1, 1EE3, 1EE5, 1EE7, 1EE9, 1EEB, 1EED, 1EEF, 1EF1, 1EF3, 1EF5, 1EF7, 1EF9, 1EFB, 1EFD, 1EFF, 1F00, 1F01, 1F02, 1F03, 1F04, 1F05, 1F06, 1F07, 1F10, 1F11, 1F12, 1F13, 1F14, 1F15, 1F20, 1F21, 1F22, 1F23, 1F24, 1F25, 1F26, 1F27, 1F30, 1F31, 1F32, 1F33, 1F34, 1F35, 1F36, 1F37, 1F40, 1F41, 1F42, 1F43, 1F44, 1F45, 03C5 0313, 03C5 0313 0300, 03C5 0313 0301, 03C5 0313 0342, 1F51, 1F53, 1F55, 1F57, 1F60, 1F61, 1F62, 1F63, 1F64, 1F65, 1F66, 1F67, 1F00 03B9, 1F01 03B9, 1F02 03B9, 1F03 03B9, 1F04 03B9, 1F05 03B9, 1F06 03B9, 1F07 03B9, 1F00 03B9, 1F80, 1F01 03B9, 1F81, 1F02 03B9, 1F82, 1F03 03B9, 1F83, 1F04 03B9, 1F84, 1F05 03B9, 1F85, 1F06 03B9, 1F86, 1F07 03B9, 1F87, 1F20 03B9, 1F21 03B9, 1F22 03B9, 1F23 03B9, 1F24 03B9, 1F25 03B9, 1F26 03B9, 1F27 03B9, 1F20 03B9, 1F90, 1F21 03B9, 1F91, 1F22 03B9, 1F92, 1F23 03B9, 1F93, 1F24 03B9, 1F94, 1F25 03B9, 1F95, 1F26 03B9, 1F96, 1F27 03B9, 1F97, 1F60 03B9, 1F61 03B9, 1F62 03B9, 1F63 03B9, 1F64 03B9, 1F65 03B9, 1F66 03B9, 1F67 03B9, 1F60 03B9, 1FA0, 1F61 03B9, 1FA1, 1F62 03B9, 1FA2, 1F63 03B9, 1FA3, 1F64 03B9, 1FA4, 1F65 03B9, 1FA5, 1F66 03B9, 1FA6, 1F67 03B9, 1FA7, 1F70 03B9, 03B1 03B9, 03AC 03B9, 03B1 0342, 03B1 0342 03B9, 1FB0, 1FB1, 1F70, 1F71, 03B1 03B9, 1FB3, 03B9, 1F74 03B9, 03B7 03B9, 03AE 03B9, 03B7 0342, 03B7 0342 03B9, 1F72, 1F73, 1F74, 1F75, 03B7 03B9, 1FC3, 03B9 0308 0300, 03B9 0308 0301, 03B9 0342, 03B9 0308 0342, 1FD0, 1FD1, 1F76, 1F77, 03C5 0308 0300, 03C5 0308 0301, 03C1 0313, 03C5 0342, 03C5 0308 0342, 1FE0, 1FE1, 1F7A, 1F7B, 1FE5, 1F7C 03B9, 03C9 03B9, 03CE 03B9, 03C9 0342, 03C9 0342 03B9, 1F78, 1F79, 1F7C, 1F7D, 03C9 03B9, 1FF3, 03C9, 006B, 00E5, 214E, 2170, 2171, 2172, 2173, 2174, 2175, 2176, 2177, 2178, 2179, 217A, 217B, 217C, 217D, 217E, 217F, 2184, 24D0, 24D1, 24D2, 24D3, 24D4, 24D5, 24D6, 24D7, 24D8, 24D9, 24DA, 24DB, 24DC, 24DD, 24DE, 24DF, 24E0, 24E1, 24E2, 24E3, 24E4, 24E5, 24E6, 24E7, 24E8, 24E9, 2C30, 2C31, 2C32, 2C33, 2C34, 2C35, 2C36, 2C37, 2C38, 2C39, 2C3A, 2C3B, 2C3C, 2C3D, 2C3E, 2C3F, 2C40, 2C41, 2C42, 2C43, 2C44, 2C45, 2C46, 2C47, 2C48, 2C49, 2C4A, 2C4B, 2C4C, 2C4D, 2C4E, 2C4F, 2C50, 2C51, 2C52, 2C53, 2C54, 2C55, 2C56, 2C57, 2C58, 2C59, 2C5A, 2C5B, 2C5C, 2C5D, 2C5E, 2C61, 026B, 1D7D, 027D, 2C68, 2C6A, 2C6C, 0251, 0271, 0250, 0252, 2C73, 2C76, 023F, 0240, 2C81, 2C83, 2C85, 2C87, 2C89, 2C8B, 2C8D, 2C8F, 2C91, 2C93, 2C95, 2C97, 2C99, 2C9B, 2C9D, 2C9F, 2CA1, 2CA3, 2CA5, 2CA7, 2CA9, 2CAB, 2CAD, 2CAF, 2CB1, 2CB3, 2CB5, 2CB7, 2CB9, 2CBB, 2CBD, 2CBF, 2CC1, 2CC3, 2CC5, 2CC7, 2CC9, 2CCB, 2CCD, 2CCF, 2CD1, 2CD3, 2CD5, 2CD7, 2CD9, 2CDB, 2CDD, 2CDF, 2CE1, 2CE3, 2CEC, 2CEE, 2CF3, 10428, 10429, 1042A, 1042B, 1042C, 1042D, 1042E, 1042F, 10430, 10431, 10432, 10433, 10434, 10435, 10436, 10437, 10438, 10439, 1043A, 1043B, 1043C, 1043D, 1043E, 1043F, 10440, 10441, 10442, 10443, 10444, 10445, 10446, 10447, 10448, 10449, 1044A, 1044B, 1044C, 1044D, 1044E, 1044F, 104D8, 104D9, 104DA, 104DB, 104DC, 104DD, 104DE, 104DF, 104E0, 104E1, 104E2, 104E3, 104E4, 104E5, 104E6, 104E7, 104E8, 104E9, 104EA, 104EB, 104EC, 104ED, 104EE, 104EF, 104F0, 104F1, 104F2, 104F3, 104F4, 104F5, 104F6, 104F7, 104F8, 104F9, 104FA, 104FB, 10CC0, 10CC1, 10CC2, 10CC3, 10CC4, 10CC5, 10CC6, 10CC7, 10CC8, 10CC9, 10CCA, 10CCB, 10CCC, 10CCD, 10CCE, 10CCF, 10CD0, 10CD1, 10CD2, 10CD3, 10CD4, 10CD5, 10CD6, 10CD7, 10CD8, 10CD9, 10CDA, 10CDB, 10CDC, 10CDD, 10CDE, 10CDF, 10CE0, 10CE1, 10CE2, 10CE3, 10CE4, 10CE5, 10CE6, 10CE7, 10CE8, 10CE9, 10CEA, 10CEB, 10CEC, 10CED, 10CEE, 10CEF, 10CF0, 10CF1, 10CF2, 118C0, 118C1, 118C2, 118C3, 118C4, 118C5, 118C6, 118C7, 118C8, 118C9, 118CA, 118CB, 118CC, 118CD, 118CE, 118CF, 118D0, 118D1, 118D2, 118D3, 118D4, 118D5, 118D6, 118D7, 118D8, 118D9, 118DA, 118DB, 118DC, 118DD, 118DE, 118DF, 16E60, 16E61, 16E62, 16E63, 16E64, 16E65, 16E66, 16E67, 16E68, 16E69, 16E6A, 16E6B, 16E6C, 16E6D, 16E6E, 16E6F, 16E70, 16E71, 16E72, 16E73, 16E74, 16E75, 16E76, 16E77, 16E78, 16E79, 16E7A, 16E7B, 16E7C, 16E7D, 16E7E, 16E7F, 1E922, 1E923, 1E924, 1E925, 1E926, 1E927, 1E928, 1E929, 1E92A, 1E92B, 1E92C, 1E92D, 1E92E, 1E92F, 1E930, 1E931, 1E932, 1E933, 1E934, 1E935, 1E936, 1E937, 1E938, 1E939, 1E93A, 1E93B, 1E93C, 1E93D, 1E93E, 1E93F, 1E940, 1E941, 1E942, 1E943

```

# Answer
> 20 votes
# perl -p, 37 bytes

```
goto Aa_;A_:$_="\U$_";a_:$_=lc$_;Aa_:

```

Try it online!

Removing all lowercase letters leaves:

```
 A_;A_:$_="\U$_";_:$_=$_;A_:

```

Try it online!

Removing the upper case letters leaves:

```
goto a_;_:$_="\$_";a_:$_=lc$_;a_:

```

Try it online!

How it works? With nothing removed, control jumps to the end, leaving the input unmodified.

With the lowercase letters removed, we have the string `A_` in void context (nothing happens), and then at label `A_`, we upper case the string, at label `_`, we have a no-op (assigning `$_` to itself), and an empty statement at label `A_`. Finally, the result is printed.

With the upper case letters removed, we jump to label `a_`, which lower cases the string, and the result is printed.

# Answer
> 16 votes
# Perl 5 \+ `-p`, 20 bytes

```
$_=0xE0?$_:lc"\lU$_"

```

Try it online!

With all uppercase removed.

With all lowercase removed.

## Explanation

Because we're using the `-p` flag, the input is placed in`$_` implicitly and `$_` is printed implicitly when the program terminates.

In the unmodified program, this checks `0xE0`, which is `224`, for truthiness and sets `$_` to itself.

When all uppercase characters are removed `0xE0` becomes `0x0` which is `0` and the else block is reached which sets `$_` to `lc"\l$_"`. `lc` is Perl's lowercase function and converts the string to lowercase. `\l` is a string modifier that changes the immediately following character to lowercase, but this is irrelevant since it'll be lowered by the function call anyway.

When all lowercase characters are removed, `0xE0` becomes `0E0` which is `0` again, hitting the else block. Here we set `$_` to `"\U$_"`. `\U` is a strong modifier that makes the following part of the string uppercase.

# Answer
> 13 votes
# APL (Dyalog Extended), 14 bytes (SBCS)

Anonymous tacit prefix function. Unmodified function:

```
'AAb'≢⍛⊃⊂,⍨⌊⍮⌈

```

Leaves argument untouched: Try it online!

Without lowercase letters:

```
'AA'≢⍛⊃⊂,⍨⌊⍮⌈

```

Uppercase argument: Try it online!

Without uppercase letters:

```
'b'≢⍛⊃⊂,⍨⌊⍮⌈

```

Lowercases letters: Try it online!

---

the uppercased argument; `"HELLO, WORLD!"`

pair to:

the lowercased argument; `[hello, world!","HELLO, WORLD!"]`

`,⍨` append:

the entire argument; `[hello, world!","HELLO, WORLD!","Hello, world!"]`

pick element number:

`≢⍛` the length of:

`'AAb'`/`'AA'`/`'b'` these three strings, i.e. number 3/2/1

# Answer
> 11 votes
## Javascript 192 characters (without `\123` literals)

```
$=>'Aa'[1]?$:'a'?$['to\u004cower\u0043ase']():
z/A/g&&([,A,,S,E,,O,,,,C]=!1+{},[T,R]=!0+$,[U,N,,,,I]=1[0]+$,$[T+O+'U'+1199331[T+O+'S'+T+R+I+N+($[C+O+N+S+T+R+U+C+T+O+R]+$)[14]](36)+'C'+A+S+E]())

```

## Javascript 197 characters (without `\123` literals)

```
$=>'Aa'[1]?$:'a'?$['to\u004cower\u0043ase']():
z/A/g&&([,O,,,E,C]={}+$,[,A,,S]=!1+$,[T,R]=!0+$,[U,N,,,,I]=1[0]+$,$[T+O+'U'+1199331[T+O+'S'+T+R+I+N+($[C+O+N+S+T+R+U+C+T+O+R]+$)[14]](36)+'C'+A+S+E]())

```

## Javascript 204 ~~208~~ ~~226~~ ~~234~~ characters (without `\123` numeric literals)

```
$=>'Aa'[1]?$:'a'?$['to\u004cower\u0043ase']():
a/A/g&&([,O,,,E,C]=JSON+$,[,A,,S]=!1+$,[T,R]=!0+$,[U,N,,,,I]=1[0]+$,P=25[T+O+'S'+T+R+I+N+($[C+O+N+S+T+R+U+C+T+O+R]+$)[14]](36),$[T+O+'U'+P+P+E+R+'C'+A+S+E]())

```

```
r=
$=>'Aa'[1]?$:'a'?$['to\u004cower\u0043ase']():z/A/g&&([,A,,S,E,,O,,,,C]=!1+{},[T,R]=!0+$,[U,N,,,,I]=1[0]+$,$[T+O+'U'+1199331[T+O+'S'+T+R+I+N+($[C+O+N+S+T+R+U+C+T+O+R]+$)[14]](36)+'C'+A+S+E]())

console.log(eval(String(r))('Sentence Case'));
console.log(eval(String(r).replace(/[A-Z]/g, ''))('Lower Case'));
console.log(eval(String(r).replace(/[a-z]/g, ''))('Upper Case'));
```

I didn't realise that you could make arbitrary characters with `\123`. It's a much more interesting challenge without :)

A couple of comments:

* Some of the concepts are inspired by JSFuck, although the constraints are different. There is fortunately one global object whose name is entirely upper case letters, JSON, so we can directly harvest quite a few letters from `[object JSON]`
* Other letters come from `true`, `false` and `undefined`. We take the letters we need to write `constructor`, which then means we can find the string representation of a random string's constructor, which starts `function String() {...`
* That `g` is the last ingredient we need to then form the method name `toString()`, which in base 36 lets us turn any number into an equivalent lowercase letter.

The only other thing of note here is that once we remove all the uppercase letters from this branch path, it's not syntactically correct. So we turn it all into a `//` comment with a regex `/A/g` which turns into a comment. We end up with three completely different syntaxes for the three modes:

* No removals: `a/A/g&&(...` one undefined variable divided by another by another.
* Remove lower case: `/A/&&(...` a regex (always truthy) and the rest of the expression
* Remove upper case: `a//g&&...` an undefined variable and a comment.

## Javascript 272 characters

```
$=>'Aa'=='\u0041\u0061'?$:'a'=='\u0061'?eval('$.to\u0055pper\u0043ase()'):(
[,O,,,E,C]=JSON+'',
[,A,,S]=(''+!1),
[T,R]=(''+!0),
[U,N,,,,I]=(''+1[0]),
Ka=Ca+Oa+Na+Sa+Ta+Ra+Ua+Ca+Ta+Oa+Ra,
Ga=(''[Ka]+'')[14],
$[Ta+Oa+'L'+Oa+(32)[Ta+Oa+'S'+Ta+Ra+Ia+Na+Ga](36)+Ea+Ra+'C'+Aa+Sa+Ea]())

```

(Linebreaks inserted for readability)

Room to golf, but pretty excited that it even works. Took a lot of inspiration from JSFuck.

Whoops, I realised I got the functionality backwards: when you remove uppercase letters it uppercases, etc.

# Answer
> 10 votes
# 05AB1E, ~~20~~ 9 bytes

Byte-count more than halved (-11) thanks to *@Dorian*!

Full program:

```
lIq.•L•.V

```

Try it online.

With uppercase characters removed; outputting in lowercase:

```
lq.••.

```

Try it online.

With lowercase characters removed; outputting in uppercase:

```
I.•L•.V

```

Try it online.

**Explanation:**

```
          # Full program:
l         #  Lowercase the (implicit) input
 I        #  Push the input again
  q       #  Stop the program, after which the top of the stack is output implicitly
   .•L•.V #  No-ops

          # Program with uppercase characters removed:
l         #  Lowercase the (implicit) input
 q        #  Stop the program, after which the top of the stack is output implicitly
  .••.    #  No-ops

          # Program with lowercase characters removed:
I         #  Push the input
 .•L•     #  Push compressed string "u"
     .V   #  Evaluate/execute it as 05AB1E code; uppercase the (implicit) input
          #  (after which the result is output implicitly)

```

See this 05AB1E tip of mine (section *How to compress strings not part of the dictionary?*) to understand why `.•L•` is `"u"`.

# Answer
> 9 votes
# Bash, 107 characters

```
cC=echoECHO
cC=${cC,,}
cC=${cC::4}
[ c ]||cC+=(${@^^})
[ C ]||cC+=(${@,,})
[[ cC = ?? ]]&&cC+=($@)
${cC[@]}

```

Try it online!

# Answer
> 9 votes
# Ruby, 106 bytes

**Full version:**

```
$_=[*$<]*''
$.=0
o_=97
O_=65
@_=->{$_[__=''<<$.+_]?$_[__]=''<<$.+(_^32):$.+=1;$.<27&&@_[]}
_&&=@_[]
$><<$_

```

Try it online!

**Uppercase:**

```
$_=[*$<]*''
$.=0
_=97
O_=65
@_=->{$_[__=''<<$.+_]?$_[__]=''<<$.+(_^32):$.+=1;$.<27&&@_[]}
_&&=@_[]
$><<$_

```

Try it online!

**Lowercase:**

```
$_=[*$<]*''
$.=0
o_=97
_=65
@_=->{$_[__=''<<$.+_]?$_[__]=''<<$.+(_^32):$.+=1;$.<27&&@_[]}
_&&=@_[]
$><<$_

```

Try it online!

**Explanation:**

The verbose part here is all about the no-lower-case version. Avoiding lower-case characters means the string replacement needs to use the syntax `str[from] = to`, wrapped in a loop via a lambda that calls itself. The lambda is the variable `@_` defined using `@_=->`, and it's called via `@_[]`.

Stepping through...

`$_=[*$<]*''` : Read multiline input into the variable `$_`. (Depending on your interpretation of the spec, this could just be `$_,=*$<` for single-line input or even happen implicitly via the `-p` flag).

`$.=0`: Initialize the variable we'll be using to iterate over the letters of the alphabet.

`o_=97`: This initializes a variable that we never use. But if `o`, the only lower-case character in the program, is deleted, it's instead initializing `_`.

`O_=65`: Same but for upper-case.

`@_=->{`: Start the loop definition.

`$_[__=''<<$.+_]`: Check for the presence of a specific letter in the string (starting with "a".)

`?$_[__]=''<<$.+(_^32)`: If it's there, swap its case.

`:$.+=1`: Otherwise, move on to the next letter.

`$.<27&&@_[]}`: Either way, repeat the loop as long as we haven't reached the end of the alphabet.

`_&&=@_[]`: If `_` has been defined, run the loop. If it was defined as 97, we'll be caseswapping letters starting with 'a' (character code 97). If it was defined as 65, we'll start with 'A'.

`$><<$_`: Output.

# Answer
> 8 votes
# C (gcc), ~~78~~ ~~76~~ ~~73~~ ~~72~~ 68 bytes

```
__(_,$){$="";_[""-$]&&__(_+1,_[""-$]^=_[""-$]-('Aa'^32u)<26U?32:0);}

```

Try it online!

# C (clang), 66 bytes

```
__(_,$){$="";""[$=_-$]&&__(_+1,""[$]^=""[$]-('Aa'^32u)<26U?32:0);}

```

Try it online!

Thank @G.Sliepen for fixing code for tio and pointing that the optimize work on clang!

# Answer
> 8 votes
# perl -p, 19 bytes

```
$A_=lc$_;$a_="\U$_"

```

Try it online!

A completely different solution than my earlier one. The program reads a line from the input (in the variable `$_`), does zero or more modifications, and prints that line (due to the `-p` flag). That is, it prints whatever ends up in `$_`.

As is, the input line isn't modified; its lower case variant is assigned to `$A_`, and its upper case variant to `$a_`, but both variables are otherwise ignored.

Removing the upper case letters gives us:

```
$_=lc$_;$a_="\$_"

```

Try it online!

Now, `$_` is set to the lower case variant of itself. The variable `$a_` is set to the literal string `$_`, but otherwise ignored.

If we remove the lowercase letters instead, we end up with:

```
$A_=$_;$_="\U$_"

```

Try it online!

Now we assign `$A_` the input line, and ignore this variable. `$_` is set to the uppercase variant of itself by using the special interpolation symbol `\U`, which upper cases the rest of the string, until it encounters `\E`, or the end of the string.

# Answer
> 8 votes
# Burlesque, 10 bytes

```
JZZzz#RjHD

```

Try it online!

This was a very fun one to puzzle out.

Explanation:

```
J            # Duplicate the input
 ZZ          # Uppercase it
   zz        # Lowercase it
     #R      # Rotate the stack right
       j     # Swap the top two elements in the stack (back to the original order)
        HD   # Hide the top (modified) element, returning the original input

```

Removing the lowercase letters gives us:

```
JZZ#RHD

```

Try it online!

Explanation:

```
J             # Duplicate the input
 ZZ           # Uppercase it
   #R         # Rotate the stack to the right
      HD      # Hide the top (unmodified) element, returning the modified input

```

And with uppercase letters removed:

```
zz#j

```

Try it online!

Explanation:

```
zz            # Lowercase the input
  #j          # Treats the stack as code to be run. Pops the string from the stack
              # and pushes it straight back in again to be implicitly output

```

# Answer
> 8 votes
# Vyxal, 11 bytes

```
uN‹ß⇧:[,]_⇩

```

Full Program:

```
             # Implicit input, e.g. "Hello, World!"
uN‹          # Pushes '-1', negates it, and decrements, evaluating to `0`
   ß⇧        # Pops the top of the stack, and if it's truthy, converts the input to UPPERCASE. The top of the stack is '0', so this isn't executed
     :[,]    # Duplicates the top of the stack, and prints it if it is truthy, which it is
         _   # Discards the top of the stack
          ⇩  # Converts the input to lowercase
             # Implicit output is disabled

Output: Hello, World!

```

---

UPPERCASE PROGRAM:

```
            # Implicit input, e.g. "Hello, World!"
N‹          # Swaps the casing of the input and appends '-', evaluating to 'hELLO, wORLD!-'
  ß⇧        # Pops the top of the stack, and if it's truthy, converts the input to UPPERCASE. The top of the stack is a non-empty string, so this is executed
    :[,]    # Duplicates the top of the stack, and prints it if it is truthy, which it is
        _   # Discards the top of the stack
         ⇩  # Converts the input to lowercase
            # Implicit output is disabled

Output: HELLO, WORLD!

```

---

lowercase program:

<pre><code>           # Implicit input, e.g. "Hello, World!"
u‹         # Pushes '-1' and decrements, evaluating to '-2'
  ⇧        # Performs graded_up() on the top of the stack, evaluating to '0'
   :[,]    # Duplicates the top of the stack, and prints it if it is truthy. '0' is falsey, so it is not executed
       _   # Discards the top of the stack
        ⇩  # Convert the input to lowercase
           # Implicit output

Output: hello, world!
```
</code></pre>

# Answer
> 7 votes
# Vim, 5 bytes

```
VgUu$

```

---

Full Program:

```
V      # Enter Visual Line mode
 gU    # Change all characters to UPPERCASE
   u   # Undo
    $  # Go to end of line

```

---

UPPERCASE PROGRAM:

```
V    # Enter Visual Line mode
 U   # Convert all characters to UPPERCASE
  $  # Go to end of line

```

---

lowercase program:

```
gu$  # Convert all letters to lowercase from here to end of line

```

# Answer
> 5 votes
# SNOBOL4 (CSNOBOL4), ~~114~~ 96 bytes

```
	OUTput =inPUT :(enD)
Den	OUTPUToutput =REPLACEreplace(INPUTinput,&LCASEucase,&UCASElcase)
END
end

```

Try it online!

T !

ry it online!

(Ab)uses SNOBOL's case-insensitivity and GOTO labels.

# Answer
> 5 votes
# JavaScript (Node.js), ~~84~~ 81 bytes

```
_=>_['A'?'slice'||'\164\157U\160\160\145\162C\141\163\145':'to\x4cower\103ase']()

```

Try it online!

Trivial one

# JavaScript (Node.js) work if `\123` was an error, 170 bytes

```
$=_=>_['A'?'slice'||(/A/,[,A,,S,,,O,,,E,C]=!1+{},[T,R]=!0+_,[U,N]=_._+_,$[C+O+N+S+T+R+U+C+T+O+R](`P='\\${U}0070'`)(),T+O+'U'+P+P+E+R+'C'+A+S+
Ea):'to\Zx4cower\Zx43ase']()

```

Try it online!

# JavaScript (Node.js) strict, ~~186~~ 184 bytes

```
(_,[,A,,S,,,O,,,E,C]=!1+{},[T,R]=!0+_,[U,N]=_._+_)=>0xE0?_:_['A'?(/A/,(_=>_)[C+O+N+S+T+R+U+C+T+O+R]('U',`U[0]='\\${U}0070'`)(U=[]),T+O+'U'+U+U+E+R+'C'+A+S+
Ea):'to\Zx4cower\Zx43ase']()

```

Try it online!

# Answer
> 5 votes
# Attache, 243 bytes

```
{`+^^(_[0...#_]|{[[_,alpha[_2[ascii[33:58],_]]]["Z@"<_∧_<"["],NTS[20363848091226750223144960725905269888206028302]@_2[NTS[6060454347787589083238889994600682623947941084],_]]["z`"<_∧_<"{"]}&_2)}&({[`0,[$,`_3][_@_3=_2]][_3<#_][_,_2,_3+1]}&0)

```

Try it online!

At first, I wasn't sure if it was possible. However, this is in fact possible due to two key factors:

1. We have a lot of symbols at our disposal, including variable names in lambdas being accessible entirely symbolically: `_`, `_2`, etc.
2. We have the `ascii` variable to work with while having access to lowercase letters, and `NTS` (**N**umber **T**o **S**tring) while having access to uppercase letters. The former is simply a string consisting of the ASCII bytes 32 to 126. The latter is a function that takes a number and gives a string representation of it. The first long number corresponds to the uppercase alphabet, and the second to the lowercase one.

## Explanation

Now, for why this is such a troubling problem in this language. Attache functions are almost exclusively PascalCase, making them unsuitable for either computation. This means we do not have access to basic functions like string lookup, which we have to implement from scratch. This can be found at the end of the code:

```
{[`0,[$,`_3][_@_3=_2]][_3<#_][_,_2,_3+1]}&0
{                                       }&0    function with right parameter = 0
                                               parameters: string, search[, index = 0]
 [  ,                ][_3<#_]                  if index < length(string) then
     [ ,   ][_@_3=_2]                            if string[index] = search then
        `_3                                         yield a fn returning the index
      $                                          else yield this current function
  `0                                           else yield 0
                             [_,_2,_3+1]       call the result with the arguments, and index + 1

```

This snippet exhibits how we do conditional computation and recursion without letters. Thankfully, Attache has the Self reference `$`, which makes this leagues easier than it would be otherwise.

The main attraction takes this helper as a right argument, and is referenced (and passed manually down through scopes) as `_2`. I'll remove the body of the mapped function to explain how the main function works generally:

```
{`+^^(_[0...#_]|{-------}&_2)}&(-------)
                              &(-------)   saving the helper function as _2
{                            }             function taking a string as _
      _[0...#_]                            get characters of input
               |{-------}                  map each character by this function
                         &_2               (passing down _2)
 `+^^(                      )              fold concatenation, returning a string

```

Last, the function which tests each character and makes the conversion. The difference is made when testing for conditions. Two seperate conditions are checked:

1. `"Z@"<_∧_<"["`
2. `"z`"\<\<"{"\`

Without any intervention, they both return false. We index into a nested array, obtaining `arr[0][0]`, in which is placed the input. So, by default, the input is unchanged.

When removing uppercase letters, the first condition will become true for uppercase letters. When removing lowercase letters, the second condition will become true for lowercase letters. So, we have that `arr[1]` corresponds to the lower-to-upper transformation, and `arr[0][1]` corresponds to the upper-to-lower transformation. This is seen in this structure, where we index by the comparison.

```
[[_,--------]["Z@"<_∧_<"["],--------]["z`"<_∧_<"{"]

```

Both transformations have the form:

```
Desired[_2[Source,Element]]

```

That is, they find the index in the alphabet the mapped element belongs to, then index that into the other alphabet. For upper-to-lower, we can use `alpha` and `ascii[33:58]` to obtain the lowercase and uppercase alphabets, respectively. For lower-to-upper, we can use `NTS` on `20363848091226750223144960725905269888206028302` and `6060454347787589083238889994600682623947941084` to obtain the uppercase and lowercase alphabets, respectively. (These numbers are obtained by inputting the desired string to `STN`).

And with that, the program functions in all three cases.

# Answer
> 4 votes
## Keg, ~~42~~ 38 bytes

Turns out that  and  aren't implemented! That surely gives me a headache to implement that myself. (No TIO 'cuz the TIO interpreter has a bug. Use the offline interpreter instead.)

```
AAa!&ø?&¦3(:AZ•[ -]")|2(:za•[ +]")║_™^

```

## Explanation

```
AAa                                    # Push the "magic string"
   !                                   # Find the length
    &                                  # Save the result into the accumulator
     ø                                 # Clear the stack
      ?&                               # Take input, append accumulator value
        ¦3(:AZ•[ -]")|2(:za•[ +]")║_™  # Default condition: directly return the input
                                     ^ # Reverse the stack

```

No lowercase letters:

```
AA!                                 # Here, the length of the "magic string" is 2
   &ø?&                             # Same as above
       ¦3                           # If the length of the stack is 2:
         (                          # Do this for every stack item:
          :AZ•                      # Is this in the A-Z range?
              [ -]                  # If so, lowercase it
                  ")|2(:•[ +]")║_™^ # Same as above

```

No uppercase letters works similarly.

# Answer
> 4 votes
# Haskell, 90 bytes

```
(<$>)__
__ _'|0XA<1&&_'>'@'&&_'<'['||0xa<1&&_'>'`'&&_'<'{'=([_'..'~']++['?'..])!!32|1<2=_'

```

Try it online!

# Answer
> 3 votes
# Charcoal, 12 bytes

```
≡_¦_a↥Ｓ_A↧θＳ

```

Try it online! Link is to verbose version of code. Explanation:

```
≡_

```

Switch on `_`.

```
_a↥Ｓ

```

If it equals `_a` (i.e. never) then print the input uppercased.

```
_A↧θ

```

If it equals `_A` (i.e. never) then print the input lowercased.

Otherwise print the input unchanged.

With uppercase characters (including ) removed:

```
≡_¦_a↥_↧θ

```

Try it online! Explanation:

```
≡_

```

Switch on `_`.

```
_a↥_

```

If it equals `_a` (i.e. never) then print `_` uppercased.

```
↧θ

```

Otherwise print the input lowercased.

With lowercase characters (including `θ`) removed:

```
≡_¦_↥Ｓ_A↧Ｓ

```

Try it online! Explanation:

```
≡_

```

Switch on `_`.

```
_↥Ｓ

```

If it equals `_` (i.e. always) then print the input uppercased.

```
_A↧Ｓ

```

If it equals `_A` (i.e. never) then print the input lowercased.

Obviously both programs still work if you only delete ASCII upper/lowercase characters.

# Answer
> 3 votes
# , 127 bytes

```
aA=`\143`("\101-\132","\141-\172")
`\164`=1
`\143\141\164`(`\143\150\141\162\164\162`(aA[T+1],aA[t+1],`\163\143\141\156`(,"")))

```

Try it online!

This uses the octal code trick to write most of the code without letters.

In its unaltered version, it is equivalent to

```
aA=c("A-Z","a-z")
t=1
cat(chartr(aA[T+1],aA[t+1],scan(,"")))

```

Recall that `T` is the boolean `TRUE` and will be coerced to `1`, so we are calling `cat(chartr("a-z","a-z",scan(,"")))` which will leave the input unchanged.

## No lowercase

Remove the lowercase letters and you get code equivalent to

```
A=c("A-Z","a-z")
t=1
cat(chartr(A[T+1],A[+1],scan(,"")))

```

Try it online!

so we are calling `cat(chartr("a-z","A-Z",scan(,"")))`, which will convert to uppercase.

## No uppercase

Remove all uppercase characters and the code becomes equivalent to

```
a=c("A-Z","a-z")
t=1
cat(chartr(a[+1],a[t+1],scan(,"")))

```

Try it online!

This time, we are calling `cat(chartr("A-Z","a-z",scan(,"")))`, which converts to lowercase.

# Answer
> 3 votes
# Zsh, 30 bytes

```
:A&&1=$1:l
:a&&1=${(U)1}
<<<$1
```

Attempt This Online!

A T O!

ttempt his nline!

`:` is a command which does nothing and always succeeds, but both `:A` and `:a` don't exist and always fail.

Conveniently, Zsh has two ways to change the case of a string: `${(U)string}`/`${(L)string}`, and `$string:u`/`$string:l`.

# Answer
> 2 votes
# PHP (224 Bytes)

```
<?=!fPassthru(STDIN)&&0;__HALT_compiler();FUNCTIONfunction fPassthru(){returnRETURN STDIN;};functionFUNCTION __HALT_compiler(){ECHOecho                                                       STRTOUPPERstrtolower(STREAMstream_GETget_CONTENTScontents(Pfopen('php://stdin','r')));}

```

## Uppercase version

```
<?=!P(STDIN)&&0;__HALT_();FUNCTION P(){RETURN STDIN;};FUNCTION __HALT_(){ECHO STRTOUPPER(STREAM_GET_CONTENTS(P('://','')));}

```

## Lowercase version

```
<?=!fassthru()&&0;___compiler();function fassthru(){return ;};function ___compiler(){echo strtolower(stream_get_contents(fopen('php://stdin','r')));}

```

# Answer
> 2 votes
# Befunge-98 (PyFunge), 51 bytes

```
<aaA^:~@#
, >-\:'``\'{^
^ 1>\:'@`\'[>\`**' *+
^ 01>

```

Try it online!

Try it online! (Uppercase letter removed)

Try it online! (Lowercase letters removed)

## Explanation

Without removing any characters, most of the code is never executed. The code that does get executed is

```
<   ^:~@#
,
^
^   >

```

This reads each character sequentially with `~`, duplicates it with `:`, and then prints the duplicate. Once the input runs out, `~` reflects the instruction pointer and `@` ends the program. A copy of the input string is left on the stack, but it never gets printed, so we don't care about it.

With the uppercase `A` removed, the `^` on the top line moves one space to the left and the third line is executed rather than the second.

```
<  ^:~@#
,
^  >\:'@`\'[>\`**' *+
   1

```

This sequentially reads through the input with `:~@#` as before. Then, it puts a 1 on the stack, followed by two copies of the character. The two duplicates are compared against `'@` and `'[` (64 and 91 respectively) to see whether the character is an uppercase letter. If it is, the product of these checks (1\*1=1) is multiplied by 1 and then by the code point of  (space) to get 32, which is then added to the original character to make it lowercase. However, if the character is not uppercase, one of the comparisons will return 0. This 0 gets multiplied by a bunch of things and then added to the original character, and so the character remains unaltered when it is printed.

With the lowercase `a`s removed, the first `^` is now shifted over two spaces to the left, and the second line is executed rather than the fourth.

```
< ^:~@#
, >-\:'``\'{^
^ 1         >\`**' *+
  0

```

This does mostly the same thing, except -1 is pushed onto the stack rather than 1 at the beginning of the loop and the bounds are replaced with 96 and 123 (to see whether it is lowercase). Then, the `^` (we can't use `v` because it's lowercase!) shifts the IP down a line, to execute the same logic as before. If the character is a lowercase letter, 1 is multiplied by the top of the stack (which is now -1 rather than 1) and by 32 to get -32, which is added to the original character to make it uppercase. As before, if the character is not lowercase, 32 is multiplied by 0 and the final `+` does nothing.

In all cases,

```
<
,
^
^

```

is executed at the end of the loop, printing the possibly modified character and rerouting the IP back to the start.

# Answer
> 2 votes
# Brachylog, 22 bytes

```
İḷ|f{;.P∧Ạ{∧Ṇ}ᶻ∋P∧|}ᵐ|

```

Try it online! try it online! TRY IT ONLINE!

I had some bizarre errors trying to use subscripted /. Takes a string through the input variable and outputs through the output variable, since printing is impossible without lowercase letters.

```
İ                         The input is an integer, but it's not,
 ḷ                        ...
  |                       so maybe...
   f                      its factors, but it doesn't have factors...
    {;.P∧Ạ{∧Ṇ}ᶻ∋P∧|}ᵐ     ...
                     |    so just output it unchanged.

 ḷ                        The input converted to lowercase
  |                       is the output.
  |f{;. ∧ {∧ }ᶻ∋ ∧|}ᵐ|    Hooray, that worked, forget everything else.

İ                         The input is an integer, except it's not,
  | {              }ᵐ     so then instead for each element of the input
     ;.                   that element paired with the output it's mapped to
       P                  is P,
        ∧                 and
         Ạ                the lowercase alphabet
          {∧ }ᶻ           zipped with (I don't actually know why this works!)
            Ṇ             a list of all printable ASCII characters (ABCDEFGHI...)
               ∋P         contains P
                 ∧        (which isn't the output);
                  |       if that's impossible pass the element through unchanged.
                     |    Since that worked, we don't worry about the rest.

```

# Answer
> 2 votes
# Julia 1.0, ~~72~~ 49 bytes

```
Zz=0;Yy=z=Z=0;~Xx=@.Xx+('`'<Xx+32Z<'{')*(32Z-32z)

```

Try all 3 versions online!

input and output are lists of characters

# Answer
> 2 votes
### Haskell, 208 bytes or 210 bytes

Note: my original, shorter, solution was buggy. This one seems pretty solid. This challenge is not so easy in Haskell; there's no golfing here, aside from space removal. I imagine it's possible to do better.

```
(!)((/):($))((#):(*))(+)|(+)==(/)=(#)|0<1=(!)($)(*)(+)
(!)_ _(+)=(+)
(&)[(*)]=[]
(&)((*):(+))=(*):(&)(+)
_:(#)=(&)['@'..'[']
_:(%)=(&)['`'..'{']
(+*)|"A"==[]=(!)(#)(%)|"a"==[]=(!)(%)(#)|0<1= \(+)->(+)
(+*)<$>

```

The first seven lines are definitions. The last line is prepended to the input, like

```
(+*)<$>"My name is David."

```

If you don't accept this, you can upgrade to a "function" by enclosing in parentheses, at the cost of two bytes. To make a proper function definition, you'd turn on `NoMonomorphismRestriction` and write, say,

```
(##)=((+*)<$>)

```

### Explanation

Haskell variables (including function names) generally have to start with a lower-case letter. Infix operators, however, can consist of various symbols, as long as they don't begin with a `:`. So ... all the functions defined and their argument names are written as operators. An operator enclosed in parentheses is treated as a regular old name, so this works. The case restriction prevents us from using any standard functions except infix ones, and also prohibits us from importing any modules. So we can't use `fromEnum`, `toEnum`, `ord`, `chr`, or `unsafeCoerce` to manipulate characters as numbers. Instead we write a function, `(!)`, that looks for a character in a list, and produces the character in the same position in the second list if it's found. These lists are produced rather awkwardly using characters before and after the lower and upper case ASCII ranges and a hand-rolled version of `init` (called `(&)`).

# Answer
> 1 votes
# Lua, 111 bytes

```
bB=...aA=io or _G['\112\114\105\110\116'](('')['\117\112\112\101\114'](B))load"print(_G and bB or b:lower())"()

```

Try it online!

## Lowercase Version

```
b=...a=io or _['\112\114\105\110\116'](('')['\117\112\112\101\114']())load"print(_ and b or b:lower())"()

```

## Uppercase Version

```
B=...A=  _G['\112\114\105\110\116'](('')['\117\112\112\101\114'](B))"(_G  B  :())"()

```

## Explanation

This code takes input as a command line argument, and can effectively be split up into two conditionals.

```
aA=io or _G['\112\114\105\110\116'](('')['\117\112\112\101\114'](B))

```

This segment is equivalent to `aA=io or print(B:upper())`, just written in a way to avoid lowercase characters for the print. Normally, this section of code does nothing because `io` is a truthy value. When lowercase letters are removed, `io` and `or` are removed, allowing the print to occur.

```
load"print(_G and bB or b:lower())"()

```

This segment is surrounded by a `load` call because without it, Lua will see this part as a syntax error when attempting to run the uppercase version. The uppercase version will throw a runtime error when it encounters this part, however.

The normal version will see `_G` as a truthy value and print the input as-is. The lowercase version will instead see `_` as a falsy value and print the input in lowercase.

---
Tags: code-golf, source-layout
---


title: Find the hardest OEIS sequence to golf!

text:
# Question
Title: Find the hardest OEIS sequence to golf!
Notice: This question originally had people write comments with a shorter program, rather than new answers. This has been changed so that people with shorter programs can get reputation too. Hopefully this doesn't become unmanageable...

There have been a couple of OEIS-related questions recently, so here's another:

Pick a sequence from the Online Encyclopedia of Integer Sequences, and write a full program or function which computes the sequence in one of the following ways:

* It prints every term in the sequence in order
* It takes an index in the sequence as input, and returns/outputs the term at that index.

You will be trying to pick the sequence with the longest possible shortest possible program/function to compute that sequence (see the example below if that's confusing). You must include which sequence you are using in your answer.

Try to make your program/function as short as possible. **If anyone can find a shorter program which computes the same sequence, they should add a another answer with their shorter program**. If you do find a shorter program than someone else, you should refer to their answer in yours. For all answers, a Try it Online link would be nice. If someone else has written a shorter program than yours, it would be nice if you put a link to it in your answer.

Of course, none of the programs should access the internet or the OEIS in any way, and they should all theoretically work on arbitrarily large inputs (you can ignore things like the maximum size of an integer type).

The sequence with the longest shortest program in bytes is the winner.

## For example,

Let's say I pick the sequence A000027, the positive integers, and I submit this answer:

# Python, 49 bytes, A000027

```
x = "o"
while True:
    print len(x)
    x += "o"

```

Obviously this is not a very short program for computing that sequence, so someone else (let's call them foo) might come along and add this answer:

# Haskell, 2 bytes, A000027:

```
id

```

(`id` is the identity function, so it will just return whatever you pass into it, and because the `n`th positive integer is just `n`, it will compute that sequence).

Then, the person who posted the Python solution should edit their answer:

# Python, 49 bytes, A000027

Superseded by foo's answer (link).

```
x = "o"
while True:
    print len(x)
    x += "o"

```

As long as no one else finds a shorter program, this sequence would get a score of `2` (because `id` is two bytes), and the sequence with the highest score wins.

---

Current best sequence: A014715, 252 bytes

# Answer
# Wolfram Language (Mathematica), ~~270~~ 252 bytes A014715

**252 bytes, by Expired Data**

```
RealDigits[NSolve[3x-6==Plus@@({6,-12,4,-7,7,-1,0,-5,2,4,12,-2,-7,-12,7,10,4,-3,-9,7,0,8,-14,3,-9,-2,3,10,2,6,-1,-10,3,-1,-7,7,-7,12,5,-8,-6,-10,8,8,7,3,-9,-1,-6,-6,2,3,10,2,-3,-5,-2,1,1,1,1,1,-1,-2,-2,1,2,1,0,-1}x^2~Range~71),x,#][[-1,-1,-1]]][[1,#]]&

```

Try it online!

I've never golfed in mathematica before, but the sequence seemed like an obvious contender. The code is more or less a copy of the example on the OEIS page.

The sequence is the decimal expansion of Conway's constant, which itself is the root of this polynomial:

\\$x^{71}-x^{69}-2x^{68}-x^{67}+2x^{66}+2x^{65}+x^{64}-x^{63}-x^{62}-x^{61}-x^{60}-x^{59}+2x^{58}+5x^{57}+3x^{56}-2x^{55}-10x^{54}-3x^{53}-2x^{52}+6x^{51}+6x^{50}+x^{49}+9x^{48}-3x^{47}-7x^{46}-8x^{45}-8x^{44}+10x^{43}+6x^{42}+8x^{41}-5x^{40}-12x^{39}+7x^{38}-7x^{37}+7x^{36}+x^{35}-3x^{34}+10x^{33}+x^{32}-6x^{31}-2x^{30}-10x^{29}-3x^{28}+2x^{27}+9x^{26}-3x^{25}+14x^{24}-8x^{23}-7x^{21}+9x^{20}+3x^{19}-4x^{18}-10x^{17}-7x^{16}+12x^{15}+7x^{14}+2x^{13}-12x^{12}-4x^{11}-2x^{10}+5x^{9}+x^{7}-7x^{6}+7x^{5}-4x^{4}+12x^{3}-6x^{2}+3x-6\\$
> 4 votes

# Answer
# Python 3, 3 bytes, A055642

Finally, a ridiculously short answer that isn't just A000027 or some other stupidly simple sequence.

```
len

```

This is a function. Number should be inputted as a string of its digits. Undefined behavior for non-integers and other strings.
> 2 votes

# Answer
# cQuents, 1 byte, A000027

```
$

```

Try it online!

Just to have a baseline answer in case every other answer is cracked.
> 1 votes

# Answer
# Wolfram Language (Mathematica), 490,453 bytes A002205

```
FromDigits[ToCharacterCode[StringReplace["$H\.06,\.1dVngsIno\.12RT",":3:"->FromCharacterCode[13]]]-1,127]

```

Where \\.FF is a single byte of that value.

Try it online! \- Limited to 2000 digits, I don't think the dev would appriciate ~1.5M of data coming through.

I took a while to search though the OEIS 'webcam', but I paused and looked at XKCD, where it mentioned the book "A Million Random Digits with 100,000 Normal Deviates". And what do you know, it's A002205. A pretty old entry too.

According to dieharder, a program for finding if a sequence of numbers is random, the sequence is pretty random, so I doubt there's going to be an algorithm to generate a given number. This makes it more of a Kolmogorov-complexity problem. Since every number is between 0 and 9 inclusive, then there are Log2\[10\] bits of information in a digit, or `1,000,000 * Log2[10]/Log2[256] bytes` of information total, or just a tad under 415,242 bytes.

My final solution was to take the entire 1,000,000 digit number in as a number (big-int in other languages), convert it to base 127, and then put it in the range 1-127. `1,000,000 * Log2[10]/Log2[127] = 475,330 bytes`. Character 13 is the Carriage Return, which is converted to a Line Feed on most systems, so it's replaced with the trigraph :3:, since all the digraphs are taken. Mathematica was surprisingly happy to convert a 1 million digit number to base 127. The answer can be optimized, since TIO allows the entire 127+ unicode space, but using this method the results would only reduce the score by 1%.

Here is the encoder I used, where `str` is a string containing all the digits:

```
StringReplace[FromCharacterCode[IntegerDigits[FromDigits[str],127]+1],{"\\"->"\\\\","\""->"\\\"",FromCharacterCode[13]->":3:"}]

```

BZIP2 can compress the data down to 431,122 bytes, which is pretty close, but I felt just BZipping the data and calling it an answer was a bit cheap since it's not a 'language', as much as those answers have been fun on other questions.
> 0 votes

---
Tags: code-golf, sequence, cops-and-robbers, code-bowling
---


title: The rice and chess problem

text:
# Question
Title: The rice and chess problem
An Indian legend tells the story of the alleged inventor of the chess game, who impressed the emperor of India with his game so much that he would get rewarded with anything asked.

The man said he wanted to be paid in rice. He wanted a grain of rice for the first square of the chessboard, two for the second, four for the third, eight for the fourth, and so on, until the 64th square.

The emperor was amazed that the man asked for such a small reward, but as his mathematicians started counting, he ended up losing one of his provinces.

# Task

Given the length of the side of a hypothetical chessboard (which is 8 on a default chessboard) and the multiplier between squares (which is 2 in the legend), calculate the number of grains of rice the emperor must pay to the man.

# Notes

* The side length will always be a positive integer. The multiplier could instead be any kind of rational number.
* If your language of choice can't display very large numbers, it's okay as long as your program can correctly process smaller inputs.
* Also if your language of choice rounds larger values (with exponential notations), it's okay if those values are approximately correct.

# Testcases

```
Input (side length, multiplier) => Output
8, 2                            => 18446744073709551615
3, 6                            => 2015539
7, 1.5                          => 850161998.2854
5, -3                           => 211822152361
256, 1                          => 65536
2, 2                            => 15
2, -2                           => -5

```

Please note that the explicit formula

```
result = (multiplier ^ (side ^ 2) - 1) / (multiplier - 1)

```

Performs wrong on `multiplier = 1`, as

```
1 ^ (side ^ 2) - 1 = 0
1 - 1 = 0
0 / 0 != side ^ 2 (as it should be)

```

# Scoring

This is code-golf. Shortest answer in bytes wins.

# Answer
> 22 votes
# Jelly, 4 bytes

```
²b1ḅ

```

This uses the approach from @APLDude's clever APL answer.

Try it online! or verify all test cases.

### How it works

```
²b1ḅ  Main link. Arguments: x (side length), y (multiplier)

²     Square; yield x².
 b1   Convert to base 1 (unary), yielding a list of x² ones.
   ḅ  Convert from base y to real number.
      This yields y^(x²-1) + ... + y + 1.

```

# Answer
> 28 votes
# MATL, 6 bytes

```
2^:q^s

```

**Try it online!**

```
2^   % Take implicit input, say N, and square it: N^2
:q   % Generate array [0 1 ... N^2-1]
^    % Take implicit input, M, and compute [M^0 M^1 ... M^(N^2-1)]
s    % Sum of the array. Implicit display

```

# Answer
> 23 votes
# APL, 10 bytes

```
⎕⊥1+0×⍳⎕*2

```

is used to read user input twice. If we store the side length in **s** and the multiplier in **m**, we get the following code.

```
m⊥1+0×⍳s*2

```

And here's how APL parses this code:

# Answer
> 19 votes
## Python, 40 bytes

```
lambda n,m:eval('1+m*('*n*n+'0'+')'*n*n)

```

Generates and evaluates a string like

```
1+m*(1+m*(1+m*(1+m*(0))))

```

that encodes the sum as a Hornerized polynomial with `n*n` terms.

A lot of different methods gave very similar byte counts:

```
#String evaluation
lambda n,m:eval('1+m*('*n*n+'0'+')'*n*n)   #40

#Direct summation
lambda n,m:sum(m**i for i in range(n*n))   #40
lambda n,m:sum(map(m.__pow__,range(n*n)))  #41

#Direct formula
lambda n,m:n*n*(1==m)or(m**n**2-1)/(m-1)   #40

#Iterative sequence
f=lambda n,m,j=0:j<n*n and 1+m*f(n,m,j+1)  #41
def f(n,m):s=0;exec"s=s*m+1;"*n*n;print s  #41

#Recursive expression
#Fails due to float imprecision of square root
f=lambda n,m:n and 1+m*f((n*n-1)**.5,m)    #39*

```

# Answer
> 11 votes
# Pyth, 6 bytes

1 byte saved thanks to @FryAmTheEggman.

```
s^Lvz*

```

Try it online!

Test suite.

# Answer
> 11 votes
# JavaScript (ES2016/ES7), ~~31~~ ~~29~~ 28 bytes

```
a=>b=>(b**(a*a)-1)/--b||a*a

```

Just @Bassdrop Cumberwubwubwub and @Kaizo's ES6 version, but with exponentiation operator. :) (I didn't have enough reputation to comment instead.)

Edit: `/+(b-1)` changed to `/--b` (thanks @Neil).

Edit: now uses currying (thanks @MamaFunRoll).

# Answer
> 11 votes
## Haskell, 25 bytes

```
n%m=sum$(m^)<$>[0..n*n-1]

```

Sums the list `[m^0, m^1, ..., m^(n*n-1)]`.

# Answer
> 10 votes
# Jelly, 6 bytes

```
²R’*@S

```

Try it online!

# Answer
> 8 votes
# Javascript ES6, ~~59~~ ~~37~~ ~~35~~ 34 bytes

```
a=>b=>(Math.pow(b,a*a)-1)/--b||a*a`

```

Thanks to @Kaizo for shaving off a whopping 19 bytes, @Neil for another 2 and @gcampbell for 1 more!

Try it here

```
f=
a=>b=>(Math.pow(b,a*a)-1)/--b||a*a

a.innerHTML='<pre>'+
  [[8,2],
   [3,6],
   [7,1.5],
   [5,-3],
   [256,1],
   [2,2],
   [2,-2]].map(b=>`${b[0]}, ${b[1]} => ${f(b[0])(b[1])}`).join('<br>')+'</pre>'
```

```
<div id=a>
```

# Alternative broken versions

**32 bytes**

```
(a,b)=>(Math.pow(b,a*a)-1)/(b-1)

```

Causes `NaN` for `b==1`.

**30 bytes**

```
(a,b)=>(Math.pow(b,a*a)-1)/~-b

```

Causes `Infinity` for `b==1.5`.

**28 bytes**

```
(a,b)=>~-Math.pow(b,a*a)/~-b

```

Outputs `1` for some valid testcases.

# Old version for 59 bytes

`(a,b)=>Array(a*a).fill``.reduce((c,d,i)=>c+Math.pow(b,i),0)`

# Answer
> 8 votes
# MATLAB, 23 bytes

```
@(n,k)sum(k.^(0:n^2-1))

```

Test it here!

# Answer
> 6 votes
# Java, 132 bytes

```
import java.math.*;Object e(int n,BigDecimal m){BigDecimal r=BigDecimal.ONE,a=r;for(n*=n;n>1;n--)r=r.add(a=a.multiply(m));return r;}

```

### Ungolfed

```
import java.math.*;

Object e(int n, BigDecimal m) {
    BigDecimal r = BigDecimal.ONE, a = r;
    for (n *= n; n > 1; n--)
        r = r.add(a = a.multiply(m));
    return r;
}

```

### Notes

* This will work for arbitrarily big outputs as required by OP (Too bad Java supports big numbers, this would be shorter otherwise).

### Outputs

```
Input:      8 2.0
Expected:   18446744073709551615
Actual:     18446744073709551615

Input:      3 6.0
Expected:   2015539
Actual:     2015539

Input:      7 1.5
Expected:   850161998.2854
Actual:     850161998.285399449204543742553141782991588115692138671875

Input:      5 -3.0
Expected:   211822152361
Actual:     211822152361

Input:      256 1.0
Expected:   65536
Actual:     65536

Input:      2 2.0
Expected:   15
Actual:     15

Input:      2 -2.0
Expected:   -5
Actual:     -5

Input:      263 359.9
Expected:   ?
Actual:     9709...[176798 digits]...7344.7184...[69160 digits]...6291

```

# Answer
> 6 votes
# R, 18 bytes

```
sum(m^(1:s^2-1))

```

Explanation:

```
sum(               # Calculate sum
    m              # Multiplier
     ^             # Exponentiate
      (1:s^2-1))   # Generate sequence from 1 to s(ide)^2-1

```

# Answer
> 5 votes
# 05AB1E, 5 bytes

Code:

```
nL<mO

```

Explanation:

```
n      # Compute i ** 2
 L     # Push the list [1, ..., i ** 2]
  <    # Decrement by 1, [0, ..., i ** 2 - 1]
   m   # Power function with implicit input, [0 ** j, ..., (i ** 2 - 1) ** j]
    O  # Sum that all up

```

Try it online!.

# Answer
> 4 votes
## Haskell, 30 bytes

```
n#m=sum$take(n^2)$iterate(*m)1

```

or equally long

```
n%1=n^2
n%m=(m**(n*n)-1)/(m-1)

```

The first version starts with `1` repeatedly multiplies with `m`. Then it sums the first `n^2` numbers of this sequence. The second version is the explicit formula as seen in other answers.

# Answer
> 4 votes
# J, 10 bytes

```
+/@:^i.@*:

```

## Usage

I mark some integers with the `x` suffix to use extended integers to get exact results.

```
   f =: +/@:^i.@*:
   2x f 8
18446744073709551615
   3x f 6
75047317648499560
   6x f 3
2015539
   1.5 f 7
8.50162e8
   _3x f 5
211822152361
   1 f 256
65536
   2 f 2
15
   _2 f 2
_5

```

## Explanation

```
+/@:^i.@*:
        *:  Square the value s to get s^2
     i.@    Make a range from 0 to s^2 exclusive, [0, 1, ..., s^2-1]
    ^       Using m as the base, calculate the power with the range
            [m^0, m^1, ..., m^(s^2-1)]
+/@:        Sum the entire list and return it

```

# Answer
> 4 votes
# PostgreSQL, 67 66 bytes

```
SELECT SUM(m^v)FROM(VALUES(3,6))t(s,m),generate_series(0,s*s-1)s(v)

```

`**`SqlFiddleDemo`**`

Input: `VALUES(side, multiplier)`

---

**EDIT:**

Input moved to table, all cases at-once:

```
SELECT s,m,SUM(m^v)FROM i,generate_series(0,s*s-1)s(v)GROUP BY s,m

```

`**`SqlFiddleDemo`**`

Output:

```
╔══════╦══════╦══════════════════════╗
║  s   ║  m   ║         sum          ║
╠══════╬══════╬══════════════════════╣
║   7  ║ 1.5  ║ 850161998.2853994    ║
║   2  ║ 2    ║ 15                   ║
║   2  ║ -2   ║ -5                   ║
║ 256  ║ 1    ║ 65536                ║
║   5  ║ -3   ║ 211822152361         ║
║   8  ║ 2    ║ 18446744073709552000 ║
║   3  ║ 6    ║ 2015539              ║
╚══════╩══════╩══════════════════════╝

```

# Answer
> 4 votes
## Mathcad, \[tbd\] bytes (~11)

Uses Mathcad's built in summation operator. Also demonstrates symbolic processor simplification to generate exact formula.

Mathcad effectively runs two processing engines in parallel - one a standard IEEE 64/80 bit floating point, and the other an arbitrary number length symbolic process (MuPad). Standard numerical evaluation is indicated by equals sign (=), whilst a right arrow indicates symbolic evaluation.

---

Mathcad counting scheme yet to be determined so no byte count given.

ctl-$ enters the summation operator (Sigma), including empty placeholders to put the summation variable, initial value, final value and expression. Approximate byte-equivalent count = 11.

# Answer
> 3 votes
# Python, 40 bytes

```
lambda l,m:sum(m**i for i in range(l*l))

```

# Answer
> 3 votes
# TI-Basic, 19 bytes

`S` is side length, and `M` is the multiplier.

```
Prompt S,M:Σ(M^I,I,0,S²-1

```

# Answer
> 3 votes
# Ruby: 39 bytes

```
->s,m{(0...s*s).reduce(0){|a,b|a+m**b}}

```

**Test:**

```
f = ->s,m{(0...s*s).reduce(0){|a,b|a+m**b}}

f[8,2]   # 18446744073709551615
f[3,6]   # 2015539
f[7,1.5] # 850161998.2853994
f[5,-3]  # 211822152361
f[256,1] # 65536
f[2,2]   # 15
f[2,-2]  # -5
f[1,1]   # 1

```

# Answer
> 3 votes
# Python, 41 Bytes

Totally new at this golfing thing, criticism welcome!

```
lambda n,m:sum(m**i for i in range(n**2))

```

# Answer
> 2 votes
# Jolf, ~~18~~ ~~15~~ 10 bytes

*Thanks to Cᴏɴᴏʀ O'Bʀɪᴇɴ for saving 3 bytes and pointing me towards mapping*

```
uΜzQjd^JwH

```

Try it here!

```
 ΜzQj       Map over an array of 1 -> square(side length)
     d^JwH  Set the current array value to multiplier^(current value - 1)
u           Sum the array

```

# Answer
> 2 votes
# Mathematica, 22 bytes

```
Tr[#^(Range[#2^2]-1)]&

```

Creates a range of `{1, 2, ... s^2}`, subtracts 1 over it to make `{0, 1, ..., s^2-1}`. Then raise each to the power of `m` making `{m^0, m^1, ..., m^(s^2-1)}` and return the sum of it.

Alternatively, Mathematica can use the explicit formula by taking its limit. This requires **29** bytes.

```
Limit[(s^#^2-1)/(s-1),s->#2]&

```

# Answer
> 2 votes
# CJam, 9 bytes

```
q~2#,f#:+

```

Inputs are in reverse order separated by a newline or a space.

**Try it online!**

```
q~    e# Read input. Evaluate: pushes the two numbers, M and N, onto the stack
2#    e# Square: compute N^2
,     e# Range: generates array [0 1 ... N^2-1]
f#    e# Compute M raised to each element of the array [0 1 ... N^2-1]
:+    e# Fold addition: compute sum of the array [M^0 M^1 ... M^(N^2-1)]

```

# Answer
> 2 votes
## PHP, ~~58~~ 54 bytes

```
<?function a($n,$m){$n*=$n;echo(1-$m**$n)/(1-$m)?:$n;}

```

This just uses the summation formula to show the value, after checking if the multiplier is 1 (which returns NAN in the formula).

# Answer
> 1 votes
# PARI/GP, 25 bytes

```
f(s,m)=sum(i=0,s^2-1,m^s)

```

Longer but faster (35 bytes):

```
f(s,m)=if(m==1,s^2,(m^s^2-1)/(m-1))

```

Cute (30 bytes):

```
f(s,m)=vecsum(powers(m,s^2-1))

```

# Answer
> 1 votes
# Lua, 54 47 bytes

```
r=0l,m=...for i=0,l^2-1 do r=r+m^i end print(r)

```

Run from the command line with the board side length as the first argument and the multiplier as the second.

Thanks to user6245072 for saving 6 bytes, and Katenkyo for saving an additional 1.

---

Original 54 byte version:

```
a,b=...c=1 d=1 for i=2,a^2 do c=c*b d=d+c end print(d)

```

# Answer
> 1 votes
## C#, 56 bytes

```
double f(int n,double q){return(Math.Pow(q,n*n)-1)/--q;}

```

# Answer
> 1 votes
# J, 17 bytes

A non-tacit solution, by defining a dyad:

```
f=:4 :'+/y^i.x^2'

```

e.g.

```
8x f 2

18446744073709551615

```

# Answer
> 1 votes
# , 11 chars / 14 bytes

```
⨭⩥ î²)ⓜⁿ⁽í$

```

`Try it here (Firefox/WebKit Nightly only).`

Yes, now works in WebKit Nightly! Chrome support is next.

# Explanation

```
⨭⩥ î²)ⓜⁿ⁽í$ // implicit: î = input1, í = input2
   ⩥ î²)       // generate a range [0..î^2)
                     ⓜ      // map over range ($ is mapitem):
        ⁿ⁽í$  //   í^$
⨭            // sum resulting range
              // implicit output

```

# Answer
> 1 votes
# RETURN, 32 bytes

```
[a:2^0\
{[$¥][a;\^]#[¤¥][+]#]!

```

`Try it here.`

Anonymous lambda that leaves result on Stack2. Usage:

```
8 2[a:2^0\
{[$¥][a;\^]#[¤¥][+]#]!

```

# Explanation

```
[                              ]!  lambda
 a:                                store multiplier to a
   2^                              square side-length
     0\␊                           create range [0..result)
        {                          set current stack to range
         [  ][     ]#              while loop
          $¥                         check if TOS is truthy
              a;\^␌                  if so, push a^TOS to Stack2
                     ␁            set current stack to Stack2
                       [¤¥][+]#    sum Stack2

```

# Answer
> 1 votes
## Actually, 9 bytes

```
╗²r`╜ⁿ`MΣ

```

Takes input as side length first, then multiplier.

Try it online!

Explanation:

```
╗²r`╜ⁿ`MΣ
╗          save m to reg0
 ²r        range(s**2) ([0, s**2-1])
   `  `M   map (for n in list):
    ╜ⁿ       m**n (m is pushed from reg0)
        Σ  sum

```

# Answer
> 1 votes
## Pyke, 5 bytes

```
XUm^s

```

Try it here!

```
X     - input()**2
 U   - range(0,^)
  m^  - map(^,^)
    s - sum(^)

```

# Answer
> 1 votes
# MathGolf, 4 bytes

```
²r#Σ

```

Try it online!

## Explanation

Basically a port of Luis Mendo's MATL answer, but uses some implicit operating magic of MathGolf.

```
²      Square the first input
 r     Create range [0, 1, ..., N^2-1]
  #    Map (2nd input)^i for i in the array
   Σ   Sum the array

```

# Answer
> 1 votes
# Thunno 2 `S`, 3 bytes

```
²L*

```

Try it online!

Port of Luis Mendo's MATL answer.

#### Explanation

```
²L*  # Implicit input
²    # Square the first input
 L   # Push [0..that)
  *  # Take the second input
     # to the power of each
     # Sum the resulting list
     # Implicit output

```

# Answer
> 0 votes
## C#, 48 bytes

```
x=>y=>x==1?y*y:(System.Math.Pow(x,y*y)-1)/(x-1);

```

Where x is the multiplier, y is the side length. It uses the explicit formula for the sum of the geometric series, which is a1\*(q^n-1)/(q-1), if q!=1, n\*a1, if q==1.

# Answer
> 0 votes
# k, ~~16~~ 11 bytes

Bytes shaved using the technique from a clever answer.

```
{y/(x*x)#1}

```

Try it online! <sub>(There seems to be some sort of rounding happening for large numbers.)</sub>

Explanation:

```
{         } /function, x is board length, y is multiplier
   (x*x)#1  /make a list with as many 1s as there are board squares
 y/         /read as base y number

```

# Answer
> 0 votes
# Powershell, 48 bytes

```
param($l,$m,$r)$c=1;1..$l*$l|%{$r+=$c;$c*=$m};$r

```

Test script:

```
$f = {
    param($l,$m,$r)$c=1;1..$l*$l|%{$r+=$c;$c*=$m};$r
}

@(
    ,(8, 2    ,18446744073709551615)
    ,(3, 6    ,2015539)
    ,(7, 1.5  ,850161998.2854)
    ,(5, -3   ,211822152361)
    ,(256, 1  ,65536)
    ,(2, 2    ,15)
    ,(2, -2   ,-5)
) | %{
    $x,$n,$e = $_
    $r = &$f $x $n
    "$($e-eq$r): $r $e"
}

```

Output:

```
False: 1.84467440737096E+19 18446744073709551615
True: 2015539 2015539
False: 850161998.285399 850161998.2854
True: 211822152361 211822152361
True: 65536 65536
True: 15 15
True: -5 -5

```

Differences from rounding are permitted by rules.

`$r` is a local parameter. If a parameter omitted in a caller then `$r` will have the value `$null`.

# Answer
> 0 votes
# Japt `-x`, 5 bytes

```
²o!pV

```

Try it

# Answer
> 0 votes
## F#, 51 bytes

```
let c s m=Seq.init(s*s)(fun x->m**float x)|>Seq.sum

```

Fairly straight-forward. Works as well when `m` is 1.

Try it online!

---
Tags: code-golf, math
---


title: Decode the Dreaded Alphabet Cypher™

text:
# Question
Title: Decode the Dreaded Alphabet Cypher™
This challenge is inspired by one of my other challenges: Pointlessly make your way down the alphabet

That challenge asked you to take a string of text, and for each letter produce a sequence of letters moving down the alphabet to 'a'.

For this challenge I'd like to decode the output of that challenge (minus the line breaks), to find a human-readable string from a much longer human readable string.

---

Here is some text which has been encoded using the Dreaded Alphabet Cypher™

hgfedcbaedcbalkjihgfedcbalkjihgfedcbaonmlkjihgfedcba wvutsrqponmlkjihgfedcbaonmlkjihgfedcbarqponmlkjihgfedcbalkjihgfedcbadcba

It consists of descending alphabetical sequences, ending in an 'a'. The first character in each of these sequences is a letter in the decoded text. (A space is still a space).

# The challenge

* Write code to convert a Dreaded Alphabet Cypher™ encoded string into a decoded, human-readable string.
* No need to validate if it is a Dreaded Alphabet Cypher™ string, I'm not interested in how it handles invalid input.
* Use any language you please.
* Please include a link to an online iterpreter.
* The input will only consist of lower-case letters and spaces. No upper cases, punctuation etc.
* Code golf, try to write short code, standard loopholes etc.

# Test Cases

Input:

```
hgfedcbaedcbalkjihgfedcbalkjihgfedcbaonmlkjihgfedcba wvutsrqponmlkjihgfedcbaonmlkjihgfedcbarqponmlkjihgfedcbalkjihgfedcbadcba

```

Output:

```
hello world

```

---

Input:

```
abacbadcbaedcbafedcbagfedcbahgfedcbaihgfedcbajihgfedcbakjihgfedcbalkjihgfedcbamlkjihgfedcbanmlkjihgfedcbaonmlkjihgfedcbaponmlkjihgfedcbaqponmlkjihgfedcbarqponmlkjihgfedcbasrqponmlkjihgfedcbatsrqponmlkjihgfedcbautsrqponmlkjihgfedcbavutsrqponmlkjihgfedcbawvutsrqponmlkjihgfedcbaxwvutsrqponmlkjihgfedcbayxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba

```

Output:

```
abcdefghijklmnopqrstuvwxyz

```

---

(beware the multiple a's)

Input:

```
aarqponmlkjihgfedcbaonmlkjihgfedcbanmlkjihgfedcba a aarqponmlkjihgfedcbaonmlkjihgfedcbanmlkjihgfedcbasrqponmlkjihgfedcbaonmlkjihgfedcbanmlkjihgfedcba hgfedcbaasrqponmlkjihgfedcba anmlkjihgfedcba aarqponmlkjihgfedcbadcbavutsrqponmlkjihgfedcbaarqponmlkjihgfedcbakjihgfedcba

```

Output:

```
aaron a aaronson has an aardvark

```

---

Input:

```
hgfedcbaaponmlkjihgfedcbaponmlkjihgfedcbayxwvutsrqponmlkjihgfedcba gfedcbaonmlkjihgfedcbalkjihgfedcbafedcbaihgfedcbanmlkjihgfedcbagfedcba

```

Output (is a secret, shh)

# Answer
> 16 votes
# JavaScript (ES9),  ~~37 33~~  26 bytes

Returns an array of characters.

Either a negative look-behind:

```
s=>s.match(/(?<![b-z])./g)

```

Try it online!

Or a positive look-behind:

```
s=>s.match(/(?<=a| |^)./g)

```

Try it online!

---

## 25 bytes

If the input is guaranteed not to contain leading or double spaces (or we're allowed to remove and collapse them respectively), the positive look-behind can be made 1 byte shorter:

```
s=>s.match(/(?<=a|\b)./g)

```

Try it online!

# Answer
> 13 votes
## Haskell, 32 bytes

```
f s=[y|(x,y)<-zip('a':s)s,x<'b']

```

Try it online!

For each pair of consecutive characters, if the first one is `'a'` or `' '`, output the second one. Prepends an `'a'` to the string so that the first character is always output.

# Answer
> 10 votes
# Jelly, 6 bytes

```
OŻI‘Tị

```

A monadic Link accepting a list of characters which yields a list of characters.

**Try it online!**

### How?

```
OŻI‘Tị - Link: list of characters, S   e.g. "  baadcba  acbaedcba  "
                                       i.e. [' ',' ','b','a','a','d','c','b','a',' ',' ','a','c','b','a','e','d','c','b','a',' ',' ']
O      - to ordinal (vectorises across S)   [ 32, 32, 98, 97, 97,100, 99, 98, 97, 32, 32, 97, 99, 98, 97,101,100, 99, 98, 97, 32, 32]
 Ż     - prepend a zero                 [  0, 32, 32, 98, 97, 97,100, 99, 98, 97, 32, 32, 97, 99, 98, 97,101,100, 99, 98, 97, 32, 32]
  I    - incremental differences            [ 32,  0, 66, -1,  0,  3, -1, -1, -1,-65,  0, 65,  2, -1, -1,  4, -1, -1, -1, -1,-65,  0]
   ‘   - increment (vectorises)             [ 33,  1, 67,  0,  1,  4,  0,  0,  0,-64,  1, 66,  3,  0,  0,  5,  0,  0,  0,  0,-64,  1]
    T  - truthy indices                     [  1,  2,  3,      5,  6,             10, 11, 12, 13,         16,                 21, 22]
     ị - index into (S)                     [' ',' ','b',    'a','d',             ' ',' ','a','c',       'e',                ' ',' ']
                                       i.e. "  bad  ace  "

```

# Answer
> 9 votes
# , ~~22 13~~ 12 bytes

–9 bytes, thanks @Jonah!

```
#~1,1-{:I.}:

```

Try it online!

# Answer
> 8 votes
# Perl 5 (`-p`), ~~15~~, 16 bytes

```
s/[b-z]\K.*?a//g

```

Try it online!

or using options trick

# Perl 5 (`-nF/(?<![\x20a])(?!^)[b-z]*a/`), 7 bytes

```
print@F

```

Try it online!

# Answer
> 8 votes
# Python 3, 43 bytes

```
lambda s:[r for l,r in zip(' '+s,s)if'b'>l]

```

An unnamed function accepting a string which returns a list of characters.

**Try it online!**

---

To accept & return lists use `...zip([' ']+s...` instead (45)

To accept & return strings use `lambda s:''.join(r for l,r in zip(' '+s,s)if'b'>l)` (50)

# Answer
> 8 votes
# C (clang), ~~100~~ ~~98~~ ~~96~~ ~~95~~ ~~94~~ ~~92~~ ~~90~~ ~~88~~ ~~64~~ 46 bytes

Saved 24 bytes thanks to @Neil!!!
Saved 18 bytes thanks to @dingledooper (removed #include\<stdio.h\>)

```
f(char*c){while(*c)for(putchar(*c);*c++>97;);}

```

Try it online!

# Answer
> 7 votes
# 05AB1E, ~~9~~ 8 bytes

*-1 byte thanks to Kevin Cruijssen*

```
AηíR¬S.:

```

Try it online!

# Answer
> 7 votes
# Japt `-g`, ~~10~~ ~~9~~ 8 bytes

```
óÈ¥YcÄÃy

```

Try it

```
ó           split between those characters that return true when passed through...
 È    Ã     function :
  ¥         x equal to..
   YcÄ      character next to y
       y   transpose

Flag -g used to get 1st element

```

Saved 1 thanks to @Shaggy

# Answer
> 6 votes
# , ~~57~~ 56 bytes

-1 byte thanks to Giuseppe.

```
function(s)intToUtf8(c(v<-utf8ToInt(s),0)[c(0,v)%%32<2])

```

Try it online!

Could probably be made shorter with a regex, but this is more R-like. Converts to integers (vector `v`), then keeps only the first character and the characters which follow a space or an `a`. Since the corresponding codepoints are 32 and 97, we can check whether \\$v\_i\mod 32 \<2\\$ to get the relevant entries.

# Answer
> 5 votes
# JavaScript, ~~35~~ ~~32~~ 31 bytes

```
s=>s.replace(/ |.*?a/g,x=>x[0])

```

Try it online!

# Answer
> 5 votes
# Haskell, 59 bytes

```
f""=""
f(x:s)|x<'b'=x:(f s)|1>0=x:(f$tail$dropWhile(>'a')s)

```

Try it online!

No match for regex solutions, but I figured I'd try a recursive solution.

# Answer
> 5 votes
# Japt `-S`, ~~9~~ 8 bytes

```
¸®ò§ mÎ¬

```

Try it

```
¸®ò§ mÎ¬    :Implicit input of string
¸           :Split on spaces
 ®          :Map
  ò         :  Partition between characters where
   §        :  First is <= second
     m      :  Map
      Î     :    First character
       ¬    :  Join
            :Implicit output, joined with spaces

```

# Answer
> 5 votes
# Ruby, 28 bytes

```
->s{s.scan(/(?<=a|\b)./)*""}

```

Try it online!

This is a port of Arnauld's Javascript answer to Ruby.

# Answer
> 5 votes
# K (oK), 14 bytes

```
{x@&1,98>-1_x}

```

Try it online!

Inspired by FrownyFrog's/Jonah's J solution

# Answer
> 4 votes
# SNOBOL4 (CSNOBOL4), 106 bytes

```
	I =INPUT
S	I LEN(1) . X	:F(O)
	O =O X
	R =
	REVERSE(&LCASE) X REM . R
	I X R REM . I	:(S)
O	OUTPUT =O
END

```

Try it online!

```
	I =INPUT			;* Read input
S	I LEN(1) . X	:F(O)		;* extract the first letter or goto O if none exist
	O =O X				;* append that letter to the output
	R =				;* set R to the empty string
	REVERSE(&LCASE) X REM . R	;* Set R to the letters up to 'a', starting at X.
					;* R is empty string if X is space or 'a'
	I X R REM . I	:(S)		;* Set the REMainder of I after (X + R) to I; goto S
O	OUTPUT =O			;* output the string
END

```

# Answer
> 4 votes
# Jelly, 10 bytes

```
Ḳµ=Ṃk⁸ZḢ)K

```

Try it online!

A monadic link taking a Jelly string and returning a Jelly string. When run as a full program takes a string as its argument and implicitly prints the output string.

# Answer
> 4 votes
# C# (Visual C# Interactive Compiler), 33 bytes

```
x=>x.Where((_,l)=>l<1||x[l-1]<98)

```

Try it online!

# Answer
> 4 votes
# Red, 74 bytes

```
func[s][parse s[any[copy t thru"a"(prin#"`"+ length? t)opt[sp(prin sp)]]]]

```

Try it online!

# Answer
> 4 votes
# braingasm, ~~20~~ 18 bytes

```
,[.32-n[65-$[,]],]

```

It's been a while since I worked on braingasm. There seems to be a `compare` function, but I guess I didn't come around to implement a way to use the result. Well, this works:

```
,                    #  Read a byte from input
 [               ]   #  While the current byte is not zero
  .                  #    Print it
   32-               #    Decrease by 32
      n[       ]     #    If the result is non-zero (meaning it wasn't a space):
        65-          #      Subtract 65, leaving 'a' => 0, 'b' => 1, 'c' => 3, etc
           $[,]      #      That many times, read a byte from input
                ,    #    Read another byte

```

Doesn't handle newlines or anything other than lowercase letters and spaces in the input.

# Answer
> 4 votes
# Pip, 12 bytes

```
aR`\w*?a`_@0

```

Try it online!

### Explanation

```
a             The input, as a command-line argument
 R            Do a regex replacement:
  `\w*?a`      Match a non-greedy series of letters ending in a
         _@0   Replace with the first character of the match

```

# Answer
> 4 votes
# C (clang), ~~66~~ 48 bytes

edit: -18 bytes thanks to @dingledooper (removed #include)

```
P;D(char*T){*T?P>97||putchar(*T),P=*T++,D(T):0;}

```

Try it online!

```
int P;          // previous character
D(char*T)
{
    if (*T)     // check for end of string
    {
        if (!(P > 'a'))     // output current if previous was 'a' or ' '
            putchar(*T);
        P = *T;             // update previous
        D(T + 1);           // find next
    }
}

```

# Answer
> 4 votes
# x86 machine code, 12 bytes

(Runs in any mode, 16-bit, 32-bit, or 64-bit.)

This is based on @Noodle9's C algorithm, but with rearrangement into do{}while asm loop structure.

NASM listing: address, machine code (hex dump of the actual answer), source

```
 1                             decda:  ; (char *dst=RDI, const char *src=RSI)
 2 00000000 AC                     lodsb             ; AL = *src++
 3                             .loop:                ; do{
 4 00000001 AA                     stosb                 ; *dst++ = AL
 5                                .skip_until_a:         ; do{
 6 00000002 3C61                    cmp  al, 'a'
 7 00000004 AC                      lodsb
 8 00000005 77FB                    ja  .skip_until_a    ; }while((AL=*p++) > 'a')
 9 00000007 84C0                   test al,al
10 00000009 75F6                   jnz .loop         ; } while(AL != terminator)
11                             ;    stosb             ; append a terminating 0
12 0000000B C3                     ret
                       ; output end pointer returned in RDI

```

Try it online!

The input is an implicit-length (0-terminated) C string. The output is an explicit-length buffer. This function returns (in RDI) a pointer to one-past-the-end.

(The caller already knows where the output buf starts, so it has C++-like .begin and .end iterators). Making this function append a terminating `0` would cost 1 extra byte for another `stosb` after the loop, unless there's a way to rearrange things that I'm not seeing.

---

A sample caller that passes the output of `decda(argv[1])` to a `write` system call is included in the TIO link. You can `inc edx` in that caller to prove that the output didn't over-write beyond where it's supposed to.

I had been thinking of using `loop .loop` instead of `test al,al/jnz` but then the inner loop would need a `dec ecx` or something. (Without that, it loops until writing RCX *output* bytes, which only works if the caller knows the decrypted length, not the source length.) Worth considering for a 32-bit-only version that can use 1-byte `dec ecx`, unless that could reach `loop` or `loopne` with ECX\<=0 for valid inputs.

# Answer
> 3 votes
# C# (Visual C# Interactive Compiler), 69 bytes

Hard to beat Regex on this one

```
s=>System.Text.RegularExpressions.Regex.Replace(s,"([b-z]).*?a","$1")

```

Try it online!

**Returns an array of Matches (characters), 64 bytes**

```
s=>System.Text.RegularExpressions.Regex.Matches(s,"(?<![b-z]).")

```

Try it online!

# Answer
> 3 votes
# Ruby, 20 + 1 bytes

```
gsub /(?<!a|\b)./,''

```

1 extra byte for the `p` command line option:

```
$ ruby -p alphabet_cypher.rb <<< "hgfedcbaedcbalkjihgfedcbalkjihgfedcbaonmlkjihgfedcba wvutsrqponmlkjihgfedgfedcbarqponmlkjihgfedcbalkjihgfedcbadcba"
hello world

```

Try it online!

# Answer
> 3 votes
# Keg, `-ir`, `-lp`, ~~9~~ 7 bytes

```
(⑩(a-|_

```

Try it online!

*2 bytes saved thanks to @A̲̲ suggesting to use a for loop over a while loop*

## Answer History

```
{!|⑩(a-|_

```

Try it online!

```
{!|⑩(a-|_
{!|             #While there are still items on the stack:
   ⑩            #Print t.o.s without popping
    (a-|            #Subtract the code point of a from tos and repeat that many times:
        _           #Pop items off the stack

```

# Answer
> 3 votes
# Perl, 20 bytes

```
s:[^a]*a(.):a$_\1:g;

```

is **almost** there. Unfortunately, it will lose the first letter, and I don’t know how to get around that.

# Answer
> 3 votes
# Gema, 41 characters

```
\A\P?=?
 \P?=$0
?\P?=@cmps{?;?;$2;$2;}
?=

```

Unfortunately recognizers can not be combined. ☹

Sample run:

```
bash-5.0$ gema '\A\P?=$0; \P?=$0;?\P?=@cmps{$1;$2;$2;$2;};?=' <<< 'cbagfedcba cbacba'
cg cc

```

Try it online!

# Answer
> 3 votes
# C++, 464 bytes

I'm still a beginner so will be grateful for any advice.

```
#include <iostream>
#include <string>
using namespace std;

int main() {
  string input , output;
  getline(cin,input);
  output = input[0];

  for (int i = 0 ; i<input.size() ; i++) {
      if (input[i] == 'a')  {
          output += input[i+1];
      }  else if (input[i] == ' ') {
          output += input[i+1];
      }  else {
          continue;
      }

  }
  cout << output;
}

```

Try it online!

# Answer
> 2 votes
# Python 3.8 (pre-release), 50 bytes

```
import re
f=lambda s:re.sub('([b-z]).*?a',r'\1',s)

```

Regex stolen from Arnauld's JavaScript answer.

Try it online!

# Answer
> 2 votes
# Python 2, ~~87~~ ~~86~~ 84 bytes

```
lambda i:"".join(x[:2]if'a'>x else x[0]for x in i.replace('a','a#').split('#')[:-1])

```

Try it online!

Non-regex effort. Replaces `a` with `a` plus a disposable character then splits on the disposable character and outputs either the first or first two letters of each list element depending on whether the first is a space or not.

# Answer
> 2 votes
# Jelly, 20 bytes

```
O0;ṡ2_/>0ƊÐḟṪ€Ọ
ḲÇ€K

```

Try it online!

probably too long lol

# Explanation

```
O0;ṡ2_/>0ƊÐḟṪ€Ọ  This challenge, for one word
O                turn all the chars to their ASCII forms
 0;              prepend 0
   ṡ2            split into (overlapping) slices of length 2 (pairs)
          Ðḟ     filter: remove elements where
     _/          reducing over subtraction (which is equivalent to the first minus the second, in each pair)
       >0        is greater than 0 (if it's strictly descending)
            Ṫ€   take the second element of each pair
              Ọ  convert back to chars
ḲÇ€K             Compiled Program
Ḳ                split on spaces
 Ç€              apply the helper to each word
   K             join on spaces

```

# Answer
> 2 votes
# Charcoal, 8 bytes

```
Φθ‹§θ⊖κb

```

Try it online! Link is to verbose version of code. Explanation:

```
 θ          Input string
Φ           Filtered where
    θ       Input string
   §        Cyclically indexed by
      κ     Current index
     ⊖      Decremented
  ‹         Is less than
       b    Literal string `b`
            Implicitly print

```

# Answer
> 2 votes
# Wren, 67 bytes

Non-regex effort. I can't use regex because Wren doesn't support it..

```
Fn.new{|x|x.replace(" "," a").split("a")[0..-2].map{|i|(i+"a")[0]}}

```

## Explanation

```
Fn.new{|x|                                                        } // New anonymous function with parameter x.
          x.replace(" "," a")                                       // Append spaces with the a character in order to make them individual.
                             .split("a")                            // Split into a list with the character a.
                                        [0..-2]                     // We have a trailing unused a, so we need to remove it.
                                               .map{|i|          }  // Foreach this list:
                                                       (i+"a")      // Append this item with an a character(since we have used it for the splitting function)
                                                              [0]   // Return the first item in this list

```

Try it online!

# Answer
> 2 votes
# Java (JDK), 35 bytes

```
s->s.replaceAll("([b-z]).*?a","$1")

```

Try it online!

# Answer
> 2 votes
# , 18 bytes

```
({.;.2~'a'=])&>@;:

```

Try it online!

# Answer
> 2 votes
# Burlesque, ~~21~~ 19 bytes

```
{'`+]2CO:so)[-}ww\[

```

Try it online!

Non-regex solution, can save 2 bytes if permitted to return list of chars

```
{
 `'+] # Prefix each word with a backtick
 2CO  # Create n-grams of length 2 (abc => {ab bc})
 :so  # Filter for those which are in alphabetical order
 )[-  # Take the last letter of each n-gram
}ww   # For each word
\[    # Concatenate to string

```

# Answer
> 2 votes
# Husk, 8 bytes

```
wmom←ġ<w

```

Try it online!

# Answer
> 1 votes
# PHP, 67 bytes

According to the definition, we don't have to worry about invalid input. So I'm not actually checking if all the letters between the intended letter and "a" are properly following the reverse alphabet order, or even if there's the right number of letters. Feels a bit dirty, but it works for all valid input :)

```
for($x=0;$c=$argn[$x++];){$l=$l?$l:$c;if(ord($c)<98){echo$l;$l=0;}}

```

Try it online!

# Answer
> 1 votes
# Thunno 2 `B`, 6 bytes

```
0ƤṢ⁺Vi

```

Try it online!

Port of Jonathan Allan's Jelly answer.

#### Explanation

```
0ƤṢ⁺Vi  # Implicit input
0Ƥ      # Prepend a 0
  Ṣ     # Deltas
   ⁺    # Incremented
    V   # Truthy indices
     i  # Index in
        # Implicit output

```

---
Tags: code-golf, encryption
---