Skip to main content
Notice removed Improve details by Martin Ender
Bounty Ended with xnor's answer chosen by Martin Ender
edited tags
Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975
Notice added Improve details by Martin Ender
Bounty Started worth 450 reputation by Martin Ender
Tweeted twitter.com/#!/StackCodeGolf/status/601429531115814914
added 136 characters in body
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

Neither input nor output must contain any trailing spaces, nor more leading spaces than necessary to align the hexagon shape. Both input and output may optionally contain a single trailing newline (this choice does not have to be the same for input and output).

Neither input nor output must contain any trailing spaces, nor more leading spaces than necessary to align the hexagon shape.

Neither input nor output must contain any trailing spaces, nor more leading spaces than necessary to align the hexagon shape. Both input and output may optionally contain a single trailing newline (this choice does not have to be the same for input and output).

Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

Scale up a Diamond Tiling

Any regular hexagon can be tiled with diamonds, for instance like so:

   ______
  /_/_/\_\
 /_/\_\/\_\
/\_\/_/\/_/\
\/_/\_\/_/\/
 \_\/_/\_\/
  \_\_\/_/

We'll consider the above a tiling of size 1 (since the diamonds' sides are made of one / or \ each). The same tiling of size 2 would look like:

      ____________ 
     /   /   /\   \  
    /___/___/  \___\ 
   /   /\   \  /\   \  
  /___/  \___\/  \___\ 
 /\   \  /   /\  /   /\  
/  \___\/___/  \/___/  \ 
\  /   /\   \  /   /\  /
 \/___/  \___\/___/  \/ 
  \   \  /   /\   \  /
   \___\/___/  \___\/ 
    \   \   \  /   /
     \___\___\/___/ 

Your task is to receive such an ASCII art tiling (of size 1) as input, along with a positive integer N (in decimal or unary), specifying the size of the desired output. You should then output a scaled-up version of the same tiling.

Note that the hexagon could be any size and as small as 1x1x1 (containing three diamonds).

Neither input nor output must contain any trailing spaces, nor more leading spaces than necessary to align the hexagon shape.

You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter.

This is code golf, so the shortest answer (in bytes) in wins.

Example Tilings

Here are a handful of input tilings you can use to test your submission.

 __
/_/\
\_\/

  ____
 /_/\_\
/\_\/_/\
\/_/\_\/
 \_\/_/

   ______
  /_/_/\_\
 /_/\_\/\_\
/\_\/_/\/_/\
\/_/\_\/_/\/
 \_\/_/\_\/
  \_\_\/_/

    ________
   /_/\_\_\_\
  /\_\/\_\_\_\
 /\/_/\/_/_/\_\
/\/\_\/_/_/\/\_\ 
\/\/_/\_\_\/\/_/
 \/\_\/_/\_\/_/
  \/\_\_\/_/_/
   \/_/_/_/_/

The following snippet contains the corresponding outputs for inputs N = 1 through N = 6.

 __
/_/\
\_\/

  ____
 /   /\
/___/  \
\   \  /
 \___\/

   ______
  /     /\
 /     /  \
/_____/    \
\     \    /
 \     \  /
  \_____\/

    ________
   /       /\
  /       /  \
 /       /    \
/_______/      \
\       \      /
 \       \    /
  \       \  /
   \_______\/

     __________
    /         /\
   /         /  \
  /         /    \
 /         /      \
/_________/        \
\         \        /
 \         \      /
  \         \    /
   \         \  /
    \_________\/

      ____________
     /           /\
    /           /  \
   /           /    \
  /           /      \
 /           /        \
/___________/          \
\           \          /
 \           \        /
  \           \      /
   \           \    /
    \           \  /
     \___________\/

  ____
 /_/\_\
/\_\/_/\
\/_/\_\/
 \_\/_/

    ________
   /   /\   \
  /___/  \___\
 /\   \  /   /\
/  \___\/___/  \
\  /   /\   \  /
 \/___/  \___\/
  \   \  /   /
   \___\/___/

      ____________
     /     /\     \
    /     /  \     \
   /_____/    \_____\
  /\     \    /     /\
 /  \     \  /     /  \
/    \_____\/_____/    \
\    /     /\     \    /
 \  /     /  \     \  /
  \/_____/    \_____\/
   \     \    /     /
    \     \  /     /
     \_____\/_____/

        ________________
       /       /\       \
      /       /  \       \
     /       /    \       \
    /_______/      \_______\
   /\       \      /       /\
  /  \       \    /       /  \
 /    \       \  /       /    \
