Caso invierte tu quine

Aug 19 2020

Escriba un quine que intente invertir el caso de tantos caracteres ascii en el código fuente como sea posible. Por ejemplo en javascript:

(x=function(y){return ('(x='+y+')(x)').toUpperCase();})(x)
  • Se aplican las reglas estándar de quine.

  • La puntuación viene dada por el número de bytes en el código fuente - número de inversiones de casos . Por ejemplo, el quine anterior tiene una puntuación de 29.

  • El programa con la puntuación más baja gana. Si dos programas tienen la misma puntuación, gana el más corto.

Respuestas

26 SE-stopfiringthegoodguys Aug 19 2020 at 17:51

> <> , puntuación 479 - 479 = 0

lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllbfppllfepeeppppgglcepppbeppppppppppplfdppedpddpgglcdppbdpfcpecpggldcppllccpbcpplfbpebppldbppcbpggcbglefgpgbeglefgpgcbglefgpgggggedglefgpgccglefgpgfdglefgpgebglefgpgecglefgpggdcglefgpgceglefgpgeeglefgpgbcglefgpgfbglefgpgcdgfefgpbdgeefgpfegdefgpccgcefgpfdgbefgpdbgaefgpppddglefgpgbcglefgpgfcglefgpgdbglefgpgdcglefgpgecglefgpgddglefgpgdbglefgplffpbfgffgefgpcbgefgefgp

¡Pruébelo en línea!

Cómo funciona

Muy pocas instrucciones útiles en> <> son letras. Sin embargo, todavía tenemos el l, empujando la longitud de la pila hacia la pila. Como tal, es posible (muy prolijamente) empujar valores arbitrarios a la pila. Por lo tanto, las cadenas se pueden codificar de manera similar a Brainfuck, utilizando apara aumentar la longitud de la pila go ppara reducirla.

Según las reglas habituales quine, gno se utiliza para leer el código fuente en sí, el mantenimiento de registros vez en lugares como bby bcy así sucesivamente.

La cadena codificada es el prefijo:

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

Que después de más de 7.000 instrucciones genera la cadena original en mayúsculas.

10 JoKing Aug 19 2020 at 20:14

Gol> <> , 77 75 - 75 = 0

urassssissezplzelssmzmzpssazmkqjmkrmbrrrrrtsuotlballsssssassmzpsssssbssmzpu

¡Pruébelo en línea!

Basado en la respuesta de Bubbler , esto va aún más lejos al poner también el "al comienzo del código para obtener una puntuación de 0!

Explicación

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
        J     And jump to 0,47 if the stack was initially empty

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
8 Bubbler Aug 19 2020 at 11:28

Gol> <> , puntuación 34 - 33 = 1

"mrllssslssscsmzpdsmzprrrrrrtsuota

¡Pruébelo en línea!

Muestra lo siguiente y sale por error, que son todos los caracteres en mayúsculas excepto el inicial ".

"MRLLSSSLSSSCSMZPDSMZPRRRRRRTSUOTA

Cómo funciona

Las líneas marcadas con *son las diferencias con la versión anterior.

"..."    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> <> , puntuación 34 - 31 = 3

"mrlTSuotaaaaaaaaaaaaaaaaaaaaaaaaa

¡Pruébelo en línea!

Muestra lo siguiente y sale por error.

"MRLTSUOTAAAAAAAAAAAAAAAAAAAAAAAAA

Todas las letras minúsculas están en mayúsculas, por lo que los únicos caracteres que no se modifican son "TS.

Cómo funciona

"..."  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

Sospecho que 2 o menos podrían ser posibles.

6 Dingus Aug 19 2020 at 11:25

V (vim) , puntuación 3

2i2I

¡Pruébelo en línea!

4 bytes con 1 inversión de caso. Inserta dos veces ( 2i) la cadena 2I.

6 ErikF Aug 21 2020 at 04:58

80186+ código de máquina (formato MS-DOS .COM), 115-115 = 0

