8 kyu
Will you make it?
49,815 of 152,687user2514386
Loading description...
Mathematics
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.
This comment has been hidden.
This comment has been hidden.
Why are you changing distanceToPump? Why are you multiplying mpg by 2?
Really good for practicing what I learned in my computer science classes.
Cai no conto. O google translate traduziu a pergunta e em uma parte mostrou milha, e em outra parte kilometro, logo fiz o tratamento de conversão e acabou por não funcionar
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting
Your function isn't returning anything. And also, it's not ok, but I'll let you figure it out why.
Thanks
Why does it give me an error?
def zero_fuel(distance_to_pump, mpg, fuel_left): return distance_to_pump / mpg == fuel_left
What will your solution return when you are 1 mile away from a pump, you have 2 gallons of fuel left, and your car can travel 100 miles on one gallon?
The no. of miles that the car runs before running out of fuel doesn't need to be exactly equaly to the distance to pump, so also include the cases in which the car has more fuel or gives higher milage.
Haskell translation
Approved by Johan
A nice little logic test, a good 8th Kyu.
hey guys am new here and i like the katas...what does it mean when it outputs expected false to equal true
it should return true not false. your is 'false' which wrong you need to return 'true'. use >= not *
def zero_fuel(distance_to_pump, mpg, fuel_left): a = distance_to_pump - (fuel_left * mpg) if a <= 0: return True else: return False
Please don't post solutions in Discourse section, there's Solutions tab for that.
Хуже условия я и представить не мог...
testing a little maths as well as coding :) cool!
Lua translation!
Approved
Si eres hispanohablante, ten en cuenta que si lo traduces de ingles a español, la descripcion te hara una mala jugada, confundiendote con kilometro y millas, pero realmente solo se manejan millas, no tienes que hacer conversion de millas a kilometros, solo tienes que calcular la autonomia del vehiculo
english speakers this is what he means: If you are a Spanish speaker, keep in mind that if you translate it from English to Spanish, the description will make you a bad move, confusing you with kilometer and miles, but really only miles are driven, you don't have to convert miles to kilometers, you just have to calculate the autonomy of the vehicle
Metrically challenged
In C++ at least, this kata's third test has rounding error flaws. One of my operations was having issues until I changed the logic slightly from a division to a multiplication.
Can you show the solution which you tried but could not pass due to rounding errors? It's highly unlikely that rounding affects this kata, I suspect your solution was not exactly correct.
This comment has been hidden.
So it means you used integer division instead of real division?
This comment has been hidden.
I am not sure i understand. do you mean that a test with distance=2 miles and mpg=4 is wrong? Both inputs are valid ints, but integer division will give incorrect intermediate result of 0. Do you mean such test case is ill-formed?
By this logic, if you have 0 fuel in your tank, and want to travel 2 miles in a car which consumes 4 mpg, the expected answer should be
true
?If you have enough to travel 2.5 miles, and need to travel 2.4, it should be true since 2.5 > 2.4, but since we're dealing with uints and the test cases are as well, the range is rounded to 2, making it be false (2 < 2.4). At least that's what I think is happening with the third test.
this cannot be considered a kata issue. You have to understand the operators and datatypes that you use when you apply them to real-world formulas. with integer division,
(3 * 4) / 12 != 3 * (4 / 12)
; the tests are correctThis comment has been hidden.
No need to add any variable
i mean, why would you make a total fuel?
这样写有什么问题吗?
This comment has been hidden.
Kata hint != kata suggestion.
Funny kata. Solution made me happy. Ask yourself "what if" more
I do had the same thought that you writte on this comment.
That helped ?
I spent 15 minutes reading my code wondering why it was wrong.. READ THE INSTRUCTIONS CAREFULLY!
that was easy!
Not a kata issue.
Cries in Kph Cries in Metric Units
There's an STDERR when I attempt the code
/tmp/main-79f62b.o: In function
zero_fuel_function::should_pass_random_tests()': main.cpp:(.text._ZN18zero_fuel_function24should_pass_random_testsEv[_ZN18zero_fuel_function24should_pass_random_testsEv]+0xa8): undefined reference to
zero_fuel(unsigned int, unsigned int, unsigned int)' clang: error: linker command failed with exit code 1 (use -v to see invocation)That's caused by your code, use the initial code:
Why did you change
uint32_t
forint
? Not a kata issue.Right! Very sorry, I must've forgotten.
This comment has been hidden.
Hello! It doesn't work if write "select *, new column from table" because of table includes column Id. But in the description wrote that you need to take all the columns from the table. Please correct the desc for kata. Task is good :) Thanks
There's two preset test values for testing the program, then it uses random numbers, as I understood. When i attempt my program, it says that 3 / 4 of these preset test values are returning expected answers, so that's good, except that there's only two... All the random numbers worked, there's only this ghost test value that went wrong. I can't even turn a question right for this situation, can someone help me?
Sample tests are one thing and Attempt tests is another. Print the input: https://docs.codewars.com/training/troubleshooting#print-input
There's an evolution : when I tried this morning after sleep, it only shown me 2 Sample cases. But when I attempt it, it's still four. One is still wrong, and I still can't know which one is wrong. There's a problem tho, the progam should run correctly, it's just a basic multiplication, and turns out it's not correct, I'm stuck
See the first sample test:
Your code returns
False
, fix it.carefully study the conditions of the assignment, correct solution is inside. correct comparison sign required
Guys, please, many times, carefully read the problem until you find a very simple solution, good luck!
When I press "test" - it lights up green. When I press "attempt" - it lights up red. I analyzed the table in attempt and realized that there, for example, 2.8 = 2, although in fact 2.8 > 2. In this case you can not use division (/), it gives a decimal fraction in some cases and equates to a whole number without the remainder, which fundamentally changes the value.
Why? expected 'true' to equal true
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
The name of this function does not say what it does. A better name would be
sufficent_fuel
Go translation
am passing the test but am getting err when I attempt it I don't know why
I have the same problem buddy! Any ideas on how to solve it?
Read this: https://docs.codewars.com/training/troubleshooting/
Thanks, but it didn't help to solve the issue.
Your code returns true if you have only the exact (not the exact really but close) amount of fuel to reach the station. That's not what is asked here. You could reach the station and yet have your tank half full for example.
I Just did this for the mental boost. (kata title)
20 minutes to understand the Instructions.... 1 minute to Solve it 🌚
I'm in the same as you lol
All the way around
Details refactored (author has deleted their account.)
SQL translation
This comment has been hidden.
Approved!
For the Rust translation a test case could be added:
assert_eq!(zero_fuel(4000000000, 100, 400000000), true);
The function arguments are 32-bit unsigned integers. If only a simple u32 multiplication is used, then an overflow could occur and crash the program. It is u32::MAX = 4294967295.
(Possible integer overflow is a hurdle in some languages, but not in all.)
This is a beginner kata, and this suggestion would invalidate most of submitted solutions. Let's hope the fuel will never reach such a price...
Good Kata!!..
How write (1 in Prolog and NASM)? i don't understand!
Some languages don't have boolean, so the solution is return
1
fortrue
and0
forfalse
. If you don't know how to do it for some language search for its documentation.Maybe the prompt shouldn't express the arguments as if they are set to specific (constant) values.
Unclear suggestion
The prompt reads as if all you want to return is whether the car can make it to its destination that is set as 50 miles and you are given the fuel efficiency which is set at 25 mpg as well as the set amount of gas that is iin the car, 2 gallons. Since the car will make it, your code could be ---> return true; and you are done. That would not be what is expected, though. I am sure a lot of people read the descriptions before selecting a kata to train on and some of the kata are exactly that easy. It's not a huge suggestion but to put it in exaggerated terms it is bait-and-switch. Clickbait. I'm sure we will all survive just fine as it is but the suggestion is proposed in order to put the best foot forward.
I say this because I think this is a great kata for this bracket and it could be even better.
to understand this problem much more hard than solving it :)
lol I was about to write this 😂
NASM translation amended with prototype (see issue below) and minor update in the description.
Approved by Monadius
Can someone please add the prototype with register usage for the NASM initial setup?
Hi. distance is xmm0, mpg is xmm1 and fuel_left is xmm2. I'm going to make a fork but you won't be able to see it unless you already solved the kata or someone approves it quickly (well, I guess you solved this kata yet...).
Fixed (see above).
Is it just me or does this function have a weird name? It returns true if you can make it to the next pump in time, right? But it's called zeroFuel. I'd expect it to return true if I ended up with zero fuel, not the opposite. Does that make sense?
This comment has been hidden.
It means your code returns
undefined
(if JS, probably you return nothing), while it must return a boolean.This comment has been hidden.
adding actual numbers to this was not the way to go... pretend the 50 25 and 2 are not there and you'll have a better time.... i did same thing as you
OP solved it, closing
This comment has been hidden.
Uh? No. Check your code. And read this first: https://docs.codewars.com/training/troubleshooting
Yep, single character error. I didn't know => created a function xD
what does (1 in Prolog) and (0 in Prolog) means?
R translation kumited (author long gone)
Thanks ;)
Great Problem for beginner.
that is just one great Kata for beginners.
Coffeescript && Crystal (author long gone)
Approved.
Please use new python test framework.
This comment has been hidden.
unless problem was fixed check your code for typos. I've tried both ways and they did work.
This comment has been hidden.
You need to log the parameters given to the console. Read this and note that the description is intended as an example and you should not use those values in your final answer.
Very subtle Kata!
My method passes the 2 tests, yet when I submit it fails a 3rd test. Anyone else encounter this issue?
me too
Show the code!
This comment has been hidden.
You could have more than the exact amount of fuel needed to get to the pump.
I just realized that and I came back here to say so. Well done fast reply, by the way.
Also, I just realized I should have marked that as question.... Oh well.
Very good problem description. At least it matched how my logic works and the results were as expected.
This comment has been hidden.
Please, mark your post as having spoiler content next time, after
return
none of yourconsole.log
lines will be executed, you need to write them before the return line.About your code, what if you have more than the exact needed fuel to reach the gas station with an empty tank?
Thanks a lot!
Please use markdown formatting to make your code more readable.
There is a typo in the description. "you fuel is running out" ==> "your fuel is running out"
Not an issue.
This comment has been hidden.
NASM translation
here we go!
PHP Translation
Please review this :)
Approved!
This comment has been hidden.
Approved.
This comment has been hidden.
you could do this to see what the inputs are:
Thanks a lot! Very useful!
Julia translation
Prolog Translation Kumited, please carefully review and approve :-D
Java translation
Your problem description is meh... you should use variables name instead of numbers to explain the problem.
Otherwise, interresting Kata to start with.
The description makes no sense at all. The factors are constant, thus the function should be parameterless and simply return
true
.Having a bit of an issue with this kata, all I'm getting when I run my test is a "missing language" error. My answer works in Repl, so I'm not sure what the problem could be, are there missing instructions or something?
1.did you use the right spelling 2.did you use in function => instead of >=
please use metric units for a larger audience...
Not a suggestion.
I think the suggestion is change the units to metric
I for one like freedom units. They are very liberating.
This comment has been hidden.
In this case, it won't. Since the inputs are within a limited range! Another case for large inputs tho
This comment has been hidden.
Integer division is not floating point division ;-)
This comment has been hidden.
This comment has been hidden.
Wrong data type,
"true"
is a string, not a boolean. And mark your post as having spoiler content when it does.thanks a lot Chrono79! I didnt realize there was a spoiler content flag, ill be sure to use it from now on.
This comment has been hidden.
Remove
console.log
. Not a kata issue.Thanks Sir, your help was very appreciated. I wasn't aware console.log would cause that issue. I owe you one :)
Ruby translation kumited. Please review and approve!
It's been approved.
Thanks!
miles and gallons?! shouldn't one use more sensible units like km and liters?
Remember: the U.S. is not us...
This comment has been hidden.
This comment has been hidden.
lol I'm so stupid
Given that the function returns
true
when you have enough fuel, the function namezero_fuel
is misleadingmy first thought exactly, should be called something like:
do_i_make_the_pump()
. or reverse the test casesNobody's going to change the function name after 5k+ completions.
Would probably be better if there were directions on whether to print or to return values
Issue marked as resolved.
I think the velocity of the car stated in the description is useless yet confusing for this kata. Maybe deleting it will make the description more understandable. Cheers!