language-agnostic - Code Golf : Spider webs

标签 language-agnostic code-golf rosetta-stone

挑战

按字符数计算的最短代码,用于输出蜘蛛网,其环等于用户的输入。

蜘蛛网是通过重建中心环开始的:

   \_|_/
  _/   \_
   \___/
   / | \

然后添加与用户输入的金额相等的环。环是“蜘蛛圈”的另一个层次,由 \ / | 制成。和_ ,并包裹中心圆。

输入始终保证为单个正整数。

测试用例

Input
    1
Output
      \__|__/
      /\_|_/\
    _/_/   \_\_
     \ \___/ /
      \/_|_\/
      /  |  \
<小时/>
Input
    4
Output
         \_____|_____/
         /\____|____/\
        / /\___|___/\ \
       / / /\__|__/\ \ \
      / / / /\_|_/\ \ \ \
    _/_/_/_/_/   \_\_\_\_\_
     \ \ \ \ \___/ / / / / 
      \ \ \ \/_|_\/ / / /
       \ \ \/__|__\/ / /
        \ \/___|___\/ /
         \/____|____\/
         /     |     \
<小时/>
Input:
    7
Output:
            \________|________/
            /\_______|_______/\
           / /\______|______/\ \
          / / /\_____|_____/\ \ \
         / / / /\____|____/\ \ \ \
        / / / / /\___|___/\ \ \ \ \
       / / / / / /\__|__/\ \ \ \ \ \
      / / / / / / /\_|_/\ \ \ \ \ \ \
    _/_/_/_/_/_/_/_/   \_\_\_\_\_\_\_\_
     \ \ \ \ \ \ \ \___/ / / / / / / /
      \ \ \ \ \ \ \/_|_\/ / / / / / /
       \ \ \ \ \ \/__|__\/ / / / / /
        \ \ \ \ \/___|___\/ / / / /
         \ \ \ \/____|____\/ / / /
          \ \ \/_____|_____\/ / /
           \ \/______|______\/ /
            \/_______|_______\/
            /        |        \

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

最佳答案

Perl,164 个字符

<罢工>195 <罢工>184 <罢工>171 <罢工>167 164

print@o=((map{$z=_ x($x=1+$N-$_);$"x$x." /"x$_."\\$z|$z/".'\ 'x$_.$/}0..($N=<>)),
"_/"x++$N."   ".'\_'x$N.$/);
y'/\\'\/',@o||y#_# #,$t++||y#_ # _#,print while$_=pop@o

第一个语句打印出蜘蛛网的上半部分。第二条语句使用音译操作来创建上半部分的反射。

下一篇的重量接近 314 个字符(有效代码),但更符合本季的精神。

           ;               "
         Tr                 Ic
        K|                   |t
       Re                     aT
       ",                     "H
       av                     e
        A:                    -
     )H AL                   LO  W
    ee  N"                   ,"  En
   jo    y_                 Yo    ur
   _      C&&             y";     ##
   &I      ();           $N=      1+
   <>;      $,=  $/;@O  =((     map 
    $" x($   X=$N-$_). ${   f}x$_.$
        B.${U}x$X.$P.${U}x$X.$
    F.${b}x$_,0..$N-1),${g}x$N.(${S}
   x3).${c}x$N);sub I{($F,$B,$U, $P)
  =qw         (/ \\ _ |);;         ${
 S}=        " ";$f=$S.$F;$g=$       U.
 $F     ;$b=$B.$S;$c=$B.${U};}@{    P}=
@{     O};  while($_=pop@{P}  ){     @{
 P}    ||   y:_: :;$spooky++  ||    0|
  0    ||   y@_ @ _@;y:/:8:;   ;    ;
   ;   ;;   y:\\:/:;y:8:\\:;  @O   =
    (  @O    ,$_);}print@O;   q{
       Do     !Discuss:Rel    ig
       io       n,Politi      cs
        ,&                   &T
        heG                 rea
          tP              ump
            ki           n}

http://www.ascii-art.de/ascii/s/spider.txt致敬

我手工构建了蜘蛛形状的代码,但看到Acme::AsciiArtinator CPAN 上的模块可帮助自动化(或至少半自动化)任务。

关于language-agnostic - Code Golf : Spider webs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1646887/

相关文章:

language-agnostic - 交互式统计网站的库

language-agnostic - Code Golf - 横幅生成

javascript - 注入(inject)尽可能少的字符的 javascript 文件?

code-golf - Code Golf : Quickly Build List of Keywords from Text, 包括实例数

algorithm - 这个 "Lexographic order generation algorithm"是如何工作的?

algorithm - 将整数表示为一系列乘数

regex - Code Golf : Regex parser

language-agnostic - Code Golf : Diamond Pattern

language-agnostic - 在质心视口(viewport)中移动对象

language-agnostic - Code Golf : Triforce