Fue un poco difícil de hacer esto, ya que solo tenía acceso a INC, DEC, PUSH, ciertas POPvariaciones, POPA, IMULy ciertos saltos condicionales. Afortunadamente, ¡ IMULpodría hacer el trabajo pesado para este desafío!

Codifiqué el código real que hace la impresión en una serie de valores que se multiplican. Calculo esos valores (que se truncan a valores de 16 bits), los guardo en la pila que moví para que esté justo encima del código y luego salto al código generado para imprimir el código del programa en el caso contrario.

Codigo de maquina:

hrXhCNhGUhnPhPwhYkhvLhKwaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaPQRjZTUVjfaiQVGARiQSCARiQPQARiQMJARiQJZARiQGuARiQDkARiQAWARpI

Fuente del ensamblador:

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
    JO $+4BH ; Jump to start of generated code

END MAIN
ENDS
5 the-cobalt Aug 20 2020 at 06:58

05AB1E, 16 - 6 = 10

0"D34çýu"D34çýu

(nueva línea final)

Explicación

0"D34çýu"D34çýu # full code
0"D34çý "D34çý  # standard 05AB1E quine
       u      u # uppercase string in stack
                # implicit print

No es el mejor golf, pero es mi primer golf, así que ten piedad, por favor.

Pruébelo en línea!


05AB1E (heredado), 16 - 8 = 8

0"D34çýš"D34çýš

(nueva línea final)

Explicación

0"D34çýu"D34çýu # full code
0"D34çý "D34çý  # standard 05AB1E quine
       š      š # switch case builtin
                # implicit print

Gracias a Kevin Cruijssen por -2 puntuación. No funciona con la 05AB1E actual porque la función de la caja del interruptor es lo que hace que el recuento de bytes sea mayor

Pruébelo en línea!

5 Dingus Aug 19 2020 at 10:08

Rubí , puntuación 24 20 16 12

eval S="print'EVAL s=';p S.swapcase"

¡Pruébelo en línea!

37 bytes con 25 inversiones de casos. El caso de cada letra se cambia en la salida.

3 DomHastings Aug 19 2020 at 13:51

Perl 5 , 37 bytes, 20 casos intercambiados, puntuación 17

¡Gracias a @Dominic van Essen por -1!

eval($a=q{print uc"eval(\$a=q{$a})"})

¡Pruébelo en línea!

3 SeanSchricker Aug 22 2020 at 06:45

JavaScript (Node.js) , 70 - 38 = 32

f=x=>`f=${f}`.replace(/(.)/g,y=>y<'`'?y.toLowerCase():y.toUpperCase())

¡Pruébelo en línea!

Por cierto: esta es mi primera contribución y estoy un poco confundido. Me aseguré de intercambiar todos los personajes posibles. El ejemplo solo en mayúsculas. Si no necesita realmente intercambiar casos, entonces uno puede obtener 11-0 = 11 con una variante simplificada de una respuesta dada anteriormente:

f=x=>"f="+f
2 Lyxal Aug 19 2020 at 11:33

Barril , puntuación 4

`④`④

¡Pruébelo en línea!

4 bytes con 0 conversiones de casos.

El quine estándar sin conversión de casos supera fácilmente a cualquier enfoque de Keg que tenga conversión de casos: para cuando haya incluido las técnicas de conversión de casos en la mezcla, también podría haber escrito un quine estándar sin detalles sofisticados.

2 Shaggy Aug 20 2020 at 00:22

Javascript, 27 - 13 = 14

f=x=>`f=${f}`.toUpperCase()

Pruébelo en línea!

1 ovs Aug 19 2020 at 13:23

Python 2 , puntuación 52 - 33 = 19

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

¡Pruébelo en línea!

Case invierte cada letra del quine.

1 DominicvanEssen Aug 19 2020 at 17:17

R , puntuación = 78 - 53 = 25

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

¡Pruébelo en línea!