Gere programas que imprimem n vezes o seu comprimento

16

Dado um número inteiro não negativo n, sua solução deve gerar um programa no idioma escolhido cuja saída tenha o nnúmero de bytes que o programa gerado.

Regras

  • Você deve especificar o idioma e a codificação dos programas que sua solução gera e não pode escolher idiomas ou codificações diferentes para entradas diferentes da sua solução. O idioma do seu programa de saída pode ou não ser o mesmo da sua solução.
  • Seu envio precisa lidar com números inteiros no intervalo do seu idioma, mas não abuse dessa regra.

Este é o pelo que vence o envio mais curto em bytes.

Exemplo

Suponha que nseja 4. Minha solução então gera f_8um programa que, na minha linguagem (imaginária), gera j3 1s+/2]!mz. A saída do programa possui comprimento 3 e sua saída possui comprimento 3 * 4 = 12, portanto, a solução está correta para a entrada 4.

Suponha que nseja 1 e meu programa saia ffffpfpffp(10 bytes). O programa ffffpfpffpno meu idioma escolhido teria que produzir uma saída de 10 * 1 = 10 bytes.

HyperNeutrino
fonte
No momento, isso é bastante subespecificado. Você poderia fornecer alguns exemplos?
DJMcMayhem
3
Eu acho que eu sei o que é suposto fazer, mas cada vez que leio o spec, eu me torno menos certo. produzir algum texto que tenha n vezes mais bytes do que o programa produzido parece implicar que temos que produzir um texto e um programa. O conjunto de caracteres e o idioma devem ser consistentes para todos os números inteiros. A qual "conjunto de caracteres" isso se refere?
Dennis
Deixa pra lá, eu realmente entendi errado, e o mesmo aconteceu com todas, exceto uma das respostas.
Dennis
1
@ Dennis Não ajuda que o título pareça contradizer o corpo. Talvez programa uma saída que as saídas n vezes o seu comprimento seria um título melhor, se eu entendi o desafio corretamente (não tenho certeza que eu faço)
Sísifo
1
Podemos tomar ncomo uma corda?
Shaggy

Respostas:

7

JavaScript (ES6), 38 bytes

n=>`(x="${n}")=>(x+1/7+1e9).repeat(x)`

Demo

Arnauld
fonte
3

brainfuck , 348 bytes

--[>+<++++++]>>--[>+<++++++]>++[-<+>]----[>+<----]>---[-<+>]----[>+<----]>-[-<+>]-[>+<---]>++++++[-<+>]-[>+<---]>++++++++[-<+>]--[>+<++++++]>+++[-<+>]<[<],[->.<]>>>>>.<<<.>>.<<<.>>>.<<<.>>>.<<<.>>...>>>.<<....<<.>>>.<<..<<.>>>..<<.......>>>>.<<<..<<.>.....>>>.<<.>>.>>.<<<<<.>>>>.<<.<<.>>.>.<<<.>>.<<<.>>...<<.>>>..>>.<<.>.<<<.>.<<.>>>.>>.<<<..>>>.

Experimente online! Ou veja a versão Ungolfed (ou seja, com o que eu tinha que trabalhar)


aviso Legal

Passei mais tempo fazendo isso do que pensava ser humanamente possível. Gostaria de agradecer à minha namorada por me permitir dispensá-la para trabalhar nisso; assim como meu salvador .

Como isso funciona?

Nenhuma pista.

Como isso funciona?

Todas as saídas têm um trecho de código à direita que é o mesmo:

[->+>+>+<<<]>>>>-[<<+>>-------]<<+-----[<[.-]>->[->+<<<+>>]>[-<+>]<<]

Vamos dividi-lo em três partes chamadas a,b,c

a : [->+>+>+<<<]>>>>               THE DUPLICATOR
b : -[<<+>>-------]<<+-----        THE ADJUSTER
c : [<[.-]>->[->+<<<+>>]>[-<+>]<<] THE PRINTER

A entrada ié simplesmente pregada na frente em unário:

iabc

(por exemplo, se a entrada foi 10, então i = '++++++++++')

