From 365bacec2e71e687ac3418f76cd87ee9809d139d Mon Sep 17 00:00:00 2001 From: Marco Biedermann <5244986+marcobiedermann@users.noreply.github.com> Date: Mon, 23 Jan 2023 09:37:47 +0100 Subject: [PATCH] feat: "Ball Upwards" Add "Ball Upwards" kata --- kata/6 kyu/ball-upwards/index.test.ts | 12 +++++++++++ kata/6 kyu/ball-upwards/index.ts | 8 ++++++++ kata/6 kyu/ball-upwards/readme.md | 29 +++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 kata/6 kyu/ball-upwards/index.test.ts create mode 100644 kata/6 kyu/ball-upwards/index.ts create mode 100644 kata/6 kyu/ball-upwards/readme.md diff --git a/kata/6 kyu/ball-upwards/index.test.ts b/kata/6 kyu/ball-upwards/index.test.ts new file mode 100644 index 00000000..76d7a9cc --- /dev/null +++ b/kata/6 kyu/ball-upwards/index.test.ts @@ -0,0 +1,12 @@ +import maxBall from '.'; + +describe('maxBall', () => { + it('should return the time of the maximum height', () => { + expect.assertions(4); + + expect(maxBall(37)).toBe(10); + expect(maxBall(45)).toBe(13); + expect(maxBall(99)).toBe(28); + expect(maxBall(85)).toBe(24); + }); +}); diff --git a/kata/6 kyu/ball-upwards/index.ts b/kata/6 kyu/ball-upwards/index.ts new file mode 100644 index 00000000..be52d689 --- /dev/null +++ b/kata/6 kyu/ball-upwards/index.ts @@ -0,0 +1,8 @@ +function maxBall(v0: number): number { + const g = 9.81; + const kmh = 3600 / 1000; + + return Math.round((10 * v0) / kmh / g); +} + +export default maxBall; diff --git a/kata/6 kyu/ball-upwards/readme.md b/kata/6 kyu/ball-upwards/readme.md new file mode 100644 index 00000000..3b19a834 --- /dev/null +++ b/kata/6 kyu/ball-upwards/readme.md @@ -0,0 +1,29 @@ +# [Ball Upwards](https://www.codewars.com/kata/566be96bb3174e155300001b) + +You throw a ball vertically upwards with an initial speed `v (in km per hour)`. The height `h` of the ball at each time `t` +is given by `h = v*t - 0.5*g*t*t` where `g` is Earth's gravity `(g ~ 9.81 m/s**2)`. A device is recording at every **tenth of second** the height of the ball. +For example with `v = 15 km/h` the device gets something of the following form: +`(0, 0.0), (1, 0.367...), (2, 0.637...), (3, 0.808...), (4, 0.881..) ...` +where the first number is the time in tenth of second and the second number the height in meter. + +#### Task + +Write a function `max_ball` with parameter `v (in km per hour)` that returns the `time in tenth of second` +of the maximum height recorded by the device. + +#### Examples: + +`max_ball(15) should return 4` + +`max_ball(25) should return 7` + +#### Notes + +- Remember to convert the velocity from km/h to m/s or from m/s in km/h when necessary. +- The maximum height recorded by the device is not necessarily the maximum height reached by the ball. + +--- + +## Tags + +- Fundamentals