You are given a 2D map with balls and ground in it. It looks like this:
1 5 2
Each number is a ball, and the
_ is ground level. The underscore
_ character is not allowed in any other line than ground level line. There are only spaces, newlines and digits
0-9 allowed above ground level. You cannot assume that last line is the ground level - empty lines below ground level are allowed. You can also add spaces, to fill empty lines, if that does help you.
Balls can have numbers from
9, can be placed above each other, but not under ground. The ball's numbers will be unique.
Assume that each character is one meter.
Your challenge is to read a map like that from a file or from
stdin — you are allowed to use
cat balls.txt | ./yourexecutable — and output velocity of each ball when it hits the ground.
h is the line number difference between the ground's line number, and the ball's line number, and that
You should output each balls number and velocity in
m/s at ground level.
N - Vm/s, where
N is ball number and
V is its velocity.
You can also output an array if you want.
Happy coding! :)