Write a quine which attempts to invert the case of as many ascii characters in the source code as possible. For example in javascript:

(x=function(y){return ('(x='+y+')(x)').toUpperCase();})(x)

• Standard quine rules apply.

• The score is given by number of bytes in the source code - number of case inversions. For example, the quine above has a score of 29.

• The program with the lowest score wins. If two programs have the same score then the shorter one wins.

• So non-letters count as 1 byte each no matter what, because they cannot be case-inverted? (Also, please use the sandbox next time.) – Bubbler Aug 19 '20 at 3:06
• Yes they do. The challenge is to try to make as much of the program change as possible. Sorry for not using the sandbox. It wasn't letting me post in there for some reason (maybe not enough rep?) – user82867 Aug 19 '20 at 3:09
• invert the case of as many ascii characters Does that mean that if a unicode character has its case inverted complement, we aren't expected to count that unicode character if we invert it in our output? – user96495 Aug 19 '20 at 9:40
• Hmm, so theoretically you could get a negative score if you found a language that encoded letters in less than a byte? – Jo King Aug 19 '20 at 11:53
• @user253751 Code golf is secondary winning criterion (so currently Gol><> wins over ><>). OP didn't have access to the sandbox when they wrote the challenge (see OP's first comment). – Bubbler Aug 20 '20 at 2:24

# ><>, score 479 - 479 = 0

lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllbfppllfepeeppppgglcepppbeppppppppppplfdppedpddpgglcdppbdpfcpecpggldcppllccpbcpplfbpebppldbppcbpggcbglefgpgbeglefgpgcbglefgpgggggedglefgpgccglefgpgfdglefgpgebglefgpgecglefgpggdcglefgpgceglefgpgeeglefgpgbcglefgpgfbglefgpgcdgfefgpbdgeefgpfegdefgpccgcefgpfdgbefgpdbgaefgpppddglefgpgbcglefgpgfcglefgpgdbglefgpgdcglefgpgecglefgpgddglefgpgdbglefgplffpbfgffgefgpcbgefgefgp


Try it online!

### How it works

Very few useful instructions in ><> are letters. However, we still have the l, pushing the length of the stack to the stack. As such, it's possible to (very verbosely) push arbitrary values to the stack. Thus, strings can be encoded in a similar fashion to brainfuck, using a to increase the length of the stack, and g or p to reduce it.

As per usual quine rules, g is not used to read the source code itself, instead maintaining registers at locations such asbb and bc and so on.

The string encoded is the prefix:

"r&:20&3-:&?.p48*-od0l2)?.;lllll"]"

Which after over 7,000 instructions outputs the original string in upper case.

• @JoKing Made a better encoding, where your version performs better. – SE - stop firing the good guys Aug 19 '20 at 12:58

# Gol><>, 77 75 - 75 = 0

urassssissezplzelssmzmzpssazmkqjmkrmbrrrrrtsuotlballsssssassmzpsssssbssmzpu


Try it online!

Based on Bubbler's answer, this goes even further by also putting the " at the start of the code to get a score of 0!

### Explanation

ur       Move over one on the stack tape and reverse the stack
assssissez      Push 10+16*4=74,-1+16*2=31,!(15)=0
p     And put the 74 (J) at position 0,31

