-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathball_upwards_unit.pas
More file actions
41 lines (34 loc) · 811 Bytes
/
ball_upwards_unit.pas
File metadata and controls
41 lines (34 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{
6 kyu
Ball Upwards
https://www.codewars.com/kata/566be96bb3174e155300001b
}
unit ball_upwards_unit;
{$mode objfpc}{$H+}
interface
function MaxBall(v0: int64): int64;
implementation
function MaxBall(v0: int64): int64;
var
StartVelocityMeterPerSec: double;
HeightMeter: double;
MaxHeightMeter: double;
TimeSec: double;
TenthSecond: int64;
const
G: double = 9.81;
begin
StartVelocityMeterPerSec := v0 * 1000.0 / 3600.0;
MaxHeightMeter := 0.0;
TenthSecond := 0;
repeat
TenthSecond := TenthSecond + 1;
TimeSec := TenthSecond / 10.;
HeightMeter := StartVelocityMeterPerSec * TimeSec - 0.5 *
G * TimeSec * TimeSec;
if HeightMeter >= MaxHeightMeter then
MaxHeightMeter := HeightMeter;
until HeightMeter < MaxHeightMeter;
Result := TenthSecond - 1;
end;
end.