4
\$\begingroup\$

The task

Given a folded and cut in places snowflake, "unwrap" it and output the result

Input

The base folded snowflake, without any cuts, looks like:

|\
| \
|  \
|   \
|    \
|     \
|      \
|       \
|________\

And the input will always resemble this. No changed or added symbols will go out of the range of this triangle, so

 |\
 | \
-|  \
 |   \  o 0
 |    \
 |     \ 
 |      \.
 |       \
 |________\

is not a valid input.

Possible changes and additions:

  1. Corner cuts
minimal cut:
 _
| \
|  \
|   \
|    \
|     \
|      \
|_      \
  |_____/
Big, different cuts with cuts in them:


|\_/\
|    \
|     \
|___   \
   _|  _|
  |___/
  1. Side cuts
minimal cuts, in random places on the sides:

|\
| \
|  \
|  |_
|    \
 \    \
 /     \
|       \
|____/\__\
Big, recursive cuts:
|\
| \
 \ \
  \|
  /|
 | |  _
 / |_| \
| |\___ \
|_|    \_\

And, of course, both types can be present at the same time.

Output

An "unfolded" snowflake. Here is an explanation of the unfold:

Say we have a snowflake
 __
|  \
|   \
|    \
 \    \
 /     \
|       /
|______/

Which we will, for the explanation, remake as:

 aa
1  1
2   2
3    3
 b    4
 b     5
1       c
2123456c

Where each uncut piece of sides is numbered from 1 to 9, and each cut has its own letter.
On the first unfold, you will get
    123  12
   a   bb 1
 aaa      2
1         3
2         4
3         5
 b        c
 b       c
1       c
2123456c

Which looks like
    ___  __
   |   \/ |
 __|      |
|         |
|         |
|         |
 \       /
 /      /
|      /
|_____/



Then, on the next unfold, we get:
    123  1221  321
   a   bb    bb   a
 aaa              aaa
1                    1
2                    2
3                    3
 b        cc        b
 b       c  c       b
1       c    c       1
2123456c      c6543212

Which looks like

    ___  ____  ___
   |   \/    \/   |
 __|              |__
|                    |
|                    |
|                    |
 \        /\        /
 /       /  \       \
|       /    \       |
|______/      \______|

If you would want another unfold, the scheme looks fine:

    123  1221  321
   a   bb    bb   a
 aaa              aaa
1                    1
2                    2
3                    3
 b        cc        b
 b       c  c       b
1       c    c       1
2      c      c      2
2      c      c      2
1       c    c       1
 b       c  c       b
 b        cc        b
3                    3
2                    2
1                    1
 aaa              aaa
   a   bb    bb   a
    123  1221  321

Until you actually make it in ascii:

    ___  ____  ___
   |   \/    \/   |
 __|              |__
|                    |
|                    |
|                    |
 \        /\        /
 /       /  \       \
|       /    \       |
|      /      \      |
|      \      /      |
|       \    /       |
 \       \  /       /
 /        \/        \
|                    |
|                    |
|                    |
 __|              |__
   |   /\    /\   |
    ___  ____  ___

So, for this challenge, I have chosen not to go for another unfold.

Here is another example on one of the snowflakes, without the scheme:

|\
| \
|  \
|   \
 \   \
 /    \
|      \
|  /\   \
|_/  \__/

Then, on the first unfold turns to:
____  ____
|   \/    |
|         /
|        /
|        \
 \        \
 /        |
|         |
|  /\    /
|_/  \__/

And then:
 ____  ________  ____
|    \/        \/    |
|         /\         |
|        /  \        |
|        \  /        |
 \        \/        /
 /                  \
|                    |
|  /\            /\  |
|_/  \__________/  \_|

Notice how, on the first unfold, the bottom side of the triangle translates to the right side of the square and, the same, with the left and top side.

Output

The final result, so

 ____  ________  ____
|    \/        \/    |
|         /\         |
|        /  \        |
|        \  /        |
 \        \/        /
 /                  \
|                    |
|  /\            /\  |
|_/  \__________/  \_|

for the example.

This is code-golf, so lowest byte-count wins!

\$\endgroup\$
3
  • 5
    \$\begingroup\$ I still don't understand the first unfolding. In your first example (right below the "Output" heading), the bottom edge has 123456, but the unfolded right edge has only 12345. Where does the 6 go? \$\endgroup\$ Commented May 20, 2020 at 8:21
  • 2
    \$\begingroup\$ Why do in the second example the bottom three left-hand side | become four top-right _ after the first unfold? \$\endgroup\$ Commented May 20, 2020 at 10:04
  • 2
    \$\begingroup\$ Also in the second example (second unfold): where did the bottom gap go? Shouldn't the result be this instead? Although in that case I'm also wondering why the two _ at the bottom have become three _ from the first to second unfold. \$\endgroup\$ Commented May 20, 2020 at 10:12

0

Browse other questions tagged or ask your own question.