/      \_______\/_______/      \
\      /       /\       \      /
 \    /       /  \       \    /
  \  /       /    \       \  /
   \/_______/      \_______\/
    \       \      /       /
     \       \    /       /
      \       \  /       /
       \_______\/_______/

          ____________________
         /         /\         \
        /         /  \         \
       /         /    \         \
      /         /      \         \
     /_________/        \_________\
    /\         \        /         /\
   /  \         \      /         /  \
  /    \         \    /         /    \
 /      \         \  /         /      \
/        \_________\/_________/        \
\        /         /\         \        /
 \      /         /  \         \      /
  \    /         /    \         \    /
   \  /         /      \         \  /
    \/_________/        \_________\/
     \         \        /         /
      \         \      /         /
       \         \    /         /
        \         \  /         /
         \_________\/_________/

            ________________________
           /           /\           \
          /           /  \           \
         /           /    \           \
        /           /      \           \
       /           /        \           \
      /___________/          \___________\
     /\           \          /           /\
    /  \           \        /           /  \
   /    \           \      /           /    \
  /      \           \    /           /      \
 /        \           \  /           /        \
/          \___________\/___________/          \
\          /           /\           \          /
 \        /           /  \           \        /
  \      /           /    \           \      /
   \    /           /      \           \    /
    \  /           /        \           \  /
     \/___________/          \___________\/
      \           \          /           /
       \           \        /           /
        \           \      /           /
         \           \    /           /
          \           \  /           /
           \___________\/___________/

   ______
  /_/_/\_\
 /_/\_\/\_\
/\_\/_/\/_/\
\/_/\_\/_/\/
 \_\/_/\_\/
  \_\_\/_/

      ____________
     /   /   /\   \
    /___/___/  \___\
   /   /\   \  /\   \
  /___/  \___\/  \___\
 /\   \  /   /\  /   /\
/  \___\/___/  \/___/  \
\  /   /\   \  /   /\  /
 \/___/  \___\/___/  \/
  \   \  /   /\   \  /
   \___\/___/  \___\/
    \   \   \  /   /
     \___\___\/___/

         __________________
        /     /     /\     \
       /     /     /  \     \
      /_____/_____/    \_____\
     /     /\     \    /\     \
    /     /  \     \  /  \     \
   /_____/    \_____\/    \_____\
  /\     \    /     /\    /     /\
 /  \     \  /     /  \  /     /  \
/    \_____\/_____/    \/_____/    \
\    /     /\     \    /     /\    /
 \  /     /  \     \  /     /  \  /
  \/_____/    \_____\/_____/    \/
   \     \    /     /\     \    /
    \     \  /     /  \     \  /
     \_____\/_____/    \_____\/
      \     \     \    /     /
       \     \     \  /     /
        \_____\_____\/_____/

            ________________________
           /       /       /\       \
          /       /       /  \       \
         /       /       /    \       \
        /_______/_______/      \_______\
       /       /\       \      /\       \
      /       /  \       \    /  \       \
     /       /    \       \  /    \       \
    /_______/      \_______\/      \_______\
   /\       \      /       /\      /       /\
  /  \       \    /       /  \    /       /  \
 /    \       \  /       /    \  /       /    \
/      \_______\/_______/      \/_______/      \
\      /       /\       \      /       /\      /
 \    /       /  \       \    /       /  \    /
  \  /       /    \       \  /       /    \  /
   \/_______/      \_______\/_______/      \/
    \       \      /       /\       \      /
     \       \    /       /  \       \    /
      \       \  /       /    \       \  /
       \_______\/_______/      \_______\/
        \       \       \      /       /
         \       \       \    /       /
          \       \       \  /       /
           \_______\_______\/_______/

               ______________________________
              /         /         /\         \
             /         /         /  \         \
            /         /         /    \         \
           /         /         /      \         \
          /_________/_________/        \_________\
         /         /\         \        /\         \
        /         /  \         \      /  \         \
       /         /    \         \    /    \         \
      /         /      \         \  /      \         \
     /_________/        \_________\/        \_________\
    /\         \        /         /\        /         /\
   /  \         \      /         /  \      /         /  \
  /    \         \    /         /    \    /         /    \
 /      \         \  /         /      \  /         /      \
