单词内的单词单词内的单词。。。


17

在这种大写字母的像素化字体中,所有字符均为5个单位宽和5个高。

 ███  ████   ███  ████  █████ █████  ████ █   █ █████     █ █   █ █     █   █
█   █ █   █ █   █ █   █ █     █     █     █   █   █       █ █  █  █     ██ ██
█████ ████  █     █   █ ████  ████  █  ██ █████   █       █ ███   █     █ █ █
█   █ █   █ █   █ █   █ █     █     █   █ █   █   █   █   █ █  █  █     █   █
█   █ ████   ███  ████  █████ █      ████ █   █ █████  ███  █   █ █████ █   █

█   █  ███  ████   ███  ████   ████ █████ █   █ █   █ █   █ █   █ █   █ █████
██  █ █   █ █   █ █   █ █   █ █       █   █   █ █   █ █   █  █ █   █ █     █ 
█ █ █ █   █ ████  █   █ ████   ███    █   █   █  █ █  █ █ █   █     █     █  
█  ██ █   █ █     █  ██ █  █      █   █   █   █  █ █  █ █ █  █ █    █    █   
█   █  ███  █      ████ █   █ ████    █    ███    █    █ █  █   █   █   █████

可以看出,字母之间和行之间也有1个单位的空间。因此,每个字母最多可占用6×6个单位的空间。

假设而不是使用完整的块字符),直接形成字母的形状,我们希望使用在相同的字体其他字母。这涉及将文本的尺寸增加6倍,以便由大写字母组成的字母可以用作较大文本中的大写字母替换。

如果那没有道理,希望这个例子会。这是A使用像素化字体由B组成的:

      ████  ████  ████       
      █   █ █   █ █   █      
      ████  ████  ████       
      █   █ █   █ █   █      
      ████  ████  ████       
                             
████                    ████ 
█   █                   █   █
████                    ████ 
█   █                   █   █
████                    ████ 
                             
████  ████  ████  ████  ████ 
█   █ █   █ █   █ █   █ █   █
████  ████  ████  ████  ████ 
█   █ █   █ █   █ █   █ █   █
████  ████  ████  ████  ████ 
                             
████                    ████ 
█   █                   █   █
████                    ████ 
█   █                   █   █
████                    ████ 
                             
████                    ████ 
█   █                   █   █
████                    ████ 
█   █                   █   █
████                    ████ 

B由完整的块组成,而A由B组成。请注意,B在水平和垂直方向之间仍然有一个单位。

我们可以通过使用单词而不是字母来扩展这个想法。这是由“火”制成的“水”:

█████                   █████             ████  █████ █████             █████ ████  █████ █████ █████       ████  █████ █████ █████ ████        █████ █████ █████ ████       
█                         █               █   █ █     █                   █   █   █ █     █       █         █   █ █     █       █   █   █       █     █       █   █   █      
████                      █               ████  ████  ████                █   ████  ████  ████    █         ████  ████  ████    █   ████        ████  ████    █   ████       
█                         █               █  █  █     █                   █   █  █  █     █       █         █  █  █     █       █   █  █        █     █       █   █  █       
█                       █████             █   █ █████ █                 █████ █   █ █████ █     █████       █   █ █████ █     █████ █   █       █████ █     █████ █   █      
                                                                                                                                                                             
█████                   █████       ████                    █████                   █████                   █████                               ████                    █████
█                         █         █   █                   █                       █                         █                                 █   █                   █    
████                      █         ████                    ████                    ████                      █                                 ████                    ████ 
█                         █         █  █                    █                       █                         █                                 █  █                    █    
█                       █████       █   █                   █████                   █                       █████                               █   █                   █████
                                                                                                                                                                             
█████       █████       ████        █████ █████ █████ ████  █████                   █████                   █████ ████  █████ █████             █████ ████  █████ █████      
█             █         █   █       █     █       █   █   █ █                       █                         █   █   █ █     █                   █   █   █ █     █          
████          █         ████        ████  ████    █   ████  ████                    ████                      █   ████  ████  ████                █   ████  ████  ████       
█             █         █  █        █     █       █   █  █  █                       █                         █   █  █  █     █                   █   █  █  █     █          
█           █████       █   █       █████ █     █████ █   █ █████                   █                       █████ █   █ █████ █                 █████ █   █ █████ █          
                                                                                                                                                                             