lz            Push 0 if there is anything on the stack
e           Push 14 for later
lssmzmz    Push 2+16*2=34, !(-1)=0, !(-1)=0
p   Put the 34 (") at position 0,0

sss           Add 3*16 to the -1 from earlier
az         Push !(10)=0
mkq      Some no-ops

lballsssssassmzp  Put T at position 0,43
sssssbssmzpu      Put S at position 0,44
u                 Move one over on the stack again (effectively resetting the stack)

"                 Wrap, pushing everything to the stack
r                Reverse
.........       Put everything again
J      But this time don't jump, since the stack is not empty

mk           Copy the bottom of the stack (u)
rm         Push a -1 to the bottom of the stack
brrrrr   No-ops

T   t      Finally, loop over the stack,
Suo       Capitalising then outputting everything until we get to the -1

• The arithmetic reads almost like "ur ass plz"... – SE - stop firing the good guys Aug 19 '20 at 13:31
• @SE-stopfiringthegoodguys You may like my most recent golf – Jo King Aug 20 '20 at 5:01
• @SE-stopfiringthegoodguys New challenge idea: a quine (or something else) which is also a valid English sentence. – user253751 Aug 20 '20 at 9:24
• @user253751 Similar – Jo King Aug 20 '20 at 9:30
• Yes, like that, but stricter: grammar and punctuation must also be valid for English. (I'm not sure if that would even be solvable; I suspect it would in at least one language, but it might be very long) – user253751 Aug 20 '20 at 11:12

# Gol><>, score 34 - 33 = 1

"mrllssslssscsmzpdsmzprrrrrrtsuota


Try it online!

Outputs the following and exits by error, which is every char uppercased except the leading ".

"MRLLSSSLSSSCSMZPDSMZPRRRRRRTSUOTA


### How it works

The lines marked with * are the differences from the previous version.

"..."    Push every char except "
mrl      Push -1, reverse stack, push stack length (34 = ")
* lsss   Push stack length (35) and add 16 three times (83 = S)
* lsss   Push stack length (36) and add 16 three times (84 = T)
* csmzp  Push 13, add 16 (29), push -1, boolean negate (0), and
replace the command at (29,0) by T
* dsmzp  Push 14, add 16 (30), push -1, boolean negate (0), and
replace the command at (30,0) by S
* rrrrrr  Reverse the stack 6 times;
no-op to move the positions to overwrite
TSuot    Infinite uppercase-print loop; halt by error at -1
a        Not executed


# Gol><>, score 34 - 31 = 3

"mrlTSuotaaaaaaaaaaaaaaaaaaaaaaaaa


Try it online!

Outputs the following and exits by error.

"MRLTSUOTAAAAAAAAAAAAAAAAAAAAAAAAA


Every lowercase letters are uppercased, so the only chars that are not modified are "TS.

### How it works

"..."  Start string literal, push every char in the source code (except "),
wrap around and end string literal
mr     Push -1 and reverse the stack
(setup the chars for printing from top, and bury the trap at the bottom)
l      Push length of stack, which gives 34 == "
T...t  Infinite loop until it errors in the middle:
Su     Uppercase the char at the top (errors when trying to uppercase -1)
o      Pop and print as char
a...   Not reached


I suspect 2 or lower might be possible.

• You can probably get 0 through some careful putting and Jumping? – Jo King Aug 19 '20 at 8:11
• Like this! – Jo King Aug 19 '20 at 10:12
• @JoKing Wow, awesome. You definitely should post it as your own answer. – Bubbler Aug 19 '20 at 12:41

# V (vim), score 3

2i2I


Try it online!

4 bytes with 1 case inversion. Twice inserts (2i) the string 2I.

• You need an escape character at the end for this to work. What you have now just writes 2I. <esc> completes the i insert so the initial 2 can be used to double the insertion to 2I2I. – Noodle9 Aug 19 '20 at 9:40
• @Noodle9 In vim, yes, but this is V. V escapes implicitly at the end. – Dingus Aug 19 '20 at 9:42
• Oh, didn't realise there's a language V, will check it out - thanks! :-) – Noodle9 Aug 19 '20 at 9:45
• You could get a slightly better score if unicode characters were allowed to be lowercased: ñéÑ"qpxVUllvulllllvlu would have a score of 1 Try it online! – James Aug 19 '20 at 20:45
• @James Cool! If Unicode characters end up being allowed then you should definitely post your own answer. – Dingus Aug 20 '20 at 0:04

## 80186+ machine code (MS-DOS .COM format), 115-115=0

It was a bit tricky to do this, as I only had access to INC, DEC, PUSH, certain POP variations, POPA, IMUL, and certain conditional jumps. Fortunately, IMUL could do the heavy lifting for this challenge!

I encoded the actual code that does the printing in a series of values that get multiplied together. I compute those values (which get truncated to 16-bit values), store them on the stack which I moved to be just above the code, and then jump to the generated code to print the program's code in the opposite case.

Machine code:

hrXhCNhGUhnPhPwhYkhvLhKwaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaPQRjZTUVjfaiQVGARiQSCARiQPQARiQMJARiQJZARiQGuARiQDkARiQAWARpI


Assembler source:

IDEAL
P186

MODEL   TINY
CODESEG
ORG 100H

MAIN:
; Encoded code:
;   MOV SI,100H
;   MOV CX,73H
; PRINT:
;   LODSB
;   XOR AL,20H
;   INT 29H
;   NOP
;   LOOP PRINT
;   INT 20H
; Offset Bytes Multiplier
PUSH 5872H ; +41    BE 00 4157H
PUSH 4E43H ; +44    01 B9 416BH
PUSH 5547H ; +47    73 00 4175H
PUSH 506EH ; +4A    AC 34 415AH
PUSH 7750H ; +4D    20 CD 414AH
PUSH 6B59H ; +50    29 90 4151H
PUSH 4C76H ; +53    E2 F8 4143H
PUSH 774BH ; +56    CD 20 4147H

REPT 30
POPA ; Adjust stack to point to end of generated code
ENDM

PUSH AX
PUSH CX
PUSH DX
PUSH 5AH
PUSH SP
PUSH BP
PUSH SI
PUSH 66H
POPA ; Use POPA as POP DX and POP DI are not in [A-Za-z]
IMUL DX,[BX+DI+56H],4147H
PUSH DX
IMUL DX,[BX+DI+53H],4143H
PUSH DX
IMUL DX,[BX+DI+50H],4151H
PUSH DX
IMUL DX,[BX+DI+4DH],414AH
PUSH DX
IMUL DX,[BX+DI+4AH],415AH
PUSH DX
IMUL DX,[BX+DI+47H],4175H
PUSH DX
IMUL DX,[BX+DI+44H],416BH
PUSH DX
IMUL DX,[BX+DI+41H],4157H
PUSH DX

f=x=>f=${f}.replace(/(.)/g,y=>y<''?y.toLowerCase():y.toUpperCase())  Try it online! BTW: This is my first contribution and I'm a bit confused. I made sure to swap every possible character. The example only uppercases. If you don't need to actually swap cases, then one can get 11-0=11 with a simplified variant of an answer given above: f=x=>"f="+f  • Welcome to CGCC and congratulations on a great first answer! You're right that there's no requirement to change all (or any) of the cases, so your second 'simple quine' indeed beats the first one according to the scoring system. However, you can improve your score by at least swapping one character: f=x=>"F="+f scores 10 (since the first 'f' changes case)... – Dominic van Essen Aug 22 '20 at 13:33 • Woah, good point. Thanks! – Sean Schricker Aug 28 '20 at 19:55 # Keg, score 4 ④④  Try it online! 4 bytes with 0 case conversions. The standard quine without case conversion easily beats any Keg approaches that would have case conversion: by the time you've thrown case conversion techniques into the mix, you might as well have just written a standard quine with no fancy details. # Javascript, 27 - 13 = 14 f=x=>f=${f}.toUpperCase()


Try It Online!

# Python 2, Score 52 - 33 = 19

s='S=%r;PRINT S%%S.SWAPCASE()';print s%s.swapcase()



Try it online!

Case inverts every letter in the quine.

# R, score = 78 - 53 = 25

a="a=%s;cat(toupper(sprintf(a,squote(a))))";cat(toupper(sprintf(a,sQuote(a))))


Try it online!