From aaa4573da8aac14a16dca1d1075d4c5252aef06c Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 4 Jun 2020 11:17:48 +0100 Subject: [PATCH] physics exercise js --- js/tests/physics_test.js | 15 +++++++++++++++ subjects/physics.en.md | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 js/tests/physics_test.js create mode 100644 subjects/physics.en.md diff --git a/js/tests/physics_test.js b/js/tests/physics_test.js new file mode 100644 index 00000000..2f861865 --- /dev/null +++ b/js/tests/physics_test.js @@ -0,0 +1,15 @@ +export const tests = [] +const t = (f) => tests.push(f) + +t(({ eq }) => eq(getAcceleration({}), 'impossible')) +t(({ eq }) => eq(getAcceleration({ d: 10, f: 2, Δv: 100 }), 'impossible')) +t(({ eq }) => eq(getAcceleration({ f: 10, Δv: 100 }), 'impossible')) +t(({ eq }) => eq(getAcceleration({ f: 10, m: 5 }), 2)) +t(({ eq }) => eq(getAcceleration({ f: 10, m: 5, Δv: 100, Δt: 50 }), 2)) +t(({ eq }) => eq(getAcceleration({ Δv: 100, Δt: 50 }), 2)) +t(({ eq }) => eq(getAcceleration({ f: 10, Δv: 100, Δt: 50 }), 2)) +t(({ eq }) => eq(getAcceleration({ f: 10, m: 5, Δt: 100 }), 2)) +t(({ eq }) => eq(getAcceleration({ d: 10, t: 2, Δv: 100 }), 5)) +t(({ eq }) => eq(getAcceleration({ d: 100, t: 2, f: 100 }), 50)) + +Object.freeze(tests) diff --git a/subjects/physics.en.md b/subjects/physics.en.md new file mode 100644 index 00000000..0c266168 --- /dev/null +++ b/subjects/physics.en.md @@ -0,0 +1,41 @@ +## physics + +### Instructions + +Isaac Newton has forgotten his laws of physics and needs your help to animate an object on his game. +He must use the Second Law of Motion that states, when the forces acting on an object are unbalanced, the object will accelerate. +This acceleration is dependent upon the force that act upon the object and the object's mass. + +So he wants to know for an object with : + +- mass of xx +- Δv of xx +- Δt of xx +- force of xx +- distance xx +- time xx + +whats the acceleration of that object. +Create a function called `getAcceleration` that given an object with the values of `{ f: 10, m: 5, Δv: 100, Δt: 50, t:1, d: 10 }` +it must calculate the acceleration. If its not possible to calculate it you must print `impossible` + +### Formulas + +``` +a = F/m +a = Δv/Δt +a = 2d/t^2 + +a = acceleration +F = force +Δv = final velocity - initial velocity +Δt = final time - initial time +d = distance +t = time +``` + +### Quote + +Truth is ever to be found in simplicity, and not in the multiplicity and confusion of things + +Isaac Newton