Programmers are often obsessed with drawing fractals. I think we need a new computer based medium.
Now, imagine each of the lines in the image is a directory (folder) in a standard computer file system. All but the smallest lines intersect two lines smaller than themselves; these two smaller lines are subdirectories of the larger line. Thus the large horizontal line in the middle is the parent directory of the two largest vertical lines, which are in turn parents, grandparents, etc. of rest of the lines in the image.
Write a program that takes in a positive integer N via stdin or the command line (or closest alternative) and creates a directory tree that mirrors the Nth iteration of the H tree fractal.
The first iteration (N = 1) is a single horizontal line. In each subsequent iteration a new set of vertical or horizontal lines is added to the ends of the current lines. So for N = 2 two vertical lines are added (making an H shape), for N = 3 four horizontal lines are added to that, etc.
The name of the root directory must always be
tree. The names of the subdirectories must match the direction they are in with respect to their parent line, using
Since the root directory is always a horizontal line it will always have
left subdirectories. But those two will have
down subdirectories, and those will have
left again, and so on.
The directories at the end of the limit of iterations should be empty.
For N = 3 the directory tree should look like this:
tree right up down left up down
- Ideally the
treedirectory will pop up in the same folder the source code is in, but it's alright if it goes to some working directory.
- You may assume that there is no pre-existing
treedirectory in the place yours will be created.
- You may assume that your program will always be run on the same common modern operating system (Mac/Windows/Linux). Basically don't worry about using a file separator that doesn't work in all OS's.
This is code-golf, so the shortest code in bytes wins.