Challenge
This is a simple challenge. Given two positive integers w
and h
create an ASCII fence with a width of w
and a height of h
. The fence should be constructed using the following rules:
- The
+
character will represent a post. - The
-
character will be used to represent the width of the fence. - The
|
will be used to represent the height of the fence. - After exactly three
-
characters have been outputted, a+
character must be outputted afterward. Excluding the four corners, any other time you output a+
would be invalid. You are allowed to follow this rule starting either from the left or the right (see examples), but you must be consistent. - After exactly two
|
characters have been outputted, a+
character must be outputted afterward. Excluding the four corners, any other time you output a+
would be invalid. You are allowed to follow this rule starting either from the top or bottom (see examples), but you must be consistent. - Each fence will have exactly four corners, and each corner will be represented with a
+
.
In other words: At every three -
characters, you must output a +
. And at every two |
characters, you must output a +
.
You can assume that the fence will always be a rectangle, and that both w
and h
will never be greater than 100
or less than 1
. Trailing and/or preceding whitespace is allowed.
Examples/Test Cases
w = 1
h = 1
+-+
| |
+-+
w = 3
h = 2
+---+
| |
| |
+---+
w = 5
h = 7
+---+--+ or +--+---+
| | | |
| | + +
+ + | |
| | | |
| | + +
+ + | |
| | | |
| | + +
+ + | |
| | | |
+---+--+ +--+---+
w = 10
h = 5
+---+---+---+-+ or +-+---+---+---+
| | | |
| | + +
+ + | |
| | | |
| | + +
+ + | |
| | | |
+---+---+---+-+ +-+---+---+---+
w = 4
h = 4
+---+-+ or +-+---+
| | | |
| | | |
+ + + +
| | | |
| | | |
+---+-+ +-+---+
Rules
- Standard loopholes apply.
- This is code-golf, so the shortest answer in bytes wins!
+
's touching? \$\endgroup\$ – xnor Jun 27 '17 at 22:53+-+-+-+-+-+
is invalid. Sorry for the confusion. \$\endgroup\$ – Christian Dean Jun 28 '17 at 5:17