█████       █████       ████        █████                   █████                   █████                   ████                                █████             █████      
█             █         █   █       █                       █                         █                     █   █                               █                 █          
████          █         ████        ████                    ████                      █                     ████                                ████              ████       
█             █         █  █        █                       █                         █                     █  █                                █                 █          
█           █████       █   █       █████                   █                       █████                   █   █                               █████             █          
                                                                                                                                                                             
      █████       █████             ████                    █████                   █████                   █████ ████  █████ █████ █████       ████                    █████
      █             █               █   █                   █                       █                         █   █   █ █     █       █         █   █                   █    
      ████          █               ████                    ████                    ████                      █   ████  ████  ████    █         ████                    ████ 
      █             █               █  █                    █                       █                         █   █  █  █     █       █         █  █                    █    
      █           █████             █   █                   █████                   █                       █████ █   █ █████ █     █████       █   █                   █████

请注意,“ FIRE”如何在每一行上重复出现,并且始终保持顺序,无论字母之间有多少间距。由于“ WATER”字母的形状是很早的,所以最右边的三个“ FIRE”实例被早期切除。

通过使用由单词构成的这些单词,使由单词构成的单词构成的单词,或者甚至由单词构成的单词构成的单词构成的单词,可以进一步扩展该思想。理论上没有限制。

另一个示例会将这篇文章的字符数限制在30k以内,但是通过运行这个漂亮的Stack Snippet,您可以看到“单词由单词组成的单词”的含义。只需将参数保留为默认值,然后按“ Go!”。您应该看到由单词“ CAT”和单词“ MOUSE”组成的单词“ DOG”。

在文本框中键入任何用空格分隔的仅包含大写字母的单词列表,将产生由第二个单词组成的第一个单词,第二个单词由第三个单词组成,第四个单词由...组成,等等。

警告:输入超过4个或什至3个单词将产生大量文本,并且花费很长时间。它可能会使您的浏览器/计算机/汽车崩溃。

挑战

这项挑战的目标是反映出堆栈片段在最少字符数下的功能。

您必须编写一个程序,该程序使用空格分隔的仅包含大写字母的单词字符串,并使用上面给出的像素化字体输出第一个单词“由...构成”,第二个“由...构成”,依此类推。

程序中不需要支持“纯ASCII”复选框和代码片段的字体大小功能。从单词列表到单词组成的单词的转换镜像是重点,也是唯一的要求。

细节

  • 输入应来自stdin,命令行,或者您可以编写一个带有字符串的函数。

  • 您可能会假设输入始终有效,即由大写字母组成的一串字词,由一个空格完全分隔,没有前导或尾随空格。

  • 输出应转到标准输出(或类似的替代品)或具有您选择的名称的文件。

  • 输出应完全由空格全角和换行符组成。

    • 空/满空格字符应或者是空间和全块(分别地),或周期和X( .X分别地)。
  • 输出不应包含仅包含空格字符的任何前导列,尽管允许在任何行上尾随空格字符的任意组合。

    • 因此,这是允许的:

      X...X.XXXXX..
      X...X.X
      X.X.X.XXXX....
      X.X.X.X..
      .X.X..XXXXX..
      
    • 但这不是:

      .X...X.XXXXX..
      .X...X.X
      .X.X.X.XXXX....
      .X.X.X.X..
      ..X.X..XXXXX..
      
  • 不应有仅包含空格字符的开头或结尾行。可选地允许单条尾随换行符。

这是字体的更加字符串友好的版本:

.XXX.
X...X
XXXXX
X...X
X...X

XXXX.
X...X
XXXX.
X...X
XXXX.

.XXX.
X...X
X....
X...X
.XXX.

XXXX.
X...X
X...X
X...X
XXXX.

XXXXX
X....
XXXX.
X....
XXXXX

XXXXX
X....
XXXX.
X....
X....

.XXXX
X....
X..XX
X...X
.XXXX

X...X
X...X
XXXXX
X...X
X...X

XXXXX
..X..
..X..
..X..
XXXXX

....X
....X
....X
X...X
.XXX.

X...X
X..X.
XXX..
X..X.
X...X

X....
X....
X....
X....
XXXXX

X...X
XX.XX
X.X.X
X...X
X...X

X...X
XX..X
X.X.X
X..XX
X...X