/        \_________\/_________/        \/_________/        \
\        /         /\         \        /         /\        /
 \      /         /  \         \      /         /  \      /
  \    /         /    \         \    /         /    \    /
   \  /         /      \         \  /         /      \  /
    \/_________/        \_________\/_________/        \/
     \         \        /         /\         \        /
      \         \      /         /  \         \      /
       \         \    /         /    \         \    /
        \         \  /         /      \         \  /
         \_________\/_________/        \_________\/
          \         \         \        /         /
           \         \         \      /         /
            \         \         \    /         /
             \         \         \  /         /
              \_________\_________\/_________/

                  ____________________________________
                 /           /           /\           \
                /           /           /  \           \
               /           /           /    \           \
              /           /           /      \           \
             /           /           /        \           \
            /___________/___________/          \___________\
           /           /\           \          /\           \
          /           /  \           \        /  \           \
         /           /    \           \      /    \           \
        /           /      \           \    /      \           \
       /           /        \           \  /        \           \
      /___________/          \___________\/          \___________\
     /\           \          /           /\          /           /\
    /  \           \        /           /  \        /           /  \
   /    \           \      /           /    \      /           /    \
  /      \           \    /           /      \    /           /      \
 /        \           \  /           /        \  /           /        \
/          \___________\/___________/          \/___________/          \
\          /           /\           \          /           /\          /
 \        /           /  \           \        /           /  \        /
  \      /           /    \           \      /           /    \      /
   \    /           /      \           \    /           /      \    /
    \  /           /        \           \  /           /        \  /
     \/___________/          \___________\/___________/          \/
      \           \          /           /\           \          /
       \           \        /           /  \           \        /
        \           \      /           /    \           \      /
         \           \    /           /      \           \    /
          \           \  /           /        \           \  /
           \___________\/___________/          \___________\/
            \           \           \          /           /
             \           \           \        /           /
              \           \           \      /           /
               \           \           \    /           /
                \           \           \  /           /
                 \___________\___________\/___________/

    ________
   /_/\_\_\_\
  /\_\/\_\_\_\
 /\/_/\/_/_/\_\
/\/\_\/_/_/\/\_\
\/\/_/\_\_\/\/_/
 \/\_\/_/\_\/_/
  \/\_\_\/_/_/
   \/_/_/_/_/

        ________________
       /   /\   \   \   \
      /___/  \___\___\___\
     /\   \  /\   \   \   \
    /  \___\/  \___\___\___\
   /\  /   /\  /   /   /\   \
  /  \/___/  \/___/___/  \___\
 /\  /\   \  /   /   /\  /\   \
/  \/  \___\/___/___/  \/  \___\
\  /\  /   /\   \   \  /\  /   /
 \/  \/___/  \___\___\/  \/___/
  \  /\   \  /   /\   \  /   /
   \/  \___\/___/  \___\/___/
    \  /\   \   \  /   /   /
     \/  \___\___\/___/___/
      \  /   /   /   /   /
       \/___/___/___/___/

            ________________________
           /     /\     \     \     \
          /     /  \     \     \     \
         /_____/    \_____\_____\_____\
        /\     \    /\     \     \     \
       /  \     \  /  \     \     \     \
      /    \_____\/    \_____\_____\_____\
     /\    /     /\    /     /     /\     \
    /  \  /     /  \  /     /     /  \     \
   /    \/_____/    \/_____/_____/    \_____\
  /\    /\     \    /     /     /\    /\     \
 /  \  /  \     \  /     /     /  \  /  \     \
/    \/    \_____\/_____/_____/    \/    \_____\
\    /\    /     /\     \     \    /\    /     /
 \  /  \  /     /  \     \     \  /  \  /     /
  \/    \/_____/    \_____\_____\/    \/_____/
   \    /\     \    /     /\     \    /     /
    \  /  \     \  /     /  \     \  /     /
     \/    \_____\/_____/    \_____\/_____/
      \    /\     \     \    /     /     /
       \  /  \     \     \  /     /     /
        \/    \_____\_____\/_____/_____/
         \    /     /     /     /     /
          \  /     /     /     /     /
           \/_____/_____/_____/_____/

                ________________________________
               /       /\       \       \       \
              /       /  \       \       \       \
             /       /    \       \       \       \
            /_______/      \_______\_______\_______\
           /\       \      /\       \       \       \
          /  \       \    /  \       \       \       \
         /    \       \  /    \       \       \       \
        /      \_______\/      \_______\_______\_______\
       /\      /       /\      /       /       /\       \
      /  \    /       /  \    /       /       /  \       \
     /    \  /       /    \  /       /       /    \       \
    /      \/_______/      \/_______/_______/      \_______\
   /\      /\       \      /       /       /\      /\       \
  /  \    /  \       \    /       /       /  \    /  \       \
 /    \  /    \       \  /       /       /    \  /    \       \
