Escreva um programa ou função que leva dois inteiros positivos, uma largura e uma altura, e desenha uma arte ASCII houndstooth padrão de grade com essas dimensões usando essa grade de 25 × 26 texto como a célula de base:
.......#.....#####.......
.......##.....#####......
.......###.....#####.....
.......####.....####.....
.......#####.....###.....
.......######.....##.....
.......#######.....#.....
.......########..........
####################.....
.####################....
..####################...
...####################..
....####################.
.....####################
#.....##############.####
##.....#############..###
###....#############...##
####...#############....#
#####..#############.....
.#####.#############.....
..##################.....
........#####............
.........#####...........
..........#####..........
...........#####.........
............#####........
Portanto, se a entrada fosse 2,1
a saída, seria:
.......#.....#####..............#.....#####.......
.......##.....#####.............##.....#####......
.......###.....#####............###.....#####.....
.......####.....####............####.....####.....
.......#####.....###............#####.....###.....
.......######.....##............######.....##.....
.......#######.....#............#######.....#.....
.......########.................########..........
####################.....####################.....
.####################.....####################....
..####################.....####################...
...####################.....####################..
....####################.....####################.
.....####################.....####################
#.....##############.#####.....##############.####
##.....#############..#####.....#############..###
###....#############...#####....#############...##
####...#############....#####...#############....#
#####..#############.....#####..#############.....
.#####.#############......#####.#############.....
..##################.......##################.....
........#####....................#####............
.........#####....................#####...........
..........#####....................#####..........
...........#####....................#####.........
............#####....................#####........
E se a entrada fosse 5,4
a saída seria:
.......#.....#####..............#.....#####..............#.....#####..............#.....#####..............#.....#####.......
.......##.....#####.............##.....#####.............##.....#####.............##.....#####.............##.....#####......
.......###.....#####............###.....#####............###.....#####............###.....#####............###.....#####.....
.......####.....####............####.....####............####.....####............####.....####............####.....####.....
.......#####.....###............#####.....###............#####.....###............#####.....###............#####.....###.....
.......######.....##............######.....##............######.....##............######.....##............######.....##.....
.......#######.....#............#######.....#............#######.....#............#######.....#............#######.....#.....
.......########.................########.................########.................########.................########..........
####################.....####################.....####################.....####################.....####################.....
.####################.....####################.....####################.....####################.....####################....
..####################.....####################.....####################.....####################.....####################...
...####################.....####################.....####################.....####################.....####################..
....####################.....####################.....####################.....####################.....####################.
.....####################.....####################.....####################.....####################.....####################
#.....##############.#####.....##############.#####.....##############.#####.....##############.#####.....##############.####
##.....#############..#####.....#############..#####.....#############..#####.....#############..#####.....#############..###
###....#############...#####....#############...#####....#############...#####....#############...#####....#############...##
####...#############....#####...#############....#####...#############....#####...#############....#####...#############....#
#####..#############.....#####..#############.....#####..#############.....#####..#############.....#####..#############.....
.#####.#############......#####.#############......#####.#############......#####.#############......#####.#############.....
..##################.......##################.......##################.......##################.......##################.....
........#####....................#####....................#####....................#####....................#####............
.........#####....................#####....................#####....................#####....................#####...........
..........#####....................#####....................#####....................#####....................#####..........
...........#####....................#####....................#####....................#####....................#####.........
............#####....................#####....................#####....................#####....................#####........
.......#.....#####..............#.....#####..............#.....#####..............#.....#####..............#.....#####.......
.......##.....#####.............##.....#####.............##.....#####.............##.....#####.............##.....#####......
.......###.....#####............###.....#####............###.....#####............###.....#####............###.....#####.....
.......####.....####............####.....####............####.....####............####.....####............####.....####.....
.......#####.....###............#####.....###............#####.....###............#####.....###............#####.....###.....
.......######.....##............######.....##............######.....##............######.....##............######.....##.....
.......#######.....#............#######.....#............#######.....#............#######.....#............#######.....#.....
.......########.................########.................########.................########.................########..........
####################.....####################.....####################.....####################.....####################.....
.####################.....####################.....####################.....####################.....####################....
..####################.....####################.....####################.....####################.....####################...
...####################.....####################.....####################.....####################.....####################..
....####################.....####################.....####################.....####################.....####################.
.....####################.....####################.....####################.....####################.....####################
#.....##############.#####.....##############.#####.....##############.#####.....##############.#####.....##############.####
##.....#############..#####.....#############..#####.....#############..#####.....#############..#####.....#############..###
###....#############...#####....#############...#####....#############...#####....#############...#####....#############...##
####...#############....#####...#############....#####...#############....#####...#############....#####...#############....#
#####..#############.....#####..#############.....#####..#############.....#####..#############.....#####..#############.....
.#####.#############......#####.#############......#####.#############......#####.#############......#####.#############.....
..##################.......##################.......##################.......##################.......##################.....
........#####....................#####....................#####....................#####....................#####............
.........#####....................#####....................#####....................#####....................#####...........
..........#####....................#####....................#####....................#####....................#####..........
...........#####....................#####....................#####....................#####....................#####.........
............#####....................#####....................#####....................#####....................#####........
.......#.....#####..............#.....#####..............#.....#####..............#.....#####..............#.....#####.......
.......##.....#####.............##.....#####.............##.....#####.............##.....#####.............##.....#####......
.......###.....#####............###.....#####............###.....#####............###.....#####............###.....#####.....
.......####.....####............####.....####............####.....####............####.....####............####.....####.....
.......#####.....###............#####.....###............#####.....###............#####.....###............#####.....###.....
.......######.....##............######.....##............######.....##............######.....##............######.....##.....
.......#######.....#............#######.....#............#######.....#............#######.....#............#######.....#.....
.......########.................########.................########.................########.................########..........
####################.....####################.....####################.....####################.....####################.....
.####################.....####################.....####################.....####################.....####################....
..####################.....####################.....####################.....####################.....####################...
...####################.....####################.....####################.....####################.....####################..
....####################.....####################.....####################.....####################.....####################.
.....####################.....####################.....####################.....####################.....####################
#.....##############.#####.....##############.#####.....##############.#####.....##############.#####.....##############.####
##.....#############..#####.....#############..#####.....#############..#####.....#############..#####.....#############..###
###....#############...#####....#############...#####....#############...#####....#############...#####....#############...##
####...#############....#####...#############....#####...#############....#####...#############....#####...#############....#
#####..#############.....#####..#############.....#####..#############.....#####..#############.....#####..#############.....
.#####.#############......#####.#############......#####.#############......#####.#############......#####.#############.....
..##################.......##################.......##################.......##################.......##################.....
........#####....................#####....................#####....................#####....................#####............
.........#####....................#####....................#####....................#####....................#####...........
..........#####....................#####....................#####....................#####....................#####..........
...........#####....................#####....................#####....................#####....................#####.........
............#####....................#####....................#####....................#####....................#####........
.......#.....#####..............#.....#####..............#.....#####..............#.....#####..............#.....#####.......
.......##.....#####.............##.....#####.............##.....#####.............##.....#####.............##.....#####......
.......###.....#####............###.....#####............###.....#####............###.....#####............###.....#####.....
.......####.....####............####.....####............####.....####............####.....####............####.....####.....
.......#####.....###............#####.....###............#####.....###............#####.....###............#####.....###.....
.......######.....##............######.....##............######.....##............######.....##............######.....##.....
.......#######.....#............#######.....#............#######.....#............#######.....#............#######.....#.....
.......########.................########.................########.................########.................########..........
####################.....####################.....####################.....####################.....####################.....
.####################.....####################.....####################.....####################.....####################....
..####################.....####################.....####################.....####################.....####################...
...####################.....####################.....####################.....####################.....####################..
....####################.....####################.....####################.....####################.....####################.
.....####################.....####################.....####################.....####################.....####################
#.....##############.#####.....##############.#####.....##############.#####.....##############.#####.....##############.####
##.....#############..#####.....#############..#####.....#############..#####.....#############..#####.....#############..###
###....#############...#####....#############...#####....#############...#####....#############...#####....#############...##
####...#############....#####...#############....#####...#############....#####...#############....#####...#############....#
#####..#############.....#####..#############.....#####..#############.....#####..#############.....#####..#############.....
.#####.#############......#####.#############......#####.#############......#####.#############......#####.#############.....
..##################.......##################.......##################.......##################.......##################.....
........#####....................#####....................#####....................#####....................#####............
.........#####....................#####....................#####....................#####....................#####...........
..........#####....................#####....................#####....................#####....................#####..........
...........#####....................#####....................#####....................#####....................#####.........
............#####....................#####....................#####....................#####....................#####........
- O argumento da largura deve vir primeiro. Qualquer formato de entrada razoável (por exemplo
w,h
,w h
,(w, h)
) é bom. - Imprima ou retorne o resultado com uma nova linha à direita opcional.
- Você pode usar dois caracteres ASCII imprimíveis distintos no lugar de
.
e#
. - Você pode converter a célula base vertical ou horizontalmente, como se tivesse condições de contorno periódicas . Portanto, o canto superior esquerdo da saída não será necessariamente um retângulo 7 × 8 de
.
's. ( Nova regra! )
O código mais curto em bytes vence.
Como bônus, gere uma imagem em que cada .
um é um pixel de uma cor e cada #
um é um pixel de outra cor.
code-golf
ascii-art
kolmogorov-complexity
Passatempos de Calvin
fonte
fonte
Respostas:
Pitão,
61605549 bytesExperimente online: Demonstração
editar 1: Combine as duas instruções que geram a banda e o triângulo (veja abaixo)
editar 2: não viu que podemos usar qualquer símbolo. Salvo 5 bytes editar
edit 3: @ Calvin'sHobbies permitido traduzir a imagem base. Como minha abordagem foi baseada nessa idéia, isso ajudou bastante. -6 bytes
E para o bônus do Cookie :
Isso tem apenas 2 bytes mais (51 bytes) e gera o arquivo
o.png
. Para a entrada5\n4
, gera a seguinte imagem:Explicação:
O padrão Houndstooth parece realmente bastante irregular. Mas se trouxemos as 7 colunas da esquerda para a direita e as 5 principais linhas para o botão, obtemos um padrão muito melhor:
Primeiro, produzo o bloco 13x13 superior esquerdo:
Existem 2 desigualdades simples, que descrevem as duas
#
áreas. A banda pode ser descrita pory + 1 <= x <= y + 5
e o triângulo pode ser descrito porx <= y - 5
. Eu combinei essas duas condições:Em seguida,
+Rm012
adiciona 12 zeros no final de cada linha para obter o bloco superior de 25x13.O bloco inferior de 25x13 agora é realmente simples:
Tudo o que resta agora é repetir o padrão e imprimi-lo
A diferença para o código de bônus do Cookie :
255
ao invés de1
mjk*Qd
usar*RQ
, já que não quero uma string.w
salva esse array 2D em arquivo (o converte em png implicitamente)fonte
CJam,
1067371 bytesImprime
1
e em0
vez de.
e#
. Experimente online no intérprete CJam .Como funciona
Bônus de cookie
imprime um BitMap portátil em vez de ASCII art.
Abaixo está a saída para entrada
24 13
, convertida em PNG:fonte
Befunge-93 ,
21201967 bytesAqui estão alguns exemplos de alta qualidade, com manipulação de exceção para depuração!
(Obviamente, isso ainda é muito jogável. Eu só queria obter uma resposta aqui por enquanto)
Então, isso é composto de partes diferentes.
Este é apenas o inicializador, pega os valores e os armazena
Esta seção redefine a contagem de linhas, para que possamos imprimir outras fotos (de largura) lado a lado.
94+2*
está calculando 26, o número de linhas. Além disso, se a altura for zero, o programa será encerrado.Isso fica com a largura da pilha, para que possamos saber quantas imprimir
Isso adiciona dois valores fictícios à pilha para dizer quando terminamos uma operação, bem como em que linha (n) estamos. Isso adiciona n valores à pilha
Esta é uma seção de controle que irá para a linha (26-n). Esta é a maneira mais fácil de descobrir como fazê-lo.
Obviamente, isso é lido e exibirá qualquer linha lida na pilha de trás para frente. Isso significa que, quando o abrirmos, ele será impresso corretamente.
Isso será impresso até que a pilha atinja um 0, que deixamos anteriormente.
Isso retira 1 do número da linha específica a ser impressa e verifica se é zero ou não. Se for diferente de zero, voltaremos ao quarto bloco de código.
Isso subtrai 1 da linha (n), imprime uma nova linha e volta ao bloco 3
Uma vez impressas todas as linhas, isso subtrai uma da altura inicial e volta para o bloco 2.
Todo o restante do código é fluxo de controle ou gerenciamento de pilha. Escrever esse mas mais do que eu pensava, mas estou satisfeito com a aparência. É muito mais jogável e provavelmente continuará sendo um projeto por mais um dia.
2120 -> 1967 : aparadas algumas linhas com muitos espaços desperdiçados
fonte
Perl, 243
(Um byte foi adicionado para que o
-n
comutador busque entrada de stdin.)Isso é bastante simples - basta converter uma matriz de 26 números hexadecimais em binários e imprimi-los o número necessário de vezes.
Exemplo:
Entrada:
Saída:
fonte
Rev 1, C,
118115 bytes9 bytes salvos devido a nova regra que permite a conversão da célula. 3 bytes salvos pelo uso de
w*=25
. O restante da postagem permanece inalterado.Rev 0, C, 127 bytes
Isso passa pelos caracteres, imprimindo-os um por um.
i%(25*w)||puts("")
insere uma nova linha no final de cada linha.Minha maneira de visualizar o design é semelhante à de Jakube, mas trago as 8 linhas superiores para a parte inferior e as 5 colunas da direita para a esquerda para obter a seguinte visualização. No programa, essa etapa é "revertida" por
+20
e+8
nas expressões para x e y.Além da "inversão de cores", pode parecer muito semelhante, mas há uma diferença importante: as listras diagonais coincidem. (observe que o design original não possui simetria diagonal, pois mede 25x26.)
A expressão
((y>x^y>x+5^x>y+4)^y/13)+34
produz o seguinte, onde os vários operadores de comparação produzem as listras,^y/13
produz o "deslocamento da cor" até a metade e+34
pega o número resultante0,1
e o eleva para o intervalo ASCII34,35
.O termo é
&y/13==x/13
avaliado como false = 0 nos quartos superior direito e inferior esquerdo, produzindo a parte quadrada do padrão, como mostrado anteriormente. Observe que, como o programa reduz a contagem, a origem x = y = 0 está no canto inferior direito. Isso é útil, pois o quadrado de#
13 caracteres de largura, enquanto o quadrado de"
apenas 12 caracteres de largura.fonte
Befunge -93, 968 bytes
Sim está certo! Uma resposta concorrente da Befunge!
Explicação amanhã, cama agora. No entanto, direi que faço coisas inteligentes movendo algumas setas de redirecionamento e também uso a propriedade wrap-around bastante. Teste-o neste intérprete online .
fonte