R – Code Golf: Spider webs

code-golflanguage-agnosticrosetta-stone

The challenge

The shortest code by character count to output a spider web with rings equal to user's input.

A spider web is started by reconstructing the center ring:

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

Then adding rings equal to the amount entered by the user. A ring is another level of a "spider circles" made from \ / | and _, and wraps the center circle.

Input is always guaranteed to be a single positive integer.

Test cases

Input
    1
Output
      \__|__/
      /\_|_/\
    _/_/   \_\_
     \ \___/ /
      \/_|_\/
      /  |  \

Input
    4
Output
         \_____|_____/
         /\____|____/\
        / /\___|___/\ \
       / / /\__|__/\ \ \
      / / / /\_|_/\ \ \ \
    _/_/_/_/_/   \_\_\_\_\_
     \ \ \ \ \___/ / / / / 
      \ \ \ \/_|_\/ / / /
       \ \ \/__|__\/ / /
        \ \/___|___\/ /
         \/____|____\/
         /     |     \

Input:
    7
Output:
            \________|________/
            /\_______|_______/\
           / /\______|______/\ \
          / / /\_____|_____/\ \ \
         / / / /\____|____/\ \ \ \
        / / / / /\___|___/\ \ \ \ \
       / / / / / /\__|__/\ \ \ \ \ \
      / / / / / / /\_|_/\ \ \ \ \ \ \
    _/_/_/_/_/_/_/_/   \_\_\_\_\_\_\_\_
     \ \ \ \ \ \ \ \___/ / / / / / / /
      \ \ \ \ \ \ \/_|_\/ / / / / / /
       \ \ \ \ \ \/__|__\/ / / / / /
        \ \ \ \ \/___|___\/ / / / /
         \ \ \ \/____|____\/ / / /
          \ \ \/_____|_____\/ / /
           \ \/______|______\/ /
            \/_______|_______\/
            /        |        \

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

Best Answer

Perl, 164 chars

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

First statement prints out the top half of the spider web. Second statement uses transliteration operations to create a reflection of the top half.

This next one weighs in closer to 314 chars (of productive code), but is more in the spirit of the season.

           ;               "
         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}

Hat tip to http://www.ascii-art.de/ascii/s/spider.txt

I constructed the spider shaped code by hand, but see the Acme::AsciiArtinator module on CPAN for help with automating (or at least semi-automating) the task.