Search code examples
language-agnosticcode-golfrosetta-stone

Code Golf: Spider webs


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).


Solution

  • Golfscript - 124 chars

    All whitespace is significant! If you accidently add a newline to the end there will be an extra _ at the end of the output

    ~):@,{@\:&-:0' ': *& '/':/+*'\\':~'_':
    0*.'|':|\/~ +&*n}%
    /+@*   ~
    +@*n ~+@*
    
    
    @/ +*n@,{):& *@&-:( ~+*/[
     ](!=&*.|\~/ +(*n}%
    

    Golfscript - 129 chars

    ~):@,{@\:&-:0' ': *&' /'*'\\':~'_':
    0*.'|'\'/'~ +&*n}%'_/'@*   '\_'@*n ~+@*
    
    
    @'/ '*n@,{):& *@&-:( ~+*'/'[
     ](!=&*.'|'\~'/ '(*n}%
    

    Golfscript - 133 chars

    ~):@,{@\:&-:0' ': *&' /'*'\\':~'_':
    0*.'|'\'/'~ +&*n}%'_/'@*3 *'\_'@*n' \\'@*3
    *@'/ '*n@,{):& *@&-:( ~+*'/''_ '1/(!=&*.'|'\~'/ '(*n}%