高尔夫代码:玩立方体

问题描述:

按字符数计算的最短代码,它将根据用户输入输出打砖块塔系列.

The shortest code by character count, that will output playing bricks tower series according to user input.

输入将是一系列数字(正,负和零),这些数字代表当前多维数据集塔遵循其索引的高度.高度0表示没有塔并且被隔开.

The input will be a series of numbers (positive, negative and zero) that represents the height of the current cube tower following their index. A height of 0 means no tower and is spaced.

一个立方体塔由堆叠的立方体组成.如果当前索引上的输入数字为正,则多维数据集会上升;如果输入数字为负,则多维数据集会下降.使用以下4行绘制一个多维数据集:

A cube tower is composed of stacked cubes. If the input number on the current index is positive, the cubes go up, if the input number is negative, the cubes go down. A single cube is drawn using the 4 following lines:


   __
 /__ /|
|   | |
|___|/

多维数据集是3D的-这意味着当两个塔彼此相邻放置时,它们会彼此隐藏,从而产生假的视角.

Cubes are 3D - this means they hide each other when two towers are placed next to each other, generating fake perspective.

可以假定所有输入均有效且没有错误-每个数字在一行上用空格分隔,并且至少有一个数字.

All input can be assumed to be valid and without errors - Each number is separated with a white space on a single line, with at least one number.


Input:
    2 -3 -2 1 2 -1
Output:
       __              __
     /__ /|          /__ /|
    |   | |        _|   | |
    |___|/|      /__|___|/|
    |   | |__  _|   |   | |__
    |___|/__ /__|___|___|/__ /|
        |   |   | |     |   | |
        |___|___|/|     |___|/
        |   |   | |
        |___|___|/
        |   | |
        |___|/



Input:
    1 2 3 4 -2 4 3 2 1
Output:
                   __      __ 
                 /__ /|  /__ /|
               _|   | | |   | |__
             /__|___|/| |___|/__ /|
           _|   |   | | |   |   | |__
         /__|___|___|/| |___|___|/__ /|
       _|   |   |   | | |   |   |   | |__
     /__|___|___|___|/| |___|___|___|/__ /|
    |   |   |   |   | |_|   |   |   |   | |
    |___|___|___|___|/__|___|___|___|___|/
                    |   | |
                    |___|/|
                    |   | |
                    |___|/



Input:
    1 3 3 7 0 -2 -2
Output:
                   __
                 /__ /|
                |   | |
                |___|/| 
                |   | | 
                |___|/| 
                |   | | 
                |___|/| 
           __  _|   | | 
         /__ /__|___|/| 
        |   |   |   | | 
        |___|___|___|/| 
       _|   |   |   | | 
     /__|___|___|___|/| 
    |   |   |   |   | |    __  __
    |___|___|___|___|/   /__ /__ /|
                        |   |   | |
                        |___|___|/|
                        |   |   | |
                        |___|___|/

代码计数包括输入/​​输出(即完整程序).

Code count includes input/output (i.e full program).

Perl 157个字符

该条目的灵感来自gnibbler的Ruby条目,其中包括有关在代码中嵌入多维数据集的部分.也感谢Kinopiko为我学习了substr的4 arg版本.

Perl 157 characters

This entry was inspired by gnibbler's Ruby entry, including the part about embedding the cube in the code. Also thanks to Kinopiko for schooling me on the 4 arg version of substr.

@O=($/.$"x99)x99;map{for$n(0..$_-1,$_..-1){map{substr$O[50-2*$n+$_],$W+4/$_,6,
(_,"__"
,"/__ /|",
"|   | |",
"|___|/")[$_]}1..4}$W+=4}@ARGV;print grep/\S/,@O

说明:

第1行:选择多维数据集的去向
第2-5行:将多维数据集放到多维数据集所在的位置,打印

Line 1: Choose where cubes go
Lines 2-5: Put cubes where cubes go, print