14
1
Given two positive integers, 'a' and 'b', output an ascii-art "box" that is a characters wide and b characters tall. For example, with '4' and '6':
****
* *
* *
* *
* *
****
Simple right? Here's the twist: The border of the box must be the characters of "a" and "b" alternating. This starts at the top left corner, and continues in a clockwise spiral. For example, the previous example with 4 and 6 should be
4646
6 4
4 6
6 4
4 6
6464
A and B may be two-digit numbers. For example, the inputs "10" and "3" should output this:
1031031031
1 0
3013013013
In order to keep the output relatively small, you do not have to support three or more digit numbers. Also, since inputs are restricted to positive integers, '0' is an invalid input, which you do not have to handle.
Here are some more test cases:
Input: (3, 5)
Output:
353
5 5
3 3
5 5
353
Input: (1, 1)
Output:
1
Input: (4, 4)
Output:
4444
4 4
4 4
4444
Input: (27, 1)
Output:
271271271271271271271271271
Input: (1, 17)
Output:
1
1
7
1
1
7
1
1
7
1
1
7
1
1
7
1
1
Input: (12, 34):
Output:
123412341234
4 1
3 2
2 3
1 4
4 1
3 2
2 3
1 4
4 1
3 2
2 3
1 4
4 1
3 2
2 3
1 4
4 1
3 2
2 3
1 4
4 1
3 2
2 3
1 4
4 1
3 2
2 3
1 4
4 1
3 2
2 3
1 4
432143214321
You may take input and output in any reasonable format, and standard loopholes are banned. Since this is code-golf, the shortest answer in bytes wins!
Related – James – 2016-08-18T06:31:51.593
Must I start the pattern from the top left hand corner clockwise? – Leaky Nun – 2016-08-18T06:33:17.257
@LeakyNun Yes, that is necessary. – James – 2016-08-18T06:33:59.573
If
a
is 1 is it the left wall or the right wall? – Leaky Nun – 2016-08-18T06:42:48.507@LeakyNun I'm not sure if it makes any difference. Either way, I added a test case with
a = 1
– James – 2016-08-18T06:46:25.623do i have to print the box? – downrep_nation – 2016-08-18T08:32:53.677
7Isn't the first example wrong? (3,5) should be 3 wide and 5 tall – Brian – 2016-08-18T10:27:19.423
@Brian Yes, you're right. Sorry about that, fixed now. – James – 2016-08-18T14:56:24.563
Is a leading newline ok? – jrich – 2016-08-18T15:10:11.830