6 kyu
Tank Truck
1,286 of 4,965g964
Loading description...
Mathematics
Geometry
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.
This comment has been hidden.
only this may not help
python new test framework is required. updated in this fork
Approved
Hello Sorry for my English, I'm writing through a translator. the solution algorithm seems to have understood, hopefully correctly. Find the area of the base of the cylinder -> find the area of the triangle AOB -> the area of the large triangle - AOB*2 -> subtract the area of the large triangle from the area of the circle and get the area of the segment with water -> the area of the volume is equal - multiply the area of the segment with water by the length of the cylinder (we find from the volume of the cylinder and the area of the base) - the answer is far from the result in the example. I have been working on this task for the second day. I can't understand, do I have the wrong algorithm or calculations?
e
suggested tag:
geometry
Good point.
proper assertion messages for C
Merged.
I was struggling cuz I named my function tankvol lol. That one hyphen wasted so much time it isnt even funny.
I love @g964 katas 🥰
Thanks!
I consider solving this kata a personal achievement. It took me a day and a half. Fun as hell, though. I wish I paid more attention in school.
Had so much fun with this kata, nice one.
Added an NASM translation: https://www.codewars.com/kumite/6295098d910756001770db76?sel=6295098d910756001770db76
In my solution I handle when h less than radius and h more than radius, but I don't handle when h=radius and still pass all the tests.. I mean I think the kata author might wanr to add testcases, maybe
Your "else" part manages the case!...
Great kata! :)
Thanks!
Made me remember university days. Great kata.
Thanks!
Hey, I need some help with the powershell version of this.
I ran the tests on my function and it passes the tests, but when I click attempt I get the error below.I thought maybe it was an issue with how I truncated the return. But other than [math]::Truncate I just get seemingly an oppostite error like "Expected: {2940} But was: {2941}"
Can someone take a look and give me a heads up if I caculated something wrong?
Avoid this kind of operations:
a/b/c
when possible.I appreciate the response, but just to be clear...youre saying do not use the "/" in repition? Or Dont use the "/" to divide?
Great Kata!!!
Thanks!
This comment has been hidden.
Thanks for your post. I copy below kazk's answer to my post (kazk is the CW admin):
Cheers!
@g964: that was the answer to another question. ;)
Oh! Sorry! It was in the continuation of the previous post but I must say that I didn't understand well kazk's post:-(
Diameter is defined as the supremum of distances over pairs of points of a set. So for a cylinder it's the distance between a point on the edge of one base and the farthest point on the other base. You probably had the diameter of the cylider's base in mind.
Modified by "the diameter of the cylinder base..." though there was no problem for 3216 people:-)
Works for me, thanks very much.
Btw, the popular wisdom is that only 1 in 10000 people who encounter a given problem complain. Though that's with paying users of companies' products and here you're doing it for free and we're using for free.
:-)
ByteEater: I'm curious about where did you get that definition about the diameter of a cylinder. A cylinder is well defined given a radius or a diameter (they're implicitly referred to the base or a cut parallel to it) and a height.
Diameter a general notion in metric spaces. Although I concede that making cylinders an exception with a different definition giving smaller values may be popular in some presentations of spatial geometry in English. I wouldn't support it, however. It's easy to say "diameter of the base" for the other notion, but if you call that diameter, then it poses more difficulty to accurately capture the diameter in the metric sense.
This comment has been hidden.
No that's perfectly correct!!
was it bad to use calculus for this question :|?
no
I really liked this Kata! Had to freshen up my math theory a bit. But it was well worth it. :)
Thanks!
Is "vt" necessary?
Yes, since you don't have the length of the tank.
Oh,fact. Thanks!
Thanks for this kata!
Thanks!
do i need caulculus for this kata? i just can seem to find a way to solve this without integration, AM I DUMB????
Yes, it can be solved without integration.But if integration helps and works for you, then why not use it? No, you are not dumb.
This comment has been hidden.
This formula is valid only when cylinder stands on its round base. When you put the cylinder on its side, height changes, and the formula does not apply anymore.
Height here is the height of the liquid in the Tank. The formula you are using is when the Cylinder is standing, here the cylinder is not standing nor does "h" represent height of the cyclinder. In this case the height (now as the cylinder is horizontal) will be the same as the lateral length.
can some tell me why my code gives very differnt output when the diameter is odd number ? (i did divide d by 2 and make it double but still doesnt work )
Use Double instead of Int
This comment has been hidden.
The expected value for this case is
3848
in Python, Go, and probably all the other languages too.@chrisstoneking: your function returns 3847. You have wrongly read the test output.
OK, managed to solve it. But I don't think it's a good idea to expect an integer when the calculations involve floating-points. It would be better to expect a floating-point and compare with a reasonable error margin, as @JohanWiltink suggested. I see from other people's comments that they have had similar issues.
It's a pity, since non-trivial math problems are good subjects for katas. But I have given this kata a "Somewhat" rating because of the floating-point inaccuracy.
In general one can follow you but do you think that the driver cares for decimal values when he has to deliver somebody? It would be non-sense to give decimal values since all given dimensions are approximative. The kata would need to be completed by a rigourous calculus of error and the result given in some interval of float numbers.
If I do the test without trunc for the input as shown in the details I get exactly the same result as shown for every decimal place but when I do the real test with truncated numbers, sometimes I got everything right except one which is off by 2 or I get every test off by aroud 2. I am pretty sure my math is correct (otherwise I doubt I would randomly get every decimal place right) but I can't pass the test for some reason. Any help?
Instead of 3.14 take Math.PI...
well, tied it before and didn't work now it works :D thanks anyways.
This comment has been hidden.
Illustration is gone
I can see that, seems your local issue.
Check your browser console for error messages. I'm using Chrome and seeing a warning that the image request is insecure - maybe your browser completely rejects these.
Ah, it's imgur. It's banned in my country, okay.
Fun kata :)
Thanks!
can anyone tell me what formula to look up to solve this lol i am terrible at math
This comment has been hidden.
.
This comment has been hidden.
Very sorry for the inconvenience. Hopefully fixed. Could you give it a try? Thanks for your post!
No worries mate, i found my way around it ;) The problem doesnt seem to appear anymore. Thanks
how did u fix it man? it's a nightmare I'm always 1 off 😂
I did not learn anything about programming language from this kata. It was more like a middle school math revision.
I enjoy it!!
Forth: Shouldn't
M-PI
be given as a constant in initial code? That's the convention in every other Forth kata.I could give it but Forth has a PI constant: it is for this reason that this time I didn't give it
PI f. 3.14159265358979 ok
.To please you I added it:-)
Really good math problem, I very much enjoyed solving it :)
I had a mathematically correct solution that failed one fixed test because of floating point representation inaccuracy.
I know it's much too late for this kata, but please, kata authors, do not test floating point values for equality, do not round, truncate or otherwise assimilate them, please please please, compare with an error margin.
Actually, never mind. I have made a mistake
This reply would seem to be placed wrong ..
This comment has been hidden.
That's a question, not an issue. Nothing is fixed, and you have everything you need to calculate the result.
How is a tank length not fixed? Its a horizontal tanker truck of certain diameter and a certain length (not listed why?) Is this to allow the function to take different total volume(vt) values other than the listed 3500 units(not listed). Its an issue with the question. Tanks, especialy tanker trucks are Fixed length and volume. I'm makign the assumption of using the area of a segment circle x the length = volume
Chris, you're wrong, he's right. Read the description carefully; you have everything you need to calculate the result. Really.
This comment has been hidden.
On what do you base your opinion?
And wouldn't it be fairer to skip kata you don't want to solve, instead of downvoting them?
I fully agree it's not challenging programmatically. That is completely obvious from the description though; no false advertising here. The challenge is working it out for yourself ( though I see with some amazement people actually just Googled it ).
To put it bluntly, who died and made you God?
Ahahaha had a great laugh. I didn't know only gods can downvote. My reasoning is in my previous message. This kata is about translating a geometrical problem to code. Nothing challeging besides finding the proper formula. And you agree with me. So my suggestion is to give the formula or a link from the description. Thank you for the laugh :-)
float/double/int? The rounding error is killing me! :( always getting one-off!
Great kata! Use of slightly complex math and different data types makes you think!
Go translation needs update. Gives "Caution: This kata does not currently have any known supported versions for Go. It may not be completable due to dependencies on out-dated libraries/language versions."
I republished it.
Fortran 95 - Something is very odd. I couldn't re-create the answers I got with my submitted solution. I finally noticed that the supplied value of Pi was missing the 1st decimal place digit of "1" (so Pi = 3.4xxxxx)! This is true of all the submitted solutions (and remember how
"1_ikind" had become "_ikind"
- Pi is the same type).Really weird! I completed my bug report https://github.com/Codewars/codewars.com/issues/1436. Thanks for your post.
This comment has been hidden.
Those examples don't make any sense:
"tankvol(40,120,3500) should return 1021"
how the total volume can be 3500 when the diameter is 120? Thea area of the circle alone is PI*(60^2) which is about 11304, way above the total volume. Can somebody explain what did I get wrong?
When you ask for an answer post a question, not an issue.
Apologies, especially that my question was stupid to begin with... Thanks for this fun kata!
This comment has been hidden.
You can't compare area with volumen in this way.
area == PIx(r^2)
volume== PIx(r^2)x(width)
The values are consistent with a very short tank.
For some reason, I can't get it to output the exact needed value -- its always some other value in range of ~20 from the needed one. To be quite honest, I'm at a loss here.
Maybe there are flaws in your code.
Well, yes. There obviously are some, I do realize that much. The thing is, I can't quite pinpoint the exact flaw causing it, so I thought someone could point me in a right direction.
Try to not round in the begining.
Hey, I have runned tests for the examples in the instructions and it's all right, but when I attempt, it expects totally different values?!?!?!
why I can't solve this kata on golang??! sadly(
I don't know how and why that happened but the Go translation has disappeared! Six guys passed it and now it has gone!!!
hope it will be repaired soon…
i had an value difference that actually made this longer than it should have been by using 3.14159265358979323846264 as pi, but passed all tests when changed to only 3.14159
For me it worked with Pi 3.1415926535897932384626 xD
Do I need to return the remaining air in the tank, or the liquid? Also, is the tank standing upright?
no, the tank is lying horizontally and you have to caculate the liquid
.
This comment has been hidden.
There should be no rounding issue.
try changing arond the value of pi to be within 5 decimal digits?
There are rounding issues.
This comment has been hidden.
Well, I guess you get something wrong in the formula. I suggest looking up a simpler formula to calculate the area of the "slice".
The C++ version is non-idiomatic. If you want to write a function in C++, write a function.
Oh! You are there! I thought you were lost...
Do you want that I write the function inside the class? I think the two methods are right, no? I wanted to have kind of separation as you have between
.h file
and.cpp file
but I can have been wrong.Anyway, I saw many C++ katas written in that manner. You are obsessed by "idiomatism":-)
Is that an issue? Unfortunately I can't see anymore in which case one puts issues.
I would be very happy if you could fork the C++ translation in your usual way. So in the future I will be able to follow your model.
Argh!
For ****s sake! No! There is no need for a class. You don't have any invariants, you don't have data encapsulation, you don't even have a frigging object to begin with. This is simply bad-practise. I don't care how many other katas are written in this style, but it's bullshit.
Look, your kata description even says that the user should only write a function:
Why even provide a class? A function should only be a member of a class if it needs access to the members.
A proper variant would be
No class. No unnecessary weight. Am I unreasonably angry? Yes. Am I harsh? Yes? Do I actually have a point that the "you have to write a function inside a class, although you don't even have an invariant, members or anything else and we're ignoring that C++ is a multi paradigm language" stuff in other katas is ridiculous? Probably.
This kind of nonsense practice is what made me leave Codewars in the first place. Seeing it after just 10 minutes makes me leave again. Users are using this site to learn a language, they learn subpar techniques, and then we're (teachers, instructors, colleagues) are stuck with their questions. It is just not fair to them.
However, don't take this personal. I get that it's really convenient to just the C# version with some changes. But that's the same as using a CS->JS converter. It works, but the resulting code will be faaaaaaar away from what you would call best practice.
I get your point. Here at CW one must manage most of the time C++ as C. I have done with a class the same as in the C# or Java translations and the same I saw other C++ katas and I am now very sorry for that. However I don't change since 32 guys passed the kata (which is no more in Beta) and - as usual - I don't want to invalidate their solutions. If I write later other C++ translations I will go as you say if I don't need members or else. For the issue keep it or remove it... Apart from that I hope you are going well.
Not quite. One should write the C++ variant in an appropriate manner. Is the kata about a class that needs specific methods? Write a class. Is the kata about a function that should return some values? Write a function. Is the kata about template meta programming? Write a PhD thesis.
Yeah, hope the same holds for you and the other folks.
As always thank you for your good advice! I don't see anything about C++ in your codex:-(
Well, here's the problem:
There's no documentation for the C++ testing framework.
One last question: what about several related functions? Class or no class?
Is there an invariant? E.g. do they all need to re-use the same (encapsulated) data? If so, maybe. If not, either use a namespace or place them at global level.
However, asking for functions is usually more user friendly. If they want to use a class internally, they do so:
Of course, this is an anti-example, but it shows that if you just ask for functions, it can give more freedom to the user if you keep the interface simple. Another user could now provide the following solution:
Both solutions will work. However, the simple interface
gives the user the freedom to implement it however they want.
TL;DR: Keep the interface of the user-facing code as simple as possible.
Lots of thanks! If you had time(!) it would be good to put that in your codex so that anybody could take advantage of it.
Feel free to add an issue if something is missing.
This comment has been hidden.
I guess you get something wrong in the formula. I suggest looking up a simpler formula to calculate the area of the "slice".
acos
is needed, but you need to use it correctly.Cheers
This comment has been hidden.
Hi! i have problems with round the final number... it passes the tests, but when i submit - i always get near 5% of errors, the number is wrong with 1 point. I tried all ways to round i know in JS but always the same.
Description says:
Hope that helps.
not a suggestion
Ok, but might be wrong here. But, if we are talking anout volume, aint cylinder length not a factor. I've managed to factorise a number of variables in the formula to the 3 we are allowed. But when it comes to finally calulating the volume, we would need the length of the cyclinder.
Since volume of a cylinder is = pi * r^2 * cylinder_length.
Please advise.
There's more than one way to solve this problem, and in only some of them is the length required.
However given that, you could just make the length the subject of the equation you have provided using simple algebraic manipulation; so if you need the length, it is there for you, you just need to work a little to get it. ;)
One significant problem I encountered was the terminology:
"The height of the remaining liquid is h, ..."
I was given the impression that this meant that h represented the height of the liquid that remained in the tank as opposed to the height of the empty space. I only discovered why i was having trouble with this Kata when I looked at the examples- as h increased, so did the remaining volume, contrary to my expectations. I would recommend changing the wordng to reflect this:
"The height of the empty space in the cylinder is h, ..."
It is clearly said:
See also the drawing and examples.
The terminology "The height of the remaining liquid," as I read it, implies that h represents the magnitude of the distance from the bottom of the tank to the surface of the liquid in the tank, as is illustrated in the image. However, the numerical quantity passed to the function represented by h is actually the magnitude of the distance from the surface of the liquid in the tank to the top of the tank, reflected by the examples (as h increases, so too does the calculated empty volume in the tank). Given that "remaining volume" refers to the empty space in the tank that we are to calculate, I don't see how "The height of the reamining liquid" is supposed to indicate the height of that space.
The height of the remaining liquid is h. You must calculate the remaining volume of the liquid corresponding to the remaining height.
Oh, I see- when you say "remaining volume", you're referring to the volume of the liquid that remains, not the volume of the space that remains. In which case, I highly recommend wording it as "the volume of the remaining liquid", since that's consistent.
Yes, I would perhaps change it but the driver, when he delivers liquid, he is more interested in the liquid than in the air:-)
I think you need to change this. This was tripping me up too. I honestly don't have much insight into how hypothetical truck drivers feel about their cargo, fuel tanks, or whatever this cylinder is. The wording needs to speficy that the problem is asking for the volume of liquid in the tank. I also interpreted "the remaining volume" to mean "the empty space."
Changed.
The description is missing some words.
Fortunately you passed the kata:-) I corrected some misplaced backticks. Hopefully everything is right now in the description. Thanks for your point.
I've bolded what I think are the missing words below and added a clarification in italic for a portion of the text that was confusing to me.
To introduce the problem, think to my neighbor who drives a tanker truck. The level indicator is down and he is worried because he does not know if he will be able to make deliveries. We put the truck on horizontal ground and measured the height of the liquid in the tank. Fortunately the tank is a perfect cylinder and the vertical walls on each end are flat.
Corrected (last time?-), thanks again!
Much better. :) Marked as ready.
This is a math problem, the kata tags should be updated to reflect this.
Updated (very often computing requires maths and less often maths requires computing:-)
This comment has been hidden.
JS too? Please, see below.
JS too. The point is that my Javascript, Python and Haskell solutions are basically the same (and, IMHO, quite straightforward, so I suppose there will be more similar solutions in the future) and they fail on this test but the test was random and this case happens rarely so in the end they all passed.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Resolved.