O duplicador - divide a entrada em dois números idênticos m, n, equivalentes à entrada

O Ajustador - Ajusta de nforma que seja igual à duração do programa

A impressora - imprime m*ncaracteres ASCII


Observe que a entrada no exemplo é a newline, que como um valor ASCII de 10, portanto a entrada é 10. Se você quiser testar outros números pequenos, substitua o ,número +que desejar.

Graviton
fonte
2

Queijo Cheddar , 10 9 bytes

(*)&" "*9

Uma poliglota protônica estranha> _ <

Downgoat
fonte
+1 para a poliglota Proton com o Cheddar para mostrar a inspiração: D
HyperNeutrino 18/17
2

Haskell , 55 bytes

f n=(++)<*>show$"main=putStr$[1.."++show n++"*2]>>'#':"

Experimente online!Exemplo de uso: f 1gera o seguinte programa de 54 bytes:

main=putStr$[1..1*2]>>'#':"main=putStr$[1..1*2]>>'#':"

Experimente online! que produz a seguinte saída de 54 bytes:

#main=putStr$[1..1*2]>>'#':#main=putStr$[1..1*2]>>'#':
Laikoni
fonte
1

Python 3 -> HQ9 +, 11 bytes

'Q'.__mul__

Tinha que ser feito

Experimente online!

michi7x7
fonte
Onde posso testar o QG?
Titus
1
Bem, Qapenas imprime seu próprio código fonte. Você pode testar isso aqui: hq9plus.alwaysdata.net . Isso nunca deveria ser uma entrada sério
michi7x7
Isso não funciona. Se eu inserir 1, então você Qproduz, o que, por sua vez, gera Q. Qtem comprimento 1, mas seu código tem comprimento 11.
NoOneIsHere
@NoOneIsHere 'cuja saída possui n vezes mais bytes que o programa gerado.' (não o programa enviado)
michi7x7 19/09/17
1
@NoOneIsHere isso não faz: almnet.de/esolang/hq9plus.php (A especificação linguagem só afirma "Imprime todo o texto do arquivo de código fonte")
michi7x7
1

Java 8, 175 174 bytes

interface M{static void main(String[]a){System.out.printf("interface M{static void main(String[]a){int i=(88+%s)*%s;for(;i-->0;System.out.print(0));}}",a[0].length(),a[0]);}}

Exemplos:

n=1saídas :

interface M{static void main(String[]a){int i=(88+1)*1;for(;i-->0;System.out.print(0));}}

(comprimento = 89) que gera 89 zeros :

00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

n=10saídas :

interface M{static void main(String[]a){int i=(88+2)*10;for(;i-->0;System.out.print(0));}}

(comprimento = 90) que gera 900 zeros :

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

n=100saídas :

interface M{static void main(String[]a){int i=(88+3)*100;for(;i-->0;System.out.print(0));}}

(comprimento = 91) que gera 9100 zeros :

0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Explicação:

interface M{                                // Class:
  static void main(String[]a){              //  Mandatory main method
    System.out.printf("interface M{static void main(String[]a){
                                            //   Print a new program with:
      int i=(88+%s)*%s;                     //    Integer containing (88*A)+B
      for(;i-->0;System.out.print(0));}}",  //    And print that many zeroes
        a[0].length(),                      //     Where A is the length of the number
                                            //     (0-9 = 1; 10-99 = 2; 100-999 = 3; etc.)
        a[0]);}}                            //     and B is the number itself
Kevin Cruijssen
fonte
0

RProgN 2 , 7 5 bytes

«•.* 

Com um espaço à direita

Explicado

«•.* 
«    # Yield a function from the remaining string.
 •.  # Append a space and stringify, which builds the original program (Because stringifying a function removes noops, which spaces are)
   * # Repeat the implicit input times.

Experimente online!

ATaco
fonte
0

CJam, 8 13 bytes

q_,S\" 8+*S*"

Experimente Online

O programa gerado gera espaços, então é meio difícil dizer.

geokavel
fonte
Eu acho que essa é a única resposta que interpreta a parte sobre a saída de um programa que gera um texto corretamente, mas a proporção está desativada se a entrada tiver mais de um dígito.
Dennis
Ah, sim, duh ,,.
geokavel
0