/      \/      \_______\/_______/_______/      \/      \_______\
\      /\      /       /\       \       \      /\      /       /
 \    /  \    /       /  \       \       \    /  \    /       /
  \  /    \  /       /    \       \       \  /    \  /       /
   \/      \/_______/      \_______\_______\/      \/_______/
    \      /\       \      /       /\       \      /       /
     \    /  \       \    /       /  \       \    /       /
      \  /    \       \  /       /    \       \  /       /
       \/      \_______\/_______/      \_______\/_______/
        \      /\       \       \      /       /       /
         \    /  \       \       \    /       /       /
          \  /    \       \       \  /       /       /
           \/      \_______\_______\/_______/_______/
            \      /       /       /       /       /
             \    /       /       /       /       /
              \  /       /       /       /       /
               \/_______/_______/_______/_______/

                    ________________________________________
                   /         /\         \         \         \
                  /         /  \         \         \         \
                 /         /    \         \         \         \
                /         /      \         \         \         \
               /_________/        \_________\_________\_________\
              /\         \        /\         \         \         \
             /  \         \      /  \         \         \         \
            /    \         \    /    \         \         \         \
           /      \         \  /      \         \         \         \
          /        \_________\/        \_________\_________\_________\
         /\        /         /\        /         /         /\         \
        /  \      /         /  \      /         /         /  \         \
       /    \    /         /    \    /         /         /    \         \
      /      \  /         /      \  /         /         /      \         \
     /        \/_________/        \/_________/_________/        \_________\
    /\        /\         \        /         /         /\        /\         \
   /  \      /  \         \      /         /         /  \      /  \         \
  /    \    /    \         \    /         /         /    \    /    \         \
 /      \  /      \         \  /         /         /      \  /      \         \
/        \/        \_________\/_________/_________/        \/        \_________\
\        /\        /         /\         \         \        /\        /         /
 \      /  \      /         /  \         \         \      /  \      /         /
  \    /    \    /         /    \         \         \    /    \    /         /
   \  /      \  /         /      \         \         \  /      \  /         /
    \/        \/_________/        \_________\_________\/        \/_________/
     \        /\         \        /         /\         \        /         /
      \      /  \         \      /         /  \         \      /         /
       \    /    \         \    /         /    \         \    /         /
        \  /      \         \  /         /      \         \  /         /
         \/        \_________\/_________/        \_________\/_________/
          \        /\         \         \        /         /         /
           \      /  \         \         \      /         /         /
            \    /    \         \         \    /         /         /
             \  /      \         \         \  /         /         /
              \/        \_________\_________\/_________/_________/
               \        /         /         /         /         /
                \      /         /         /         /         /
                 \    /         /         /         /         /
                  \  /         /         /         /         /
                   \/_________/_________/_________/_________/

                        ________________________________________________
                       /           /\           \           \           \
                      /           /  \           \           \           \
                     /           /    \           \           \           \
                    /           /      \           \           \           \
                   /           /        \           \           \           \
                  /___________/          \___________\___________\___________\
                 /\           \          /\           \           \           \
                /  \           \        /  \           \           \           \
               /    \           \      /    \           \           \           \
              /      \           \    /      \           \           \           \
             /        \           \  /        \           \           \           \
            /          \___________\/          \___________\___________\___________\
           /\          /           /\          /           /           /\           \
          /  \        /           /  \        /           /           /  \           \
         /    \      /           /    \      /           /           /    \           \
        /      \    /           /      \    /           /           /      \           \
       /        \  /           /        \  /           /           /        \           \
      /          \/___________/          \/___________/___________/          \___________\
     /\          /\           \          /           /           /\          /\           \
    /  \        /  \           \        /           /           /  \        /  \           \
   /    \      /    \           \      /           /           /    \      /    \           \
  /      \    /      \           \    /           /           /      \    /      \           \
 /        \  /        \           \  /           /           /        \  /        \           \
/          \/          \___________\/___________/___________/          \/          \___________\
\          /\          /           /\           \           \          /\          /           /
 \        /  \        /           /  \           \           \        /  \        /           /
  \      /    \      /           /    \           \           \      /    \      /           /
   \    /      \    /           /      \           \           \    /      \    /           /
    \  /        \  /           /        \           \           \  /        \  /           /
     \/          \/___________/          \___________\___________\/          \/___________/
      \          /\           \          /           /\           \          /           /
       \        /  \           \        /           /  \           \        /           /
        \      /    \           \      /           /    \           \      /           /
         \    /      \           \    /           /      \           \    /           /
          \  /        \           \  /           /        \           \  /           /
           \/          \___________\/___________/          \___________\/___________/
            \          /\           \           \          /           /           /
             \        /  \           \           \        /           /           /
              \      /    \           \           \      /           /           /
               \    /      \           \           \    /           /           /
                \  /        \           \           \  /           /           /
                 \/          \___________\___________\/___________/___________/
                  \          /           /           /           /           /
                   \        /           /           /           /           /
                    \      /           /           /           /           /
                     \    /           /           /           /           /
                      \  /           /           /           /           /
                       \/___________/___________/___________/___________/