Make a ASCII Hexagon Ring Tiling

10

1

Using ASCII print a section of a hexagon ring tiling.

Here's a small section:

       /\__/\
      /_/  \_\
 /\__/\ \__/ /\__/\ 
/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/
 /\__/\ \__/ /\__/\ 
/_/  \_\/__\/_/  \_\ 
\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/
      \ \__/ /
       \/__\/

Here's a larger section:

\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/

Challenge

Given 2 integers h and w, where h is the height and w is the width, output a hxw section of a hexagon ring tiling.

Examples

Input 1

4x4

Output 1

 /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\

Input 2

3x3

Output 2

 /\__/\ \__/ /\__/\
/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/
 /\__/\ \__/ /\__/\
/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/
 /\__/\ \__/ /\__/\
/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/

Input 3

1x3

Output 3

 /\__/\ \__/ /\__/\
/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/

Input 4

3x6

Output 4

 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\

Clarifications

  • My question is similar to this one: Me Want Honeycomb.
  • The input will be on a single line in the form hxw.
  • Output to stdout (or something similar).
  • This is code-golf so shortest answer in bytes wins.

Bobas_Pett

Posted 2016-12-12T02:50:44.047

Reputation: 965

6You should clarify exactly how large of a section we must output, to remain clear and objective – James – 2016-12-12T02:59:22.530

I just saw your comment I'll fix the dimensions to make it more clear – Bobas_Pett – 2016-12-12T03:56:08.460

Since I don't think the moderators saw my comment, if the question stays on hold for the next 2 hours, ill make an updated question with the edits I did and a 4th example for clarity. Sorry for the confusion and if the edits I made aren't close to what you wanted please post comment telling me what's needed. – Bobas_Pett – 2016-12-12T04:10:41.990

Should this be tagged kolmogorov-complexity? – Pavel – 2016-12-12T07:06:38.553

ill add it in 1 sec... – Bobas_Pett – 2016-12-12T07:07:56.600

Answers

2

Befunge, 137 bytes

I seem to have created some kind of scifi hand gun.

&>4*>~>$&>\>1-:4%3v
>00gg,\1-:v^_@#:\<>+00p\::6*\00g2/+2%+1+66+:
^%+66<:+1\_$$55+,^
_\/__\/_/  \
\ \__/ /\__/\
/_/  \_\/__\/
 /\__/\ \__/

Try it online!

Explanation

&>4*>                    Read the height and multiply by 4.
     ~>$                 Drop the 'x' separator. 
        &>\              Read the width and swap below the height

>                        Start of the outer loop.
 1-                      Decrement the height.              
   :4%3+00p              Calculate the pattern y offset: height%4+3
           \             Swap the width back to the top.

::6*\00g2/+2%+1+         Calculate the line length: w*6+(w+y/2)%2+1 
                66+:     Initialise the pattern x offset to 12, and duplicate it.

>                        Start of the inner loop.     
 00gg                    Get a pattern char using the x on the stack and the saved y.
     ,                   Output the char.
      \1-                Swap the line length to the top of the stack and decrement it.
         :v              Check if it's zero, and if so...
          _                 ...break out of the loop to the right.
       +1\               Otherwise swap the x offset back to the top and increment it.
 %+66<:                  Mod it with 12 to make sure it's in range.
^                        Then return to the beginning of the inner loop.

$$                       Drop the x offset and line length.
  55+,                   Output a newline.
     \<                  Swap the height back to the top of the stack.
 _@#:                    Check if it's zero, and exit if that's the case.
^                        Otherwise return to the start of the outer loop.

James Holderness

Posted 2016-12-12T02:50:44.047

Reputation: 8 298

3

Lua, 174 176 156 bytes

The code would print height-amount of lines, not height-amount of hexagons. Added *4, that fixed it, but added 2 extra bytes. Saved some bytes by changing the counter from if to modulo, and by putting two io.read()s into one.

Uses io.read() as input.

a,w,h,n,d={[[ /\__/\ \__/]],[[/_/  \_\/__\\]],[[\ \__/ /\__/]],[[_\/__\/_/  \\]]},io.read(,),"",0 for i=h*4,0,-1 do d=d+1 d=5%d end n=a[d]print(n:rep(w))end

Replicates the strings width-amount of times via string:rep(width), then iterates height-amount of times with a for-loop. Needed [[]] (literal strings) because the backslashes really screwed stuff up.

Old Version:

a,w,h,n,d={[[ /\__/\ \__/]],[[/_/  \_\/__\\]],[[\ \__/ /\__/]],[[_\/__\/_/  \\]]},io.read(),io.read(),"",0 for i=h*4,0,-1 do d=d+1 d=5%d end n=a[d]print(n:rep(w))end

devRicher

Posted 2016-12-12T02:50:44.047

Reputation: 1 609

1

Python 2, 180 bytes

a,b,c,d=' /\__/\ \__/','/_/  \_\/__\\','\ \__/ /\__/','_\/__\/_/  \\'
h,w=input()
x=w/2
e,E=[(2,1),(7,8)][w%2]
print'\n'.join([a*x+a[:e],b*x+b[:E],c*x+c[:E],' '+(d*x+d[:e])[1:]]*h)

Takes input as two integers

Input: 2,7

Output:

 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/
 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/

TFeld

Posted 2016-12-12T02:50:44.047

Reputation: 19 246

1

Batch, 266 bytes

@echo off
for /l %%i in (1,1,%1)do call:l %2 " \" /__\/ "_/  \_\" " \__/ /" \__/\
exit/b
:l
call:c %1 " /" %6 %5
call:c %1 / %4 %3
call:c %1 \ %5 %6
:c
set s=%~2
for /l %%j in (2,2,%1)do call set s=%%s%%%~3%~4
set/ao=%1^&1
if %o%==1 set s=%s%%~3
echo %s%

The :c subroutine does all the legwork of concatenating the pieces together for a single line; it is called by :l 4 times (one by fall though by arranging for :l's arguments to be a superset of :c's) to generate the 4 lines for each row of rings. There was also the possibility of falling through for the last row of rings instead but it turned out to be 5 bytes longer.

Neil

Posted 2016-12-12T02:50:44.047

Reputation: 95 035