15
2
See also: Wordagons
Challenge
Given a hexagon and a number n
as input, output the same hexagon rotated n
times.
Hexagon
The hexagon will be a string like so:
a b c
d d e e
f f o g g
h h i i
j k l
The hexagon will always be regular and will only ever contain the printable ASCII characters:
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
Rotation
To find how much to rotate the hexagon by, multiply n
by 60 degrees to get the angle of rotation. For example, using the above hexagon, if n
is 2, we multiply that by 60 to get 120 degrees. Then, we rotate the hexagon by 120 degrees:
j h f
k h f d
l i o d a
i g e b
g e c
Note that each side has moved two sides clockwise.
If n
is positive, you should rotate the hexagon clockwise. If n
is negative, you should rotate the hexagon anticlockwise.
n
will always be an integer in the range -6 to 6 inclusive.
Examples
Input:
. u .
. | .
l - + - r
. | .
. d .
n
= 3
. d .
. | .
r - + - l
. | .
. u .
Input:
- - -
/ \
< >
\ /
- - -
n
= -1
Output:
- \ >
- /
- -
/ -
< \ -
Input:
h e x a
g o n s a
n d t r i a
n g l e s m a
k e m e s a
d l y m a
d d e r
n
= 6
Output:
h e x a
g o n s a
n d t r i a
n g l e s m a
k e m e s a
d l y m a
d d e r
Winning
The shortest program in bytes wins.
2What do you have against triangles? :P – Conor O'Brien – 2016-09-06T23:08:59.347
4@ConorO'Brien Haven't you seen how dangerous their points are? ;) – Beta Decay – 2016-09-06T23:11:42.817
Can we take input as a list of lines? Can we assume input is space-padded? – Lynn – 2016-09-06T23:36:51.703
@Lynn Yep, a list of lines is fine and it will be padded – Beta Decay – 2016-09-06T23:40:42.027
1
Very closely related: http://codegolf.stackexchange.com/q/51964/15599
– Level River St – 2016-09-06T23:43:37.987@LevelRiverSt This challenge does support negative integers though – Beta Decay – 2016-09-06T23:53:16.873
Well, you can just repeat the code
n%6
times. – Lynn – 2016-09-07T00:20:09.6171I lost a few minutes trying to be a smartass with CSS'
transform:rotate(x)
. Turns out that wasn't a bright idea, who would have known? – Aaron – 2016-09-07T14:28:35.583I know you have space in your possible character list, but do we really need to support characters that are the same as the background character ? Having to use coordinates makes all my solutions a lot longer – Ton Hospel – 2016-09-08T12:21:17.657
@TonHospel Yes, you need to support hexagons like this and this
– Beta Decay – 2016-09-08T13:00:11.760@BetaDecay Would I be allowed to remove
t.up()
in my program? It leaves extra "pen lines" on the canvas where the turtle moves. – mbomb007 – 2016-09-09T15:13:02.723@mbomb007 Hm, sorry, but since it's an ascii art challenge, no – Beta Decay – 2016-09-09T15:14:53.953