.XXX.
X...X
X...X
X...X
.XXX.

XXXX.
X...X
XXXX.
X....
X....

.XXX.
X...X
X...X
X..XX
.XXXX

XXXX.
X...X
XXXX.
X..X.
X...X

.XXXX
X....
.XXX.
....X
XXXX.

XXXXX
..X..
..X..
..X..
..X..

X...X
X...X
X...X
X...X
.XXX.

X...X
X...X
.X.X.
.X.X.
..X..

X...X
X...X
X.X.X
X.X.X
.X.X.

X...X
.X.X.
..X..
.X.X.
X...X

X...X
.X.X.
..X..
..X..
..X..

XXXXX
...X.
..X..
.X...
XXXXX

计分

这是因此以字节为单位的最短提交会获胜。完整块()的任何实例都可以计为1个字节,而不是3个字节,因此使用提交X没有优势。


5
您可以运行以下JavaScript代码段(例如,通过输入javascript:URL栏并将其粘贴),以使此处的ASCII文字容易阅读$('#question pre').css('line-height',1)。结果:i.stack.imgur.com/XmB8C.png
门把手

1
或包含答案$('#question pre, .answer pre').css('line-height',1)
马丁·恩德

我知道开这个玩笑为时已晚,但我无法抗拒:i.imgur.com/vAZi1Zt.png
algorithmhark

我怎么错过了这个挑战?
魔术章鱼缸

Answers:


8

CJam,171个165 162 161字节