Ly , 29 bytes

"\"9>("&onu")[<&s&ol>1-]<;"&o

Experimente online! (não funciona atualmente devido a um erro de pré-processamento) Tudo bem!

LyricLy
fonte
0

Python → TECO, 20 bytes

A resposta está em Python enquanto o código gerado está em TECO. O Python é uma função que retorna VV12345\VVrepetidas n vezes. Veja aqui uma explicação do TECO.

'VV12345\VV'.__mul__
feersum
fonte
0

PHP, 47 + 1 bytes

<?="<?=str_pad(_,",strlen($argn)+18,"*$argn);";

imprime um sublinhado seguido por espaços.
Corra como tubo com -F; execute o programa gerado com -fou -F.

Isso falharia na entrada com mais de 64 dígitos, o
que é muito maior que PHP_INT_MAX(no momento).

No entanto, falha na entrada maior que PHP_INT_MAX-18 ... ainda se qualifica?

Titus
fonte
@ HyperNeutrino: Isso falhará para entradas maiores que PHP_INT_MAX-18. Isso desqualifica?
Titus
Nah, eu vou dizer que está bem :)
HyperNeutrino
0

PHP → Python 2, 40 + 1 bytes

print "A"*<?=13+strlen($argn),"*",$argn;

imprime um programa Python que imprime As repetidos . Corra como cano com -F.

Titus
fonte
0

Lote → Carvão, 22 bytes

Não tenho certeza de qual codificação devo usar, pois esses são bytes. Aqui estão os bytes interpretados como Windows-1252:

@set/p=Á%1ñªÉñ«Ìñ¹<nul

Os mesmos bytes do PC-850:

@set/p=┴%1±¬╔±½╠±╣<nul

Os mesmos bytes na página de código do Charcoal:

@set/p=A%1θ×Iθ⁺Lθ⁹<nul

O programa Charcoal resultante tem Plus(Length(Cast(n)), 9)bytes:

A       Assign
 %1      (String representation of n)
   θ      To variable q
        Implicitly print a number of `-`s equal to:
×        Product of:
 Iθ       Cast of q to integer
 ⁺        Sum of:
  Lθ       Length of q
  ⁹        Integer constant 9
Neil
fonte
0

JavaScript (ES8), 43 41 39 bytes

n=>`f=_=>"".padEnd(${n}*(88+f).length)`

Teste-o

A saída da função gerada é uma sequência de espaços que são substituídos por *s neste Snippet.

g=
n=>`f=_=>"".padEnd(${n}*(88+f).length)`

o.innerText=(h=n=>`Function: ${x=g(n)}\nLength:   ${x.length}\nOutput:   "${x=eval(x)().replace(/./g,"*")}"\nLength:   `+x.length)(i.value=10);oninput=_=>o.innerText=h(+i.value)
<input id=i type=number><pre id=o>

Shaggy
fonte
0

R , 46 bytes

function(n)sprintf("cat(rep('a',%d*23),'')",n)

Experimente online!

Função anônima que retorna a string

cat(rep('a',n*23),'')

Que imprime a( aseguido de um espaço) 23 nvezes. Eu precisava do ''porque, caso contrário cat, não imprimiria o último caractere de espaço.

Giuseppe
fonte
0

C, 94 bytes

main(int c,char**a){if(c>1){c=atoi(a[1]);if(c>0&&c<0xFFFFFF){c*=94;while(c--)printf("r");}}}

isso seria 94 bytes, incluindo o último \ n que o padrão C diz que deve ser gravado. retornar como caracteres 'r' como o (comprimento do programa) * (argumento do programa) se o argumento do programa não existir ou for <= 0 ou for> 0xFFFFF

C:\>nameProg.exe 1
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
RosLuP
fonte
0

MATLAB (63 bytes)

a=@(n)['repmat(''a'',1,',num2str(n*(15+numel(num2str(n)))),')']

Por exemplo:

>> a(5)

ans =

repmat('a',1,80)

e:

>> repmat('a',1,80)

ans =

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
PieCot
fonte