| Bytes | Lang | Time | Link |
|---|---|---|---|
| 258 | AutoHotkey v2 | 241213T043500Z | Xuesong |
| 087 | Ruby p | 231215T152620Z | Dingus |
| 070 | Jelly | 231215T213045Z | Nick Ken |
| 142 | Python 3 | 231215T012108Z | Jakav |
| 109 | Google Sheets | 231215T182647Z | doubleun |
| 079 | JavaScript Node.js | 231215T165546Z | l4m2 |
| 098 | 05AB1E | 231215T091738Z | Kevin Cr |
AutoHotkey (v2), input from stdin, output to stdout, 265 258 bytes
Since it should be a cat program in some situations, I suppose that stdin and stdout are required. A shorter script not fulfill it is also provided below.
FileAppend Sort(i:=FileOpen('*','4').Read(),'D+')=='6CO2+6H2O+light`n'?'C6H12O6+6O2':i=='r`n'?Format(s:="FileAppend Sort(i:=FileOpen('*','4').Read(),'D+')=='6CO2+6H2O+light{:c}n'?'C6H12O6+6O2':i=='r{1:c}n'?Format(s:={:c}{}{2:c},96,34,s):i,'*'",96,34,s):i,'*'
AutoHotkey (v2), input from command line argument, output to MsgBox, 231 225 bytes
MsgBox Sort(i:=A_Args.Has(1)?A_Args[1]:'','D+')=='6CO2+6H2O+light'?'C6H12O6+6O2':i=='r'?Format(s:="MsgBox Sort(i:=A_Args.Has(1)?A_Args[1]:'','D+')=='6CO2+6H2O+light'?'C6H12O6+6O2':i=='r'?Format(s:={:c}{}{1:c},34,s):i",34,s):i
Ruby -p, 96 87 bytes
eval q="$_=%w[6CO2 6H2O light]-$_.split(?+,3)==[]?'C6H12O6+6O2':/^r$/?'eval q=%p'%q:$_"
The code is an extension of the Ruby quine
eval q="$><<'eval q=%p'%q"
The optional second argument to split is needed to avoid false positives on inputs like 6CO2+6H2O+light+. The check for an input of r uses a bare regex literal as a conditional, saving a byte over the more obvious $_==?r but provoking a warning from the interpreter.
Jelly, 77 70 bytes
“+“6CO2+6H2O+light r“C6H12O6+6O2“ḣ2œṣṢjɗḲi¥@ƭƒ³ị3ị,Ṿ;⁾0ị,⁾vƊƊƲ³ṭƊ”0ịvƊ
A full program link taking a string argument and printing a string argument. This currently feels a little verbose for a Jelly answer!
Python 3, 164 142 bytes
m=r'm=%r;a=input();print("C6H12O6+6O2"if{"6H2O","6CO2","light"}==set(a.split("+"))else"m=r\x27"+m+"\x27;exec(m%%m)"if a=="r"else a)';exec(m%m)
Here is a Python quine that meets all the requirements.
Google Sheets, 109 bytes
=ifs(""=A1,,"6CO2+6H2O+light"=join("+",sort(tocol(split(A1,"+")))),"C6H12O6+6O2","r"=A1,formulatext(F1),1,A1)
Put the input in cell A1 and the formula in cell F1.
Uses a cat $0 type quine, so non-competing.
JavaScript (Node.js), 79 bytes
f=x=>x.split`+`.sort().join`+`=='6CO2+6H2O+light'?'6O2+C6H12O6':x=='r'?'f='+f:x
Nothing special
05AB1E, 98 bytes
1"D34çýU'rQiXë“6CO26H2O“2ä'‡Žªœ'+ýIåi“C6H12O6+6O2"D34çýU'rQiXë“6CO26H2O“2ä'‡Žªœ'+ýIåi“C6H12O6+6O2
Outputs the C6H12O6+6O2 with two instead of one trailing newlines. Could be fixed in +2 bytes by adding “ after both C6H12O6+6O2 in the program.
Explanation:
1 # Push a 1
"..." # Push the program's source code
D # Duplicate it
34ç # Push 34, and convert it to a character with this codepoint: '"'
ý # Join the stack with '"'-delimiter
U # Pop and store this quine-string in variable `X`
'rQi '# If the (implicit) input is "r":
X # Push quine-string `X`
# (which is output implicitly with trailing newline)
ë # Else:
“6CO26H2O“ # Push string "6CO26H2O"
2ä # Push it into two equal-sized parts: ["6CO2","6H2O"]
'‡Ž '# Push dictionary word "light"
ª # Append it to the pair
œ # Get all six permutations of this triplet
'+ý '# Join each inner triplet with "+"-delimiter
Iåi # If the input is in this list:
“C6H12O6+6O2
# Push string "C6H12O6+6O2\n"
# (which is output implicitly with trailing newline)
# (implicit else)
# (implicitly output the implicit input with trailing newline)