34
I find it fascinating how the letters "H" and "I" are very similar. "H" is a horizontal stroke surrounded by two vertical strokes; "I" is a vertical stroke surrounded by two horizontal strokes (depending on your font). I bet this could be nested... You know what that reminds me of? Fractals!!!
Let's define the "IHIH" pyramid as follows: The first iteration is this ASCII representation of the letter "I":
---
|
---
The next iteration has a vertical stroke on either side.
| |
|---|
| | |
|---|
| |
If you view the "I" in the middle as a single horizontal stroke, then this second iteration is basically an "H". The third iteration adds a horizontal stroke on the top and bottom
-------
| |
|---|
| | |
|---|
| |
-------
Again, if you view the "H" in the middle as a single vertical stroke, then this iteration is basically an "I". This pattern continues, alternating between "H"s and "I"s on every iteration. For reference, here are the first 6 iterations:
1:
---
|
---
2:
| |
|---|
| | |
|---|
| |
3:
-------
| |
|---|
| | |
|---|
| |
-------
4:
| |
|-------|
| | | |
| |---| |
| | | | |
| |---| |
| | | |
|-------|
| |
5:
-----------
| |
|-------|
| | | |
| |---| |
| | | | |
| |---| |
| | | |
|-------|
| |
-----------
6:
| |
|-----------|
| | | |
| |-------| |
| | | | | |
| | |---| | |
| | | | | | |
| | |---| | |
| | | | | |
| |-------| |
| | | |
|-----------|
| |
The Challenge:
Write a program or function that outputs the N'th iteration of the IHIH pyramid, and an optional trailing newline. Your input will be a single positive integer in whatever reasonable format you want. You do not have to handle invalid inputs, e.g. non-integers, numbers smaller than 1, etc. Your program must at the very least produce the right output for inputs up to 20. Since this is code-golf, standard loopholes are not allowed and the shortest answer in bytes wins!
Is it acceptable if I return an arrow of strings one fror each row? – Rohan Jhunjhunwala – 2016-08-19T01:13:11.750
Didn't quite meeting the challenge criteria, but did something cool by accident... Try it online!
– Magic Octopus Urn – 2018-05-21T14:09:40.070