8 kyu
Calculate BMI
1,194 of 153,277wichu
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.
this is the first kata i did on my own. It's pretty easy as the answer is literally in the question but ahhh
This comment has been hidden.
For weight = 50 and height = 1.80: expected undefined to equal 'Underweight'. This error keeps happening while everything i have written is working well. Cause I tested in the browser console.
See if this paragraph helps.
Good one !
Added Lua translation!
Could anyone assist me? I keep getting this error message: tests/Fixture.cs(11,43): error CS0117: 'Kata' does not contain a definition for 'Bmi' tests/Fixture.cs(12,38): error CS0117: 'Kata' does not contain a definition for 'Bmi' tests/Fixture.cs(13,42): error CS0117: 'Kata' does not contain a definition for 'Bmi' tests/Fixture.cs(14,37): error CS0117: 'Kata' does not contain a definition for 'Bmi'
it looks you've renamed the function definition itself from 'bmi' to 'Bmi'. Make the "B" lowercase and it will likely be resolved.
Missing edge cases below:
for
COBOL
CS
Crystal
F#
Julia
NASM
R
Ruby
Rust
Scala
Swift
Added in Crystal and Ruby.
This comment has been hidden.
This comment has been hidden.
Spoiler, I wasn't using the correct operator to work out the BMI. D'Oh!
This comment has been hidden.
You are over-writing the given
height
andweight
arguments by prompting the user to enter values. This is not required in Codewars. Read this for more info on how to train katas on CodewarsHaskell: Missing tests for edgecases: https://www.codewars.com/kata/reviews/57a429f25c00236a090000c2/groups/6672a76dfeeb8c93328a99b8
Actually all languages are missing such edge case, could you provide a few examples of such cases to be added ?
I added edge cases to Java, JavaScript, TypeScript, Ruby, Crystal, Python, C, C++, C#, PHP, and Haskell.
This comment has been hidden.
one should not post solutions to the regular discourse. there is a solutions page meant for this
This comment has been hidden.
This comment has been hidden.
There's already solutions tab for this.
This comment has been hidden.
normal
Man wrote half of a function in the description
Is it error?? height* height is not working..
Please don't raise issues so lightly, if you don't know, it's not an issue. We don't know what you are refering to, which language you are using, etc. See there: https://docs.codewars.com/training/troubleshooting
Thanks for getiing back to me so quickly! I am using Javascript, and I am trying to calculate the square of the height. I tried "height*height",but that did't work. However, using "height**2" does work. Do you know why that is?
height*height
does calculate the square ofheight
in JS (assuming thatheight
is a number), so the problem must be elsewhere.got the same error in C++. description could be updated to w / h / h since that is the only formula that works .
No, you're wrong, you can see my solution works with a different formula.
This comment has been hidden.
This comment has been hidden.
You have some conditions wrong there, compare your code with the description again.
Very interesting kata! I like it<3
This comment has been hidden.
same lmfao
This comment has been hidden.
I feel you my guy, its just to strict
This comment has been hidden.
What's the difference between w/(h*h) vs w/h/h in Cpp?
The description does the kata for you.
It says "testing blah amd blah" instead of "testing blah and blah" when showing results for your attempt.
I wouldn't use
Issue
for a typo, but... fixed. Remember to mention which language you're talking about next time, please.What measurement is the height supposed to be in???
It doesn't matter, but it's meters. And the weight is in kilograms.
i pass the test but fail when i attempt?? why?
Please see: https://docs.codewars.com/training/training-example#debugging-a-kata
Your bmi is calculated wrongly, please check again.
Not a kata issue.
This comment has been hidden.
Language: C++
Test suit missing the required header
std::string
fixed
my test passes, my attempt fails. Is that normal?
You have a global var called bmi, that's the same name of the function.
test are not working for c++
Your code is not right. Read the description again. What happens if bmi is 29.5?
This kata kinda perpetuates a somewhat incorrect belief that BMI alone is a valid measure of ones health in relation to their body mass. BMI was developed to identify malnourished elders, originally. I would suggest at least rewording it. Not feeling very strong about it but it seems like a decent thing to do.
Sorry but what is it that you would reword? It's a scale and those are the values it has, there isn't much to rewrite or reword there, isn't it?
shut up
People like you are so tiresome.
OP did not provide a re-wording statement, closing
int e = height*height doesn't work!
This comment has been hidden.
Mark your post as having spoiler content next time, please.
Check the values in the description again, you have one wrong there.
Oh yes sorry about that. ... All right I'll take a closer look next time, thank you...
This comment has been hidden.
It's because in typescript, all code paths must have a return value that matches the expected return type. In your original example, what if all of your
if
conditions are false? If that happens, there is no return value, so it returnsundefined
, butundefined
is not a string, so it can't compile. Logically, we know that that can't really happen, because all possible values ofbmiCalc
are covered by all of yourif
conditions, but the compiler isn't that smart. The compiler only sees that there are a bunch ofif
conditions, and there is no return value specified if allif
conditions are false. Alternatively, you can fix this by putting something likereturn "blah"
after your lastif
block.super interesting and helpful, thank you very much!
Instructions have to say in what measures, because I was thinking in cm and kg.
Maybe, but you're given the formula there, so you shouldn't worry about the units in this case. They are kg and meters btw. I'd add it to make it clear but there are many pending translations and they should be approved before doing it.
This comment has been hidden.
you are storing the bmi in an integer, so the decimals get truncated
Scala translation
It's not w/h^2 but w/h/h :P
Not an issue.
I had same issue and w/h/h fixed it. This doesn't work: "w/(h*h)", but this does: "w/h/h". Used calculator, both give same answer. Bug?
That's because you used a double var instead of a float one.
Thanks!
@Chrono79, Chrono79, what`s diffence in this case?
One works and one doesn't. I'm not that versed about C++ to give you the reason.
I agree with the OP though. Dividing it entirely means the result becomes a whole number instead of decimal. If we went by w/h², the result would be a pretty long decimal (many digits) meaning some of the conditions will not work.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
A little late, but your calculate value is wrong, check the formula again.
he clearly said <=, but wants the max number for a condition to be at the next condition
No, your code is wrong. Read the specs again.
I guess is something wrong with the test when your trying to attempt the solution with javascript. this is the log: Log 14.358729437462937 Underweight 22.9739670999407 Normal 25.845712987433288 Overweight 31.589204762418465 Obese Random tests 24.166101066431267 Normal
and the results is specting a wrong value: expected 'Normal' to equal 'Overweight'
No, the tests are fine.
well my C++ Code works as intended in Visual Studio but does not pass the tests on the website. I was shocked to see that my code is the same that the number 1 solution and yet is not valid regarding the tests.
The #1 solution for C++ does currently pass all the tests, though. So if your solution was the same, it should also pass all the tests. The only explanation is that your solution was actually different from the #1 solution.
c# is broken. Switch/case code don't work. But in VS in pc this code work well.
switch/case in C# works in this kata. Your solution is incorrect, it uses incorrect syntax.
It's not a kata issue.
Maybe because in VS you use Console.WriteLine() instead of return?
thx, remove break; and add default branch and it work.
I love the small practice exercises.
I like how you can pretty much just paste in the description and be done with it.
It's a nice 8 kyu kata since it fits those who just started learning programming.
This comment has been hidden.
Your result var value is wrong, read the description again.
This comment has been hidden.
I think the JS test may be broken. I got this message result = 26.666666666666668: "expected 'Overweight' to equal 'Normal'". I'm also getting a message about an error in line 80 of a test file.
I've tried your code and it works. Work on your code indentation, it seems you have an extra
}
there.Sweet Now i know my BMI)
Using javascript gives me error "bmi is not a function".
this is because you create a variable within your function with the same name as the function and declared this variable without let, which puts it in the global scope and overwrites the function itself
Language C#
A Random Test is going Wrong.. someone any idea, why? Input Weight: 100.85504869532818 Input Height: 1.8323973080289448 Calculated BMI: 28.319859194071586 Result: Test Failed Expected string length 5 but was 10. Strings differ at index 1. Expected: "Obese" But was: "Overweight" But this is strange because Obese is BMI > 30.0.... ?
This comment has been hidden.
Exactly, the correct calculated bmi is > 30.0.
Good day. I think the test may be broken, as I got this message when result = 26.666666666666668: "expected 'Overweight' to equal 'Normal'"
Your code is incorrect.
^
is probably not what you think: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XORWell, I suppose it could be that, but the result I displayed originally (26.666...8) was obtained through a console.log(result) just before my return... so the calculus was correct! Or so I think... Besides, the first test passed, the one that tries for "Underweight". That's why I thought it might be a glitch in the test.
Ok. I misread your message. You misread the log: it is telling you
You returned 'Overweight' but the correct answer is 'Normal'
.Oh, I see... I'll check my code again! Thank you!
I saw another comment on this thread regarding this, however I would like to reiterate it. In C++, the (<=30) test will fail if the test case is not cast, or stored, as a float. This is due to the decimal precision between doubles and floats in C++.
Please don't open another issue about the same problem, thanks.
you're the man ... I had this same problem, I don't understand how that's possible though? I should revisit edge cases between floats and doubles 🤔🤔. Thanks for the help anyway 👍👍
Can someone please explain why you can't use "print" instead of "return"? I'm a noob so I was trying to use print for the longest time until i realized I just had to change all of the places I put "print" to "return" then "Underweight", "Overweight" etc. Is it because its within a function so it HAS to return a value? Thanks guys!
Yes, the testing suite runs your code with various input and expects it to return a value based on the input to be used in testing your code.
print
andreturn
are two different ways which code can use to communicate with other pieces of code (it's not the only use ofreturn
andprint
, but it's the case here). The difference between them is when to use which.return
can be used only when both pieces of code reside in the same program.return
passes information from the called function (callee) to the calling function (caller).print
is used to pass information from one program to another program, or from a program to a user (interactively). Two separate, standalone programs can communicate when one program prints, and another program reads.On Codewars, solution function and tests both reside in the same program (in most cases), that's why your solution should
return
a value, and the returned value is retrieved by test cases. On the other hand, many other competitive programming platforms create solution and tests as separate programs. To make communication between solution and tests possible, solution has toprint
, and tests read whatever the solution printed. But it's not the case on Codewars.Nice kata to understand base constructions of any language
Great kata! It is instances like these that I wished Java had an exponent operator and continue to be baffled as to why it does not. Still, fun kata to poke around with.
This comment has been hidden.
approved
This comment has been hidden.
Your bmi calculation is wrong. Please read this too: https://docs.codewars.com/training/troubleshooting#post-discourse
I read it once before, but I will read it again. thanks
Check the part about markdown formatting so your code doesn't lose indentation when posted here.
This comment has been hidden.
Why are you rounding? Also:
This comment has been hidden.
Nice Kata however it is medically incorrect. please check this website : https://www.cdc.gov/healthyweight/assessing/bmi/adult_bmi/index.html
Below 18.5 || Underweight 18.5 – 24.9 || Normal or Healthy Weight 25.0 – 29.9 || Overweight 30.0 - above|| Obese
it would be nice that our community would learn how to code and learn and about facts (in this case medical information about bmi that is accurate).
Sorry buddy you are mistaken. Even according to the CDC link you showed the below table is the correct value for BMI
BMI Weight Status Below 18.5 Underweight 18.5 – 24.9 Healthy Weight 25.0 – 29.9 Overweight 30.0 and Above Obesity
Good kata. It's useful in real life too. Not just in training one's code skills. And yet in my humble opinion there is a flaw. I saw some Kata with unclear description, this is the first with a description way too clear. Using Python one can complete the task by just copypasting description and adding one or two lines.
There are a problem in C++ test with bmi = 30.0 when w = 86.7 and h = 1.7
The first two fixed tests and all random tests work correctly.
if you know how floating numbers work (in a binary system as well), then you'll know why computers can't accurately count some values.
And actually, the test is not even an edge-case which causes weird floating point rounding in typical implementations. The test-case is actually simply wrong:
w = 86.7000000000000028421709430404007434844970703125 h = 1.6999999999999999555910790149937383830547332763671875
so w>86.7, h<1.7, so w/(h* h) > 86.7/(1.7^2) = 30. So Obese is actually correct, given the input.
Almost a year later, still the same issue.
I think it also makes a difference if you calculate as w/(h*h) or w/h/h
The test cases should not sit on floating point boundary.
Still got the same issue here in cpp
changed that test. i ran the full tests a bunch of time with the reference solution and the user solution using different order of operations, and tests passed consistently, so these problematic cases should be exceedingly rare.
This comment has been hidden.
Your function should return a string. And don't use round.
This comment has been hidden.
Why are you using trunc?
Hi all, I am super confused, I felt like this one was going to be easy however even though I have what I think is correct it says it's wrong even though it's giving the answers it is supposed to?
Basic Test Cases
Log Underweight None should equal 'Underweight'
Log Normal None should equal 'Normal'
Log Overweight None should equal 'Overweight'
Log Obese None should equal 'Obese'
Log Normal None should equal 'Normal'
return
notprint
.My hero :D But seriously thanks
I generally think that the description should not include only pseudocode. If the cleanest solution is just to copy the description and fix syntax errors, what's the point? In python, it's only missing colons and a minor change to the exponent.
I also would suggest writing a sentence or just copy the WHO classification from Wikipedia: "The BMI is a convenient rule of thumb used to broadly categorize a person as underweight, normal weight, overweight, or obese based on tissue mass (muscle, fat, and bone) and height. Commonly accepted BMI ranges are underweight (under 18.5 kg/m2), normal weight (18.5 to 25), overweight (25 to 30), and obese (over 30)".
The task should definitely come with a health disclaimer that this is not advice, not universal or something. Health topics are delicate and people shouldn't be called "not normal" for no reason.
As someone who's inbetween the beginner and intermediate area in programming(generally), this challenge feels kind of underwhelming.
Nitpick: the
weight
parameter should be renamed tomass
since the BMI is universally recognized asBMI = kg/m^2
(kg is mass, not weight).There's the alternative
BMI = lb/m^2 x 703
, but there's no magic number in this kata.What does this mean in the sample test? test.assert_equals (array_plus_array ([1, 2, 3], [4, 5, 6]), 21) test.assert_equals (array_plus_array ([- 1, -2, -3], [-4, -5, -6]), -21) test.assert_equals (array_plus_array ([0, 0, 0], [4, 5, 6]), 15) test.assert_equals (array_plus_array ([100, 200, 300], [400, 500, 600]), 2100)
test.assert_equals ()
makes a comparison of the two items passed into it[- 1, -2, -3], [-4, -5, -6]
is the given input for this testarray_plus_array()
is the function you need to write21
is the expected return value for this testWhat does this have to do with "Calculate BMI"?
HA! that's a great question, and the answer is NOTHING: because the sample tests you showed are from some other kata, but the idea is the same. Anyway, the sample tests for this kata are:
...so your function
bmi()
is passed two parameters and you should return astr
as a result.Yes, I got it. Thank you very much man
This comment has been hidden.
You're not returning what you're asked to. Not an issue.
This comment has been hidden.
This comment has been hidden.
NASM Translation
Trying to get someone's attention to this as the katas author has been absen a couple of months
You can always post it here so that other PU's might come accross and review ~~
Thank you - I wasn't aware of that
Approved
Coffeescript && Julia (author inactive)
This comment has been hidden.
You should only return "Obese", "Normal", etc. Are you sure you're calculating the bmi ok?
yes, BMI calculating with 'weight / (height * 2)'
This comment has been hidden.
height * 2
isn't ok. But I'm not sure if the problem is you didn't use markdown formatting posting your code here or you didn't use the proper operator.This comment has been hidden.
In memory when you store double it's more of an approximation and ONLY accurate to a certain amount of bits like 15 I think? So when you try to use 1.7 * 1.7 its more like 1.6999...55 * 1.69999......5555. As you multiplty things with uncertainty the rate of uncertainty compounds so you're moving up the errors higher and higher to a point where it gets recognzied by the compiler as an actual value.
Atleast I think that's what it is. You can see this if you initialize a double var to a value in something like VS code, when you hover over the var it'll show you a number thats slightly off.
the C++ test case
(w = 86.7, h = 1.7)
was problematic because the orer of operations affected the result. removed.Hi! I found one problem with bmi = 30. In instruction was that equals to overweight. ((bmi<= 30)=overweight). So, everything upper than 30 (without 30, because it is in overweight class) will be obese. Right notatnion of that will be ((bmi > 30)=obese). I don't know why my code run only when ((bmi > 30.1)=obese). Please, can someone explain it to me? (I wrote it in c++)
This comment has been hidden.
This comment has been hidden.
the C++ test case
(w = 86.7, h = 1.7)
was problematic because the orer of operations affected the result. removed.bmi=weight / height ** 2= 24.69
bmi=weight / height ^ 2= 26.66
what the hell?(javascpt)
**
and^
are different operators and work different. I've changed the kata description.Here is an Elixir Translation.
I've forked the Rust translation in order to update it to Rust 1.49 and updated
rand::Rng::gen_range
to its new signature that takes astd::ops::Range
.how the hell (80 / 1.80) ^ 2 can be normal since it will return 46 ????
Your formula is not a valid formula for BMI. BMI for 80kg and 1.8m is ~24.7, which is in range of "Normal".
80/1.8^2 != (80/1.82)^2
This comment has been hidden.
You forgot the
if
or you shouldn't write a condition afterelse
This comment has been hidden.
For the warning: you should add a return after the last
else if
branch or simply useelse
.the C++ test case
(w = 86.7, h = 1.7)
was problematic because the orer of operations affected the result. removed.I'm not sure how to caculate bmi@@
The formula is right there:
^ 2
means square there.This comment has been hidden.
C Translation available
Can anyone Please explain why everybody calculate bmi w/h/h, while the explanation says w/h*h.
both methods are used in viewable solutions, as they are mathematically equivalent. (162 / 9 / 9) == 2 == (162 / 9 ** 2).
but w/(h*h) won't work for me in this case. do you know why?
No sorry: could be some other calculation, can't tell without seeing your code. Post your code with proper markdown (use the spoiler tag), and someone can take a look for you.
This is a problem with float precision:
it didn't work for me either
I am so utterly confused at this kata. I cannot solve this for the life of me, and have no clue why. I get the random tests correct with every variation of my code, but never the fixed tests. I know it's a logical issue, but I can't figure this out, I give up. This has caused too much stress in my life lol.
I have the same situation. Additionally everything is working fine when I use another compiler...
Excuse my lack of clean code and test statements, I was frusterated when coding. I'm sure it's a lack of experience in... something... on my behalf, but I don't know what.
What language were you using? It might be a problem with the Kata itself.
There is a small typo in the results text. The word "and" is misspelled as "amd".
This comment has been hidden.
Please, use Solutions section instead of Discourse to discuss solutions.
Write function bmi that calculates body mass index (bmi = weight / height ^ 2).
even if you change it to (weight / (height ^2)), the test code still comes out as 26+ which gives you obese not normal since normal is set to under 25. I don`t know how you wanted the bmi to be calculated since in the question its even high value.
if bmi <= 18.5 return "Underweight"
if bmi <= 25.0 return "Normal"
if bmi <= 30.0 return "Overweight"
if bmi > 30 return "Obese"
Not an issue.
^
is not theXOR
operation.I think the description should be (weight / (height ^2)) the current one is misleading
I wasted 20 mins and I thought that i did sometching wrong until I Googled formula with brackets. But we should remember that ^ is performed before multiplication, division, and addition, so it is our fault, that we don't remember about order in math :d
I was hoping I found a nice site to do some programs and learn something in C++. Turns out this page dont know that a*a and a^2 are the same things.... Disappointment
AFAIK
^
is a bitwise operator (in C++), so they aren't the same thing.Then what about / operator?
@Chrono:
^
is bitwise xor in a lot of languages, but in some like Julia and Factor, it's exponent. In C++, that's bitwise xor.Then why can I use / operator if i can`t use *?
I don't know what you're talking about when you say you can't use
*
, it seems you have a problem with precision for some test, try a different data type.This comment has been hidden.
Such conversion is not mentioned anywhere in the description, so why bother about it? XD
This comment has been hidden.
Not a kata issue, your function should return those values, not print them.
Thank you.
Maybe someone else already mentioned this(?) I think there's a typo in the instructions. If a bmi is greater than 30, one is considered obese.
So, this should be >= 30, rather than <= 30 in the instructions. "if bmi <= 30.0 return "Overweight"
If you make the change you propose, your code will never return "Obese" and there will be a gap between bmi's.
Yes, you're correct. I guess I need more coffee. :)
Hello!
I was able to work out the solution in Playgrounds, but seem to keep running into an error when I attempt the test here. The error is as follows:
main.swift:25:56: error: cannot convert value of type 'Int' to expected argument type 'Double' XCTAssertEqual(solution(weight, height), bmi(weight, height)) ^~~~~~ Double( )
Any idea why I am getting this error message?
Thank you!
This comment has been hidden.
Check the function definition clicking reset:
Leave it like that, do the casting inside it.
Okay great, thank you!
Hi guys, I' new to programming. Codewars give me this error altough the func works properly in Swift Playgrounds. Can you help me with this?
solution.swift:10:1: error: expressions are not allowed at the top level bmiCalc(userWeight: 85, userHeight: 1.75) ^ Thanks.
Post your code and we can help. (Note: with a spoiler flag, and using markdown formatting.)
This comment has been hidden.
Hey guys, is the Swift version broken? I'm 100% sure my solution is working in XCode and Playgrounds on iOS.
Cheers
AFAIK, it works in Swift, check the function's name, in the kata it's
bmi
and the parameter's types areInt
andDouble
, click reset to see it.Sorry for late response... The signature is
func bmi(_ weight: Int, _ height: Double) -> String
, sofunc calcBMI(userWeight weight: Double, userHeight height: Double) -> String
won't work.Hey guys thx. You both make my day. I solved the kata. Didn't know, that I have to keep the functions name and the parameters name. Thanks again and have a nice weekend. :o)
This comment has been hidden.
added random tests to f#, r, and rust
This comment has been hidden.
Click reset, check the initial code:
Thats not the inital code. Weight is a f32, not a u32.
fn bmi(weight: f32, height: f32) -> &'static str {
Then down in the test it is testing for u32, not f32, although it wants you to test for floats.
Are you sure? When I click reset I see
u32
notf32
.This comment has been hidden.
This comment has been hidden.
Have you included math with
#include <math.h>
? You don't even needpow
tho.I found a bit confuse :
in every math formula or in Matlab the symbol ^ is means "exponential" but in Python or Javascript symbol ^ is means XOR , better to write a note/legend to explain is exponential : symbol "**"
That's a part of the exercise.
In python you can do exponentiation with "**" or you can multiply the variable you want by itself(var * var)
This comment has been hidden.
just use float no double in bmi = weight /(height * height) And you cant multiply to get square of height
OP solved it, closing
This comment has been hidden.
not an issue, a question.
(unfortunately, I don't do C++, so I cannot help)
This comment has been hidden.
This comment has been hidden.
you should not round at all, you lose accuracy by rounding
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
BMI is calculated as weight / height ^ 2. You do weight / height * 2. Please don't raise this as an issue. Raise it as a question or something
Ooh sorry, I was inattentive. I can't delete or edit my question? I can't find how I can change label to the "Question".
This comment has been hidden.
It gives me a syntax error
1.) You must not put a space between the operator. Change
< =
to<=
. 2.) You must return the output instead of printing it. Changeprint
toreturn
. 3.)^
is the operator for xor, not exponentials. Change^
to**
. 4.) You have missed the "Overweight" section of your code.1.) Mark comments that have code in them as a "Spoiler". 2.) You can format code in the comments using Markdown: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code-and-syntax-highlighting.
Thank you very much AcesOfGlory. Very smart answer. I am proud to be part of codewars.
I just completed this exercise and it returned with 1 failed test that should have been "Normal". I then returned to the exercise, made no changes to the code, submitted again and it passed all tests.
random tests? It's quite possible you ran into floating point inexact comparisons, like I did. I had to hack it with a margin...
This comment has been hidden.
Inexact floating point representations can result in different outcomes for different expressions/evaluation order.
This comment has been hidden.
Floating-point rounding errors.
w/(h*h) first multiplies h and then divides w. w/h/h first divides w and then divides it again.
The different setup of the operations can introduce little discrepancies that mess with direct floating-point comparisons.
the C++ test case
(w = 86.7, h = 1.7)
was problematic because the orer of operations affected the result. removed.This comment has been hidden.
Error from Swift. My code doesn't seem related. Tried the question code in a playground and it's fine there. Any ideas? line 9 has only one item so this doesn't make any sense.
/workspace/main.swift:1:9: error: consecutive statements on a line must be separated by ';' wiimport XCTest ^ ;
I decided to run it and not hit the tests and it worked fine in the autograder!? This error message looks to be a waste of time. Onwards...
This comment has been hidden.
This comment has been hidden.
C++ Error in the test cases: Here are the cout (in w | h | bmi = w/(h*h) )
81.585 | 2.1 | 18.5 Ok 90.25 | 1.9 | 25 Ok 86.7 | 1.7 | 30 Failed here, Equal to Obese Actual Overweight; this result is contradictory to the instructions if bmi <=30.0 the person is overweight not obese.
I agree, this seems broken.
Read other posts about it, it's a floating point representation problem.
This comment has been hidden.
^
is the wrong operator ;-)that what hungers do to ur brain. thankful ♥
Python: Always showing "Fail to communicate with excuting service"
Edit: All my Python Kata meet the same problem. But c++ is OK.
Doesn't happen anymore.
Easy but essential Kata.
So easy you can actually copy and paste the description and run it to pass (with a bit of added syntax).
Gives me network error even though I run the test with working internet connection (and passing all the tests). Can't submit solution with Python.
Edit: prolly it's a problem with the site since I can't submit solution to another kata as well. Keeping this open anyways
Closing.
Trying to do this kata in c++. All tests was passed but when I try to send my attempt I got "Expected: equal to Obese - Actual: Overweight". Any idea what's going wrong ?
This comment has been hidden.
Since this kata was worth 8kyu I figured it would be harder than many others on this site but this is the simplest kata I have completed yet. Did I misunderstand the kyu currency system?
"dan" is considered mastery-level, and the numbers represent distance from "dan."
So, 8kyu is the easiest, going up to 1kyu. Then 1dan is harder than that, and 2dan is harder than 1dan, and so on.
The
kyu
level of a kata is rated when it is still in the beta stage, so it is the community in general who decides (not the kata author). Though sometimes there can be under-ranked or over-ranked katas and one's perspective on the kyu system may change as their proficiency grows ~~Hi, I've updated the C++ translation and it should be considerably higher quality, and I've also provided a TypeScript translation for your consideration.
Damn, I can't approve it, but I have no idea why (no message, that just doesn't work)...
:(
The author, wichu, likely has to approve the translation him/herself.
Yeah but that's a bit weird: I'm "power user" so I should be able to approve it. Maybe this is because he came by lately (last seen: this month).
C++ version lacks random tests. Any C++ competent poweruser passing by is welcome to update the kata.
EDIT: please check the order of the assertions arguments too: they seem to be swapped (but that didn't work anymore when I tried to swap them... I don't know where I messed it up... x-) I don't know c++...)
When trying to swap arguments, you likely changed it from
Assert::That(expected, Equals(actual))
toAssert::That(Equals(actual), expected)
, when it actually was supposed to beAssert::That(actual, Equals(expected))
.c++ was still missing some headers, so please approve my c++ fork, then this issue can be resolved.
author is active, I cannot.
now...?
alredy approved.
Kata is completly solved for C++, i had nothing to do but run the tests and submit.
I agree. The starter for C++ language contains a solution for the Kata.
I corrected the solution setup... And the assertions (expected and actual were swapped)... But I cannot do anything about the lack of random tests... I'll open a new issue about that.
This comment has been hidden.
This comment has been hidden.
I'd say you're missing ';' here 'bmi = weight/(height*height)'.
This comment has been hidden.
This comment has been hidden.
If that's javascript, ^ is the bitwise XOR operator. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators Also, you should return a string, and you're using console.log instead.
This comment has been hidden.
Log: Underweight
None should equal 'Underweight'
Why doesn't work if the answer matchs.
I translated this to Swift.
This comment has been hidden.
Please check your formula again, you got it slightly wrong.
This comment has been hidden.
This comment has been hidden.
Should be fixed.
The tests don't match the definitions in the description.
1.6403397473726824|90.43609621210567 | 27.566269840426767 Expected: 'Obese', instead got: 'Overweight'
1.7849189567364991|64.6967371697928 | 18.123158176347314 Expected: 'Normal', instead got: 'Underweight'
1.5495722923152488|46.128366942645904 | 14.884225528363228 Expected: 'Normal', instead got: 'Underweight'
This comment has been hidden.
Floating point division is different from integer division.
Yes, you have right! Thanks, now everything works!
These ranges are incorrect. Here's correct ones:
Severe Thinness < 16 Moderate Thinness 16 - 17 Mild Thinness 17 - 18.5 Normal 18.5 - 25 Overweight 25 - 30 Obese Class I 30 - 35 Obese Class II 35 - 40 Obese Class III > 40
Also bmi = 26.666666666666668 is expected to be 'Normal' ? Why ?
Because you're calculating the BMI incorrectly.
Also, that's not an issue, that's just the kata not exactly using the full official definition.
I think you might want to review what actually constitutes an issue before filing one.
"that's just the kata not exactly using the full official definition" - Why not using proper ranges ?
Several ranges exist depending on your country and your age: please do some search before raising issues -> BMI on National Heart, Lung and Blood Institute
Python, Ruby and Crystal translation added for you to approve, cheers :)
Can you add to description that operator "^" isn't XOR? Thx
Current description does not contain
^
anymore, closingHi, I made a C# translation for this Kata, please review and approve.
you might consider the terms "overweight" and "obese"
Done.
I changed the kata's decription to more precise. Thanks for suggestions.
Task needs to tell what diagnosis should be shown for what values. It's pretty not obvious that we should display "Fat" instead of "Overweight"
Description added.
thanks for Your suggestion. You can change it if You want.
Hi,
Regards,
suic
Description added.