Given an ascii-art road and the time it took me to cross it, tell me if I was speeding.
Distance is in the arbitrary unit of
d. Time is in the arbitrary unit of
Here is a simple road:
10 means 10
t. That is the speed limit for the road. The road has 5
=s, so its
d is 5. Therefore, if I cross that road in 0.5
t, I went 10
t, because 5/0.5 = 10. The speed limit of that road is 10, so I stayed within the speed limit.
But if I cross that road in 0.25
t, I went 20
t, because 5/0.25 = 20. The speed limit of that road is 10, so I went 10 over the speed limit.
Examples and calculations
Note that input 1 is the time I took to travel the road, and input 2 is the road itself.
Here is a complex road:
Input 1: 1.5 Input 2: 5=====10=====
The fastest I could have (legally) gone on the first road (the first 5
=s) is 5
t. Since 5 (distance) divided by 5 (speed limit) is 1, the fastest I could have gone on that road is 1
On the next road, the speed limit is 10 and the distance is also 5, the fastest I could cross that is 0.5 (5/10). Totaling the minimum times results in 1.5, meaning I went at exactly the speed limit.
Note: I know, I might have been going really fast on one road and really slow on another and still cross in 1.5, but assume the best here.
A final example:
Input 1: 3.2 Input 2: 3.0==========20===
The first road is 10 long and has a speed limit of 3, so the minimum time is 3.33333... (10 / 3.)
The second road is 3 long and has a speed limit of 20, so the minimum time is 0.15 (3 / 20.)
Totaling the times results in 3.483333333... I crossed it in 3.2, so I had to be speeding somewhere.
- You must output one distinct value if I am undoubtedly speeding, and another different value if I might not be.
- Your program or function may require input or output to have a trailing newline, but please say so in your submission.
- Your first input will be my speed. It will be a positive float or integer or string.
- Your second input will be the road. It will always match the regex
^(([1-9]+[0-9]*|[0-9]+\.[0-9]+)=+)+\n?$. You may test out potential inputs here if you are interested.
- You may take input in 2 parameters of a function or program, in 2 separate files, from STDIN twice, or from a space-separated string passed to STDIN, a function, a file or a command-line parameter.
- If you would like to, you can change the order of the inputs.
- Any questions? Ask below in comments and happy code-golfing!