13
Bob the Bowman
o
/( )\ This is Bob.
L L Bob wants to be an archer.
#############
.
/ \ <--- bow So he bought himself a
(c -)-> <--- arrow nice longbow and is about
( )/ <--- highly focused Bob shoot at a target.
L L
#############
___________________________________________________________________________________________
sky
Bob is a smart guy. He already knows what angle and
velocity his arrow has / will have. But only YOU know
the distance to the target, so Bob doesn't know if he
will hit or miss. This is where you have to help him.
. +-+
/ \ | |
(c -)-> | |
( )/ +++
L L |
###########################################################################################
Task
Your task is to render an ASCII art picture of Bob hitting or missing the target. For the calculation:
- Your program will receive
arrow_x,angle,velocity,distanceas comma-separated input in any order you wish. - One ASCII character equals
1m. - The first character in the last line has the coordinates
(0,0), so the ground (rendered as#) is aty=0. - Bob always stands on the ground, his
yposition does not change. - There is no max
y. However, the arrows apex should fit within the rendered picture. - All input is provided as decimal integer.
- During calculation, assume the arrow is a point.
- The arrow origin is the arrow head
>of a shooting Bob (see above). So givenarrow_x, you have to calculatearrow_y. The left foot of Bob in the output has to match thexcoord. of the shooting Bob. distanceis thexcoordinate of the target's foot. (ie. the middle of the target).- All measurements are supplied in meters and degrees respectively.
- Attention: The shooting Bob is never rendered, only used for calculations! See below for the two valid output-Bobs
- Hitting the target means the arrows path crosses either one of the two leftmost target walls (
|) (That is either (distance-1,3) or (distance-1,4). If at some point the arrow is within those 2m², place the X instead of the wall it hits. The target is always the same height and only its x position can change.). Corner hits or an arrow falling from the sky onto the target does not count. - Standard earth g applies (9.81 m/s^2).
distance+1is the end of the field, after that, everything is a miss and no arrow should be rendered.- If the arrow hits the target in any other way (
distance-1etc.), no arrow should be rendered.
Miss
This is an example rendering of Bob missing (arrow enters ground at 34m, angle is 45°, time in air is 10s, velocity is ~50 - but there are a lot more possible inputs to cause this output. Just show your program uses the usual formulas to calculate physically "accurate" results.):
+-+
| |
c\ | |
/( ) v +++
L L | |
###########################################################################################
Hit
This is an example rendering of Bob scoring (arrow enters target (= crosses its path)):
+-+
>--X |
\c/ | |
( ) +++
L L |
###########################################################################################
Example
arrow_xis 7.arrow_yis always 3.angleis30°or0.523598776radians.velocityis13m/s.distanceis 20.
So in order to hit the target, the arrow has to cross (19,3) or (19,4). Everything else will be a miss. In this case, the arrow will enter the ground (means y will be <1.0) at 12.9358m = ~13m after 1.149s.
Limits & Scoring
- This is code-golf, so the shortest solution wins. There are no bonuses.
- Your program (as in not function) must accept input in the format described above, additional input is not permitted.
- You don't have to handle wrong/pointless/impossible inputs.
- Print to whatever is the shortest reasonable output for your language (std, file, ...).
- I don't care about trailing whitespace.
- Tip: Width of output is
distance+2. The height isapex+1.

5Can you add the input used to generate the output given please? – Blue – 2015-09-20T13:29:07.460
3Why can't you post a function? – Loovjo – 2015-09-20T13:52:57.407
@steveverrill Standard g applies. – mınxomaτ – 2015-09-20T15:01:34.760
Do we have to draw bob? or just the arrow? – Mhmd – 2015-09-20T17:46:38.453
2@Mhmd You have to draw him, as stated in the task.
The left foot of Bob in the output has to match the x coord. of the shooting Bob.andSee below for the two valid output-Bobs– mınxomaτ – 2015-09-20T17:56:10.6171And for those of us who haven't taken physics further than GCSE (or have just forgotten?) – Blue – 2015-09-20T19:11:45.480
2@muddyfish Just google for the trajectory equations. – mınxomaτ – 2015-09-20T19:25:47.740
Could you add more test cases input/output. – Mhmd – 2015-09-22T13:42:57.703
btw, in the exampe you say: the arrow will enter the ground (means y will be <1.0) shouldn't this be 0? – Mhmd – 2015-09-22T14:18:46.870
@Mhmd No, because the ground
#is aty=0and is 1m high. – mınxomaτ – 2015-09-22T14:50:57.363@minxomat in the example above, it seems that you didn't take into account the initial height
y0. Could you please elaborate? I'm getting a result of 18m. – Mhmd – 2015-09-26T08:39:21.263@Mhmd Yes, I messed that up, you're right. – mınxomaτ – 2015-09-26T19:29:29.850