7
\$\begingroup\$

Imagine for a second that you can compose a tree out of dots.

       .
      ...
     .....
    .......
   .........
  ...........
 .............
...............
      ...
      ...

This tree is 13 dots tall.

Now imagine for a second that your filesystem looked like these dots. Your task in this challenge is to make a tree out of folders.

The Challenge

Given an input integer (let's call it n), make a tree out of subdirectories.

  1. In each tree, you should start with a folder called 1.
  2. In that folder, put the folders 1, 2, and 3.
  3. In every level of folder thereon until n-3, in folder 1 of this level of the tree, there should be a folder labelled 1 and 2. In folder 2 of this level of the tree, there should be a folder called 3, in folder 3, a folder called called 4, and so on until the last folder (the integer this folder is called, we'll call k), in which there should be a folder called k and one called k+1.
  4. At level n-3, however, all of the subdirectories but the middle three folders should be replaced with a file with the name that the subdirectories would have had. The middle three subdirectories should remain as subdirectories.
  5. These three subdirectories should contain a folder called 1, 2, or 3 with respect to the order of these directories' name.
  6. These are followed by a layer of files where 1 is in folder 1, 2 is in folder 2, and 3 is in folder three.

The example shown at the top of this question is represented below in folder form.

folders

This would be n = 13.

Rules

  • You may use builtins for folder creation, but not for subdirectory creation.
  • All other standard loopholes apply.
  • You must support past n=5, but do not have to support greater than n=30.
\$\endgroup\$
1
  • \$\begingroup\$ There are several problems with the original post here. The tree of dots appears to be 10 dots tall, not 13. In the graphic, the folders are 9 deep, so I'm assuming it should be n=9. The last folders on each level contain folders named k+1 and k+2, not k and k+1. \$\endgroup\$ Jun 5, 2016 at 3:39

1 Answer 1

3
\$\begingroup\$

Windows Batch File, 429 423 404 bytes

md 1
set C= call:
set/a M=%1-2
%C%f 1 1 2 L
%C%f 1 2 2 M
%C%f 1 3 2 R
goto:eof
:f
md %1\%2
set/a P=%2+1
set/a Q=%2+2
set/a L=%3+1
set D= (%C%t %1\%2\%P% 
if %L%==%M% (if %4==L .>%1\%2\1
if %Q%==%M%%D%1)else (if %P%==%M%%D%2)else (if %2==%M%%D%3)else .>%1\%2\%P%))
if %4==R .>%1\%2\%Q%
)else (if %4==L%C%f %1\%2 1 %L% L
%C%f %1\%2 %P% %L% M
if %4==R%C%f %1\%2 %Q% %L% R)
goto:eof
:t
md %1\%2
.>%1\%2\%2

Call it with the value of n as a command line parameter.

Here is a visualization of the output tree for n=9:

                   1
                +--+--+
                1  2  3
             +--+  |  +--+
             1  2  3  4  5
          +--+  |  |  |  +--+
          1  2  3  4  5  6  7
       +--+  +  |  |  |  |  +--+
       1  2  3  4  5  6  7  8  9
    +--+  |  |  |  |  |  |  |  +--+
    1  2  3  4  5  6  7  8  9 10 11
 +--+  |  |  |  |  |  |  |  |  |  +--+
 1  2  3  4  5  6  7  8  9 10 11 12 13
                |  |  |
                1  2  3
                |  |  |
                1  2  3
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.