10
\$\begingroup\$

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.
\$\endgroup\$
5
  • 6
    \$\begingroup\$ You should clarify exactly how large of a section we must output, to remain clear and objective \$\endgroup\$
    – DJMcMayhem
    Dec 12, 2016 at 2:59
  • \$\begingroup\$ I just saw your comment I'll fix the dimensions to make it more clear \$\endgroup\$
    – Bobas_Pett
    Dec 12, 2016 at 3:56
  • \$\begingroup\$ 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. \$\endgroup\$
    – Bobas_Pett
    Dec 12, 2016 at 4:10
  • \$\begingroup\$ Should this be tagged kolmogorov-complexity? \$\endgroup\$
    – Pavel
    Dec 12, 2016 at 7:06
  • \$\begingroup\$ ill add it in 1 sec... \$\endgroup\$
    – Bobas_Pett
    Dec 12, 2016 at 7:07

4 Answers 4

3
\$\begingroup\$

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
\$\endgroup\$
2
\$\begingroup\$

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.
\$\endgroup\$
1
\$\begingroup\$

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:

 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/
 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/
\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.