6 kyu
Converting Measures
217 of 461PollyRibeiro
Loading description...
Regular Expressions
Algorithms
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.
python new test framework is required. updated in this fork
Approved
A truly excellent Kata! Thanks @PollyRibeiro
Ruby 3.0 should be enabled, see this to learn how to do it
Please organize the structure of test fixture as following (although it has been mentioned in the attached link, I'm repeated here again)
Enabled in this fork
Isn't there an issue with provided example? Why should a 1/2 tsp of salt become a 1/2 tbsp of salt?
I think that's a typo, because it's followed by
3g
instead of8g
.1 tsp
=5g
1 tbsp
=15g
Fixed description
Thanks everyone that helped me to improve and translated this kata. It was my first kata, so I was a few confused and made some mistakes. I will be more careful with the random tests next time :)
I don't think this is a level 6, feels more like a level 5 to me
I just checked your solution. Maybe it seemed like 5 Kyu to you because you made it complicated yourself. A single
string.replace
with a singleRegExp
would've been sufficient to match and parse all the quantities and measures.Fixed vs. random tests are inconsistent in terms of the required formatting: (some of) the of fixed tests expect integer values for the converted weights, whereas all the random tests expect a rounded floating point number ending with '.0'.
Specify the language please.
EDIT: tried both versions - the internal validation "inserts" an integer into the string, not a float ending with
.0
. Are you sure your code is correct?Oh yes! Python 2.x sorry.
math.ceil
returns a float in Python 2.x and an integer in Python 3.x, thus giving strings with.0
floats.Use Python 3.x instead.
Ruby translation kumited -- please check and approve!
Thanks for approveing!
ptyhon:
the test suite is lacking it's
import math
Added
(Also your spelling seems pretty iffy at the moment, are you sure you're not codewarsing at 3am again? ;-))
XD
Not even so. Lacking cafein, I guess... ;o
Random tests should probably have variable amount of measures.
Python translation. You could add it if you want.
.
@FArekkusu
random test generation is faulty (see issue above) and too complicated. Take a look at the ruby translation for some simple ideas :-)By faulty do you mean math.ceil returning
float in Python 2.x
andint in Python 3.x
? Because I believe this is a difference between Python versions which is causing this, not an issue. This can be fixed very easily by including anint()
in the internal solution to cut off the.0
part, actually...Well, IMHO my generator is better because it doesn't end up with either integer N or a fraction of 1, and, I think, the generator is not important as long as it gives random results and doesn't include anything broken like
1/1000 tbsp of ***
.This comment has been hidden.
Added random tests.
And your solution suddenly broke.
EDIT 1: You're rounding it wrong. For example
11/4 tbsp = 2.75 * 15 = 41.25 --> 42
. Your solution returns41
.EDIT 2: the description might have been misleading, so I improved it too.
Fixed, thanks;-)...