76
7
Challenge
Create a function or program that, when given an integer size
, does the following:
If size
is equal to 1, output
H H
HHH
H H
If size
is greater than 1, output
X X
XXX
X X
where X
is the output of the program/function for size - 1
(If you prefer, you may have the base case correspond to 0
, so long as you specify in your answer)
Any of the following output formats are acceptable, whichever is more convenient for you:
A string of the required structure with any two distinct characters corresponding to
H
andspace
A two-dimensional array with the required structure, with any two distinct values corresponding to
H
andspace
An array/list of strings, with one line of the output in each string, with any two distinct values corresponding to
H
andspace
Leading spaces are allowed, as long as there is a constant amount of leading spaces on each line. The two distinct output characters can be dependent on anything you choose, as long as they are different.
Specify what output format your code is returning.
Test Cases
1
H H
HHH
H H
2
H H H H
HHH HHH
H H H H
H HH HH H
HHHHHHHHH
H HH HH H
H H H H
HHH HHH
H H H H
3
H H H H H H H H
HHH HHH HHH HHH
H H H H H H H H
H HH HH H H HH HH H
HHHHHHHHH HHHHHHHHH
H HH HH H H HH HH H
H H H H H H H H
HHH HHH HHH HHH
H H H H H H H H
H H H HH H H HH H H H
HHH HHHHHH HHHHHH HHH
H H H HH H H HH H H H
H HH HH HH HH HH HH HH HH H
HHHHHHHHHHHHHHHHHHHHHHHHHHH
H HH HH HH HH HH HH HH HH H
H H H HH H H HH H H H
HHH HHHHHH HHHHHH HHH
H H H HH H H HH H H H
H H H H H H H H
HHH HHH HHH HHH
H H H H H H H H
H HH HH H H HH HH H
HHHHHHHHH HHHHHHHHH
H HH HH H H HH HH H
H H H H H H H H
HHH HHH HHH HHH
H H H H H H H H
This is code-golf, so the lowest byte count for each language wins!
4Perfect for Charcoal probably... lol. Also welcome to PPCG! :D – HyperNeutrino – 2018-03-09T01:54:46.453
10Welcome to PPCG. Nice first challenge! – Adám – 2018-03-09T02:06:59.993
May we use 0 based sizes? – Adám – 2018-03-09T02:07:19.467
@Adám that is acceptable – Bazinga_9000 – 2018-03-09T02:10:45.167
Forgot to check your acceptable outputs before I submitted, but would an array of strings be acceptable instead of a two-dimensional array? This is for languages where a string is not formally an array of characters, but its own data structure. – Value Ink – 2018-03-09T02:22:42.907
@ValueInk That's fine – Bazinga_9000 – 2018-03-09T02:24:38.067
3related – ngn – 2018-03-09T02:26:35.347
Can I print the desired output instead of returning it? Can I give a program that instead of a function? – Titus – 2018-03-09T10:53:29.403
Are leading spaces (or whatever the chosen background character is) allowed ? – Ton Hospel – 2018-03-09T15:46:58.263
Possible duplicate of ABAA/ABBB: Generate this recursive 2D pattern
– Erik the Outgolfer – 2018-03-09T17:23:50.177@LuisMendo apologies, there are no restrictions on the two output characters so long as they are different. You can have them depend on whatever you want. – Bazinga_9000 – 2018-03-10T02:11:09.757
@Titus that's fine – Bazinga_9000 – 2018-03-10T02:11:43.430
@TonHospel Leading/trailing spaces are allowed so long as they are consistent across all lines (so the structure of the H remains) – Bazinga_9000 – 2018-03-10T02:12:55.013
1I'd call this a "Sierpinski H" – mbomb007 – 2018-03-12T21:37:27.573
I made a dot plot, but I don't think that qualifies: https://repl.it/repls/ShockedAgitatedKeygenerator
– mbomb007 – 2018-03-13T18:19:03.150I just found a piece of paper from 2008 where I did exactly this! I was 8 at that time and very interested in fractals (meaning: even more than now). It's the fourth iteration. Photo: https://drive.google.com/open?id=1Ww7_i2phDWGwUNUZCte0Nr4YrKz_Mlxg
– Fabian Röling – 2018-04-07T18:20:59.017Apparently a I can't do Math. I was 12 in 2008, not 8. +2, not -2. – Fabian Röling – 2018-04-07T20:59:22.227