qS/_0=,0a*a\{{W:I;{'[{RI):I=}?i65-"c¿»ÐòO*4Õ]%ÐÎ<à IX]{-ïèq=ô}s×o)½2~û³'é¨1ÃlØeúN!Ö3~4ÜË|ÕÇäaepý®"255b2b5/5/=}%z1af*}%R,1a*a*}fR2a*"█ 
"f=

我将其视为1个字节。其余所有字符都在ASCII范围内,因此也将它们视为1个字节。

您可以使用此pastebin获取确切的代码

输入的示例输出:

FIRST HELLO WORLD

在此处输入图片说明

怎么运行的

首先

"c¿»ÐòO*4Õ]%ÐÎ<à IX]{-ïèq=ô}s×o)½2~û³'é¨1ÃlØeúN!Ö3~4ÜË|ÕÇäaepý®"255b2b5/5/

只是用于(位置)和(位置)的27个字符(A-Z和空格)中每个字符的模式。解码后,将得到一个27个元素的2D数组的5列和5列的2D数组,分别代表27个字符,并分别代表这27个字符。让我们将此数组称为。0X1.X.L

现在剩下的代码:

qS/                      "Read the input and split it on space to get array Q";
   _0=                   "Get a copy of the first element of the above array";
      ,0a*               "Create an array filled with 0 with length of the first element";
          a\             "Wrap that array in another array and swap to get Q on top";
{  ...  }fR              "This is a for each loop on the array Q with R having the";
                         "current element value in each loop";
 {...}%                  "In the first iteration, the 0 array we created will be the";
                         "only thing on stack, in subsequent iterations, the result";
                         "of previous iteration will be on stack";
  W:I;                   "Initialize variable I with -1";
      {...}%             "Run this block on each element of the current array";
{'[{RI):I=}?i65-L=}%     "This is the above code block. In each iteration, we figure";
                         "out what character needs to be be put at the current index";
                         "Then we get the pattern of 0 and 1 for that character";
 '[{      }?             "Stack contains either 0 or 1. If it is 1, we want to leave";
                         "that index blank, so we put pattern of '[ which is 5X5 spaces";
    RI_:I=               "When we do not want a blank character, we get the next"
                         "character from R to fill the non empty space";
            i65-         "Convert A-Z  to 0-27 notation";
                L=       "Get the corresponding pattern from the pattern array L";
z1af*                    "After the above iterations, for each line of the previous";
                         "iteration's output, we get a vertical 2D array for next";
                         "iteration. We transpose it and join each character in";
                         "this line using a space";
      R,1a*a*            "After getting all lines from current iteration, we join them";
                         "with one full line of space characters";

 2a*                     "After all iterations, we have the 0 1 based 2D array for the";
                         "final output ASCII with each row representing a line. We join";
                         "these lines with 2, to get a 0 1 2 based array";
     "█                  "A brick, a space and a newline. Mapping 1 to 1 with 0 1 2";
"                        "based array";
 f=                      "For each of the 0 1 2 based array element, convert them to";
                         "one of the brick, space and new line character";

在这里在线尝试


9

Python 3,437字节

from numpy import*
s=input().split()
d=fromstring('NONO__^Q_PQAQQNONO^_QQQQQ_QQQQAAAQDPIA[SQQQQADQQQJJH_OAQOOY_DPGAUUQOQONDQJUDDDQQQQAAQQDQIAQYQAYIPDQJUJDBQONO_A^Q_NQ_QQNA^QODNDJQD_',byte)[:,None]>>arange(5)&1
b=0
x=1
y=len(s[0])
n=[[1]*y]
for w in s:
 g=n;b+=x;x*=6;n=zeros((x,x*y),int);i=-6
 for q in g:
  o=j=0;i+=6
  for p in q:n[i:i+5,j:j+5]|=d[ord(w[o%len(w)])-65::26]*p;o+=p;j+=6
for r in n[:-b]:print(''.join(' █'[x] for x in r))

字符形状以ASCII编码。每个ASCII字节对应一个字符的一行,其位代表单位块。这不是一个非常有效的方案,但是很容易将每个字符解压缩为NumPy位掩码。

我们从1s的2d数组开始。它的第一个单词中的每个字符都有一列,并且只有一行。然后,对于每个单词,我们创建一个新的0数组,该数组比以前的数组高6倍,宽6倍。如果先前数组的值为1,则新数组的相应6x6部分将填充适当字符的位掩码。

这是一个示例(字体非常小):

在此处输入图片说明


5

CJam,181个 174 170字节

所有这些非ASCII字符仍在扩展的ASCII范围内,因此它们都可以在单个字节中进行编码。(除了,但根据挑战规范对其进行了特殊处理。)因此,我将每个字符都计为一个字节。

"Á  :½A%õ­Íú£à˪ë8!Õ*j4¶fVËa¡ùÔ¯{+ÛyéâõKn#@?
9Ôia)(Ñç;~LÒª"257b2bYYb" █"er5/5/:L;lS/_0=,'█*a\{f{W:T;\{' ={S5*a5*}{T):T1$='A-L=}?\}%W<zSf*}Sa*}/N*

Stack Exchange可能已经破坏了一些不可打印的字符,因此您可能必须从该pastebin复制代码。

在这里测试。

通过STDIN将输入作为空格分隔的单词列表。第一个词是最大的比例。例如:

HOLISM REDUCTIONISM

产量

████                    █████             ████  █   █  ███              █████                               █████  ███  █   █ █████  ████             █   █ ████  █████ ████        █   █                    ███ 
█   █                   █                 █   █ █   █ █   █               █                                   █   █   █ ██  █   █   █                 ██ ██ █   █ █     █   █       █   █                   █   █
████                    ████              █   █ █   █ █                   █                                   █   █   █ █ █ █   █    ███              █ █ █ ████  ████  █   █       █   █                   █    
█  █                    █                 █   █ █   █ █   █               █                                   █   █   █ █  ██   █       █             █   █ █  █  █     █   █       █   █                   █   █
█   █                   █████             ████   ███   ███                █                                 █████  ███  █   █ █████ ████              █   █ █   █ █████ ████         ███                     ███ 

████                    █████       ████                    █   █        ███                                            █████                   █████                                ███  █   █       █████  ████
█   █                   █           █   █                   █   █       █   █                                             █                       █                                 █   █ ██  █         █   █    
████                    ████        █   █                   █   █       █                                                 █                       █                                 █   █ █ █ █         █    ███ 
█  █                    █           █   █                   █   █       █   █                                             █                       █                                 █   █ █  ██         █       █
█   █                   █████       ████                     ███         ███                                              █                     █████                                ███  █   █       █████ ████ 

████  █████ ████  █   █  ███        █████                   █████        ███                                            █   █                         █████  ████ █   █             ████        █████       ████ 
█   █ █     █   █ █   █ █   █         █                       █         █   █                                           ██  █                           █   █     ██ ██             █   █       █           █   █
████  ████  █   █ █   █ █             █                       █         █   █                                           █ █ █                           █    ███  █ █ █             ████        ████        █   █
█  █  █     █   █ █   █ █   █         █                       █         █   █                                           █  ██                           █       █ █   █             █  █        █           █   █
█   █ █████ ████   ███   ███          █                     █████        ███                                            █   █                         █████ ████  █   █             █   █       █████       ████ 

████                    █████       ████                    █   █        ███                                            █████                                           █████        ███                    █   █
█   █                   █           █   █                   █   █       █   █                                             █                                               █         █   █                   ██  █
████                    ████        █   █                   █   █       █                                                 █                                               █         █   █                   █ █ █
█  █                    █           █   █                   █   █       █   █                                             █                                               █         █   █                   █  ██
█   █                   █████       ████                     ███         ███                                              █                                             █████        ███                    █   █

████                    █████             ████  █   █  ███              █████ █████  ███  █   █ █████        ████ █   █ ████  █████ ████        █   █  ███  █████ █████              ███                    █   █
█   █                   █                 █   █ █   █ █   █               █     █   █   █ ██  █   █         █     ██ ██ █   █ █     █   █       █   █ █   █   █     █               █   █                   ██  █
████                    ████              █   █ █   █ █                   █     █   █   █ █ █ █   █          ███  █ █ █ ████  ████  █   █       █   █ █       █     █               █   █                   █ █ █
█  █                    █                 █   █ █   █ █   █               █     █   █   █ █  ██   █             █ █   █ █  █  █     █   █       █   █ █   █   █     █               █   █                   █  ██
█   █                   █████             ████   ███   ███                █   █████  ███  █   █ █████       ████  █   █ █   █ █████ ████         ███   ███    █   █████              ███                    █   █

说明

首先,我们在以下位置存储字母形状的查找表L

"Á  :½A%õ­Íú£à˪ë8!Õ*j4¶fVËa¡ùÔ¯{+ÛyéâõKn#@?
9Ôia)(Ñç;~LÒª"257b2bYYb" █"er5/5/:L;

第一个字符串只是一个压缩数字。我们将代码点视为以257为基数的数字,然后将结果数字转换为二进制。YYb是2以2为底,因此给出[1 0]。我们使用元素替换" █"来将数字转换成空格并阻止字符。最后,我们将字符串分成5个字符的行,再分成5行的块。结果存储在L堆栈中并从堆栈中丢弃。

现在,一般的想法是从最大比例字长的一行开始。然后,对于每个单词,我们将遍历现有网格,并以较小的比例将所有块扩展为相应的字符(同时插入空行和空列以进行分隔)。这是输入准备:

lS/_0=,'█*a\
lS/          "Read input, split on spaces.";
   _0=       "Duplicate and get first word.";
      ,'█*   "Get length repeat █ that many times.";
          a  "Wrap in array, to make the grid two-dimensional.";
           \ "Swap with word list.";

首先让我们看一下剩余程序的最外层结构。{...}/为每个单词运行下一个块,并扩展每个块字符。

{f{...}Sa*}/N*
{         }/   "Process each word in the input.";
 f{...}        "Map this block onto each line of the grid, passing in the current word as well.";
       Sa*     "Since each original line will be turned into 5 lines, the grid is still grouped
                into blocks of 5 lines. We join them together with empty lines as required.";
            N* "Join all lines together with newlines.";

最后,让我们看一下如何扩展单行:

W:T;\{' ={S5*a5*}{T):T1$='A-L=}?\}%
W:T;                                "Store -1 in T.";
    \                               "Swap word with line.";
     {                           }% "Map this block onto each character.";
      ' =                           "Check if the character is a space.";
         {      }{            }?    "If it is, run the first block, otherwise the second.";
          S5*                       "Create a string of five spaces.";
             a5*                    "Create an array of five such strings.";
                  T):T              "Push T, increment, store in T.";
                      1$=           "Copy the word and access the T'th character, cyclically.";
                         'A-        "Subtract A from the letter.";
                            L=      "Use the result to get the character shape from L.";
                                \   "Swap resulting block with word.";

"At this point each character is replaced with a 5x5 array of new characters.
 So we actually have a 3D array right now. Since we used a map operation, the
 current word will also be at the end of the array, which we need to get rid off.";

W<zSf*
W<     "Discard last array element - the current word.";
  z    "Zip or transpose the top two levels of the array.";
   Sf* "Join each line together with spaces.";

结果将自动打印在程序末尾。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.