7
\$\begingroup\$

This is an challenge where you will draw ascii-art showing a person "jumping" off the top of a building.


The building

Input given will be a group of rectangular buildings. You may assume buildings are not "stacked on top of each other", hence only one row of buildings. This is the standard format of a building:

-----
|   |
|   |
|   |
|   |

A row of buildings looks similar.

                       ------
-----    --------------|    |
|   |    |            ||    |
|   |----|            ||    |
|   ||  ||            ||    |
|   ||  ||            ||    |

You may choose to remove the duplicate | between two buildings if you would like.

Yes, buildings may be taller than the ones on their lefts, but you may assume that all buildings have a nonzero height.

This group of buildings will be given as input, in addition to the building index, which can be 0-or-1-indexed. (please specify which in your answer.)

You can also take input as an array of building characteristics or two arrays of heights and widths.

The person

A person is represented by an o. The person always starts on the right of the given building, and starts jumping immediately.

Jumping

To quote this article,

The greatest human leapers in the world are able to jump over a bar suspended nearly 8 feet off of the ground.

Since I go by meters, this is about 3 meters (actually about 2.5, but whatever.) The person will hence jump "diagonally" for 3 meters (lines) before starting to fall, after which the person will also fall diagonally until hitting the top of a building or the ground.

Each meter should be represented by another o at the exact position.

Example

Example is 1-indexed.

Given the above row of buildings and the index 1, this would be the trajectory:

       o
      o o
     o   o
    o     o            ------
-----    --------------|    |
|   |    |            ||    |
|   |----|            ||    |
|   ||  ||            ||    |
|   ||  ||            ||    |

The person started at the right of the first building, then there were 3 os going upwards before the os started trending downwards. The o's stopped the moment the person hit the third building.

Given index 3:

                         o
                        o o
                       o   o
                      o------
-----    --------------|    |
|   |    |            ||    |
|   |----|            ||    |
|   ||  ||            ||    |
|   ||  ||            ||    |

Note that the person cannot be stopped by the top of a building before completing his 3-meter initial jump.

Given index 4:

                               o
                              o o
                             o   o
                            o     o
                       ------      o
-----    --------------|    |       o
|   |    |            ||    |        o
|   |----|            ||    |         o
|   ||  ||            ||    |          o
|   ||  ||            ||    |           o

The person stopped after hitting the ground.

Given index 2:

This particular case is impossible as the person is stopped by the wall of the following building. This brings another rule into the challenge: you are allowed to assume that there will never be impossible input, i.e. one where the person is stopped by another building's wall in the way, whether in his initial 3-meter jump or as he is coming down (the top of the building does not stop the person from jumping).

You are also permitted to use a character other than o as long as it is none of |- (note the trailing whitespace, you may not use whitespace to denote the person.)

Macrons are permitted (the ones which look like "overscores") and if you do use them you may count them as one byte. There will never be gaps between buildings.

This is , so the shortest answer in bytes wins with standard loopholes disallowed as usual.

\$\endgroup\$
4
  • \$\begingroup\$ I wonder if a regex solution for this would be possible \$\endgroup\$
    – user100752
    Jun 19, 2021 at 9:43
  • 2
    \$\begingroup\$ @EliteDaMyth I've been trying that, it hasn't ended well. \$\endgroup\$
    – emanresu A
    Jun 19, 2021 at 9:44
  • \$\begingroup\$ @Ausername At least you have the balls to try, Good luck I hope you find one! \$\endgroup\$
    – user100752
    Jun 19, 2021 at 9:57
  • \$\begingroup\$ @Ausername I have made the input formats more liberal, so feel free to try again! \$\endgroup\$
    – user100690
    Jun 20, 2021 at 12:23

1 Answer 1

5
\$\begingroup\$

Charcoal, 45 bytes

FLθ«↑⊖§θι§ηι↙↓⊖§θι↗»J⊖Σ…η⊕ζ±§θζ↗oooW∧⊖ⅉ¬℅KK↘o

Try it online! Takes as input an array of heights, an array of widths, and a 0-indexed building. Explanation:

FLθ«

Loop over each building.

↑⊖§θι

Draw the left wall.

§ηι↙

Draw the roof.

↓⊖§θι↗

Draw the right wall.

»J⊖Σ…η⊕ζ±§θζ

Jump to the corner of the building.

↗ooo

Print the leap.

W∧⊖ⅉ¬℅KK

Repeat until the ground or a roof is reached.

↘o

Print the fall.

\$\endgroup\$
1
  • \$\begingroup\$ Great work! I love how it still works even in "impossible" cases. \$\endgroup\$
    – user100690
    Jun 19, 2021 at 13:44

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.