6 kyu
Projectile Motion
132 of 358narayanswa30663
Loading description...
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
looks like image is broken.. ?
This comment has been deleted.
XCTAssertEqual failed: ("h(t) = -16.0t^2 + 17.880t + 51.0") is not equal to ("h(t) = -16.0t^2 + 17.88t + 51.0") - XCTAssertEqual failed: ("x(t) = 83.070t") is not equal to ("x(t) = 83.07t") -
R E A L L Y ???
Yeah, really. They're not the same.
But because there is no proper order in XCTAssertions, it could be your answer is right and the expected one is wrong, please elaborate.
Отличное ката. При внимательном прочтении условия, все становится ясным и понятным. Автору огромное спасибо!
very inaccurate description and template
python new test framework is required. updated in this fork
use meters please
There are some TypeScript test cases which are incorrect. The description very explicitly states that integer output should have a decimal point with a zero afterwards, and that all other numbers should be rounded to 3 decimal places. In some test cases, however, numbers are rounded to only 2 decimal places. It seems to be the case that when the final digit is a zero, it is omitted in the test cases. This appears to be the same issue that other users have been facing in other languages.
Examples: expected 'h(t) = -16.0t^2 + 17.880t + 51.0' to equal 'h(t) = -16.0t^2 + 17.88t + 51.0' expected 'x(t) = 33.340t' to equal 'x(t) = 33.34t'
This comment has been hidden.
Hi, I have the same problem, can't pass tests in swift: main.swift:86:18: error: type of expression is ambiguous without more context let p1 = Projectile(h: a, v0: b, a: c); Please give me a hint as to where the error might be.
can't pass tests (swift):
main.swift:86:18: error: type of expression is ambiguous without more context let p1 = Projectile(h: a, v0: b, a: c); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ wrong test? why h is a and a is c?
Hi , just a remark : as int values are expected to be printed as .0 , perhaps could you have asked for same format for y value in landing return
I'm getting lost though is the example of p = new Projectile(5, 2, 45). When I put that into my Groovy code where a = -16, b = 2, c = 45 I get q = -0.5 and q = 0.625 and the example results for this should be q = 0.605.
I don't understand where this 0.02 difference is coming from. Is there an error in my quadratic function code I'm not seeing or is this maybe something Groovy related versus how the example results were generated?
feets DansGame
Rust translation.
Already approved by someone.
I wasted a lot of time trying to figure out why I was just a bit off. The tests use gravity as 32 ft / s exactly instead of 32.2 or 32.174. Only after figuring out the problem did I notice the -16t^2 term denoted 1/2(g)(t^2), thus showing the assumption.
The tests in javascript (see Dart issue raised below) expect some numbers with two or zero decimals in random tests, in the instructions it says otherwise:
Same thing in python.
I'm doing this exercise in Groovy and trying to solve the total time the projectile is in the air, so when
h = 0
.I've implemented the quadratic equation shown here: https://www.khanacademy.org/math/algebra/quadratics/solving-quadratics-using-the-quadratic-formula/a/quadratic-formula-review into Groovy like so:
def q = (-b + Math.sqrt((Math.pow(b,2) - (4*a*c))))/(2*a)
Using the example from Khanacademy,
a = −7, b = 2, c = 9
in my Groovy code I get the expected results ofq = -1 and q = 1.2857142857142858 (9/7)
.Where I'm getting lost though is the example of
p = new Projectile(5, 2, 45)
. When I put that into my Groovy code wherea = -16, b = 2, c = 45
I getq = -0.5 and q = 0.625
and the example results for this should beq = 0.605
.I don't understand where this 0.02 difference is coming from. Is there an error in my quadratic function code I'm not seeing or is this maybe something Groovy related versus how the example results were generated?
Below is the error code for Dart test Projectile(51, 86, 12)
Expected: 'h(t) = -16.0t^2 + 17.88t + 51.0' Actual: 'h(t) = -16.0t^2 + 17.880t + 51.0' Which: is different. Expected: ... ^2 + 17.88t + 51.0 Actual: ... ^2 + 17.880t + 51.0 ^ Differ at offset 23
The description says that everything should be given to three decimal places except for integer values that should be give to one decimal place.
Javascipt (and maybe Dart)- It seems that either the tests are wrong or the example needs to be updated- should trailing 0s be included in formulas? One of the test cases I failed in Javascript:
Expected: 'x(t) = 83.07t', instead got: 'x(t) = 83.070t' Expected: 'h(t) = -16.0t^2 + 13.2t + 86.0', instead got: 'h(t) = -16.0t^2 + 13.200t + 86.0'
The instructions say: EVERYTHING, including values in the equations appearing as coefficients, must be rounded to THREE decimal places. However, if the value is whole, only show one decimal place (for example => -16 becomes -16.0, not -16.000)
Same problem for Dart: Expected: 'h(t) = -16.0t^2 + 17.88t + 51.0' Actual: 'h(t) = -16.0t^2 + 17.880t + 51.0' Which: is different. Expected: ... ^2 + 17.88t + 51.0 Actual: ... ^2 + 17.880t + 51.0 ^ Differ at offset 23
This is brilliant. A massive thankyou to the author(narayanswa30663 is it?). This is my first ever attempt at writing a class and I am delighted that this kata gives me a very gentle introduction into how to include variable and methods. This is exactly the sort of thing I was looking for. I love codewars. I am learning sooo much.
The example of how to implement the "height(t)" method is wrong
"p.height(0.2) #=> 4.643 (Calculation: -16(0.2)^2 + (2cos(45º))(0.2) + 5)"
Should be (2sin(45º))(0.2), like describe in height_eq method. we should use sin function, I guess
yes, fixed.
How are you supposed to calculate the x and t value for the final function?
I don't want to give too much away but here is one hint: all you have is the height (0 ft). Which of the two equations can you solve to get the value of one more variable? And then what can you do with that variable to find the last one?
I tried solving 16t^2 + vt + h0 = 0 but it gives me the wrong answer
the coefficient for t^2 should be -16.
Oh yeah, I tried that but it still didn't work
i'm not going to give anything more away; check again that you're using the quadratic formula correctly and also check that your values for v and h0 are correct.
In the kata description, in the example it says "1.414 = 2sin(45º)" but 2sin(45) is 1.702 so my answer for height_eq will always be wrong
2sin(45°) is not 1.701, it is 1.414. 2sin(45 radians) is 1.701, so that's where your mistake lies. 45 radians is very very different from 45 degrees.
Thers is still problem with expected formatting and its description.
"EVERYTHING, including values in the equations appearing as coefficients, must be rounded to THREE decimal places. However, if the value is whole, only show one decimal place (for example => -16 becomes -16.0, not -16.000)" implicates that there should be 3 or 1 decimal place, but I've got error:
Expected string length 31 but was 32. Strings differ at index 23. Expected: "h(t) = -16.0t^2 + 23.84t + 64.0" But was: "h(t) = -16.0t^2 + 23.840t + 64.0" ----------------------------------^
EDIT: My next attempt, with 1, 2 or 3 decimal places:
Expected string length 28 but was 30. Strings differ at index 19. Expected: "h(t) = -16.0t^2 + 0t + 161.0" But was: "h(t) = -16.0t^2 + 0.0t + 161.0" ------------------------------^
So it excpected no decimal places now.
C#, yes? Fixed now.
Yep, thanks :)
Hi, the same problem here, in Dart. Expected: "h(t) = -16.0t^2 + 17.88t + 51" my return: "h(t) = -16.0t^2 + 17.880t + 51.0" wrong
(Scala) Some random test give me a feedback say that the expected result for heightEq() would be
-16.0t^2 + 0.000t + ????
.While the description explicitly says: "NOTE: Some solutions were invalidated because I added tests for situations where the starting height is 0, in which case the equation for height would be in the form h(t) = -16.0t^2 + vt where v represents the initial vertical velocity.", shouldn't the
0
second term be omitted?Also, why the second term has three decimal points?
found the issue, will fix shortly; the starting velocity should just never be 0 as shown in the description but the range of the random number generator is (incorrectly) inclusive of 0.
everything is meant to be rounded to 3 decimal places, except integers as is said in the description.
fixed.
I really enjoyed this Kata, it made me remember some formulas I haven't used in a long time!!
Thanks :)
But the tests want
heightEq
to format h0 with ONE decimal place. Also: The TypeScript version has no sample tests.Added the following to the description: "However, if the value is whole, only show one decimal place (for example => -16 becomes -16.0, not -16.000)." Also added example cases to TS version. Please mark as resolved if it's ok!
Thanks.
Should be fixed now, please take a look.
almost good, yes: you forgot to say that the arguments of the constructor are ints. ;)
Done:)
Errrr.... WTH!?
h = -16t²+...
=> how did you end up with 16!?? That should beg/2 = 9.81/2 = 4.405
... Unless you're not on Earth but you do not tell about it... xp
9.81 is in meters and 32(.185) is in feet.
xD
These aliens and their units... XD
I bolded the description section on units :)
Why a formula with b and another with v? Aren't those 2 the same?
Yes, they are the same. I changed the formula with
b
to match the other one.Ok then.
NOTE: Some solutions were invalidated because I added tests for situations where the starting height is 0, in which case the equation for height would be in the form
h(t) = -16t^2 + bt
whereb
represents the initial vertical velocity. Sorry!Why
t
has to be rounded to 3 decimal places before calculating the x position when hitting the ground? Especially when description says this:Ah, yes, sorry about that. Changed/fixed now. Please mark as resolved if it's ok.
;-)