4 kyu
Minimum Number of Coins
274 of 280GiacomoSorbi
Loading description...
Parsing
Strings
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.
Expected handling by random tests are utterly nonsensical:
You simply tell "dumb" users the input was wrong, not forcefully gobble up the value and produce completely insane results. The premise of this kata's """edge case handling""" is unconvincing.
The first two are indefensible, but you do sometimes see the third on handwritten price cards at markets.
I wouldn't be surprised to see the first one too tbh, but it shouldn't be valid input here per the rules in the description.
The issue is worded this way because GiacomoSorbi is well known for writing sloppy kata and code like this all the time. This is not the first time, nor the last time his crappy, nonsensical katas annoy the heck out of others. In fact I haven't find any GiacomoSorbi katas that I'm not severely annoyed by.
Well he claims that "someone from London" told him they were correct, which I presume means he can't tell when someone is taking the piss out of him. Nobody who went to school here would consider any of those valid.
Fun kata! :) My initial solution would occasionally fail some of the random tests although I could have submitted it. But of course it's hard to design testing to cover every eventuality especially where the test input can be as varied as this.
Very annoying Kata, but very entertaining. Thanks.
Certainly made me think on edge cases this, passing all but one test "Testing for .5 Expected: 'Invalid input - enter a positive amount of money', instead got: '1 50p coin'" given "if the number is a float, the value is in pounds, otherwise consider it as pennies" not sure this sits right with me, the value is a float given the decimal point, but with no decimal part, the pennies portion I'd see as valid?
According to your tests
1.257422457p == £1.26
.Great kata overall! However, I believe that input like £1p should return 'Invalid input - enter a positive amount of money'. Since £ at the beggining means we are dealing with pounds and "p" at the and means pennies, this input become really tricky because we don`t know which sign is more important in this particular case. I would suggest considering as valid only "£1", "£1.0p" or "1p" as far as here will be no space for misunderstanding.
Exactly my thoughts, £1p is nonsensical; leading "£" and trailing "p" should only be allowed if the value contains a decimal point.
Testing for £1.87p
I may have missed something in the description, but all I found about this was
How can it be okay to have BOTH in the same description? They're litterally contradictory! If what's intended there is to show that the description does not clearly state that
if p is a the end of the amount the value is in pence)
then good job, you've just ruined your kata trying to be funny.And then you contradict even your own rules:
The rules state
if a float with no symbol is given, assume it is a value in pounds and round it to the second decimal
WITH NO SYMBOL! What is it now, 'p' is no longer a symbol? It's not even subtle, the rules themselves said it was two lines above u_u
And that part is followed by
do not count fractions of pennies: 1.257422457p==1.26p
which is self-contradictory as well, if we don't count fractions of pence then1.257422457p == 1p
unless, once again 'p' is actually meaningless and should be read "pounds" when after a float.Difficulty from voluntarily misleading statements is the worst you could do. If I'm misunderstanding what you meant to do or if there's an actual mistake in the tests then please enlight me (Sorry if I sound frustrated ; I am, because your kata are usually good so I take it for granted... Ok my bad, I shouldn't get carried away).
Note: I did it in Javascript, but I don't think it matters because I'm just talking about the description and Fixed test cases here
In that first example, the pound sign and pence sign are in their respectively correct positions (beginning and end). If the
£
is first, it's in pounds. Thep
is extraneous here but not invalid :) It's like saying "one dollar and thirty-five cents" instead of "a dollar thirty-five".As for the second example, I'd have to agree the description could use an update. But here I just took it to mean a float with no leading symbol (e.g. £).
Agreed on the last statement as well (fractions of pennies). Funny I don't even remember it occurring to me that that was an issue... but I guess I expect things to just get a bit lost in translation so maybe that's why :)
Great mind-bending kata with all those edge cases and what not. Quite tough to get an optimal and good-looking solution ;-)
Thanks for making it!
My pleasure :)
Why is "L200" invalid? Is it not just 200 pounds?
And the error being?
It's in the examples
minCoins("L200") == "Invalid input - enter a positive amount of money"
i believe any character except £, p, decimal point and digits make an input invalid.
Not for Ruby, where apparently I cannot use
£
here on CW; not sure which language he was mentioning, though.So L is invalid for all languages except for Ruby?
Not sure about a few translations: what do the test cases expect and which language are we discussing?
This comment has been hidden.
Just to clarify this,
L
is the pre-decimal notation for pounds (at the very least our grandmother said so when teaching us about ancient times) andd
is the pre-decimal notation for pence. I have no idea why those are even specified as edge cases since we switched to decimal currency in the fucking 70s but there we go.Overall a fun Kata. My solution's a complete mess at the moment as a result of all those edge cases lol although obviously that's my fault for doing it piecemeal. I did find the floats in pence to be a bit odd. Overall fun though. Not sure why it has so few completions/votes.
Glad you enjoyed and thanks for your feed :)
This comment has been hidden.
Thanks for the feed; if you want to suggest some edit to the description, just be my guest :)
I'd recommend changing this example in the description - minCoins("L200") == "Invalid input - enter a positive amount of money" to this one : minCoins("L200") == "100 £2 coins"
Also, this example led me astray: minCoins("2£1p") == "Invalid input - enter a positive amount of money". There's actually nothing wrong with that example, but I took away from it that you "can't have both "£" and "p" in a string (wrong conclusion). A helpful add-on would be: minCoins("£2p") == "1 £2 coin". Then if this string were allowed (I don't recall if you had such a test case where there was £ AND decimal AND p, but... minCoins("£1.95p") == minCoins("1.95p") == "1 1£ coin, 1 50p coin, 2 20p coins and 1 5p coin".
And maybe, for clarificaiton: minCoins("1.95p") != minCoins("2p") since we know that you round to the nearest pence but your decimal rule means pounds, not pence.
I think that would reinforce the £ symbol/decimal rule you had because there would be less possible confusion with cases where symbols were messed up (two £ symobls, two p symbols, etc.) In other words, I was unclear that one could have both £ and p in the same string and still be valid. I hope that helps!
The whole point of the kata is to parse input from a "dumb" user, so cases are meant to be confusing - edge cases are meant to be messed up. And while I might agree with some of your observation, as far as I know and have seen here in the UK, you almost always prepend "£" to the amount, never seen it put inside it with a following "p", so that in my book should be wrong.
For the rest, I will make clearer that "£" wins over "p".
Thanks for your feed :)
Fixed.
This comment has been hidden.
This comment has been hidden.
Fixed?
CoffeeScript translation added, description modified. Please accept.
I can't see where you modified the description (other than adding language-specific test cases, of course), but gratefully accepted :)
What about '23.1p', will it be considered a valid input, and if so, should it be evaluated as 23 pennies? I think the test cases are missing this corner case.
Also, for me input like "£2p" doesn't look valid, it rather looks ambiguous. I can hardly imagine somebody writing money amount like that in real life. I can understand a format "£2.00p" (with a dot), but integer pounds with 'p' suffix looks strange to me.
Float=>you have to count it as pounds.
And I know many are really, REALLY edge way to write an amount of money, but I was given this idea (and most of the fixed test cases you are seeing here) by an English man, so I'll assume that he knew how currency works in his country or at least what could be considered plausible by a UK resident (I have little to no idea in that regard).
"£2p" is 200 pennies; let me know if I didn't make it clear in the description that floats and "£" symbols have a sort of precedence compared to other aspects.
Edit: improved (or so I hope) the description a bit in this regard. Thanks for your feed as usual :)!
So you think 23.1p should really be 2310 pennies?
I was skeptical too, but I was explicitly told to work and parse the input that way.
[P.S.: do you by any chance happen to know how to use UTF-8 chars here with Ruby?]
Sorry, I'm not an expert in Ruby.
If by "UTF" chars you're talking about things like "£", you can do that in Ruby just fine as far as I can tell. If you were for example trying to use one as the key of a hash, though, you'd have to put it in quotes. Ruby sees it without a string as a variable or method name.
Also.. as far as the 23.1p being 2310 pence, I don't get that at all. There are countries where 2.043 would mean 2043 (as they use commas to mean a decimal point and vice versa) but I don't think England is one of them, and I've definitely never seen that format. Granted, I'm American. But it seems pretty odd.
Have you tried if it works here on CW? Maybe now, but back then was a known issue, apparently, to use such symbols.
For the pence: try to multiply
23.1
by100
...Ah, didn't realize that. No, I thought you just meant in Ruby in general, I haven't tried it in Ruby. As far as the 23.1*100, I mean yeah, I'd worked that out haha. I'm just having an issue right now where I must be hitting an infinite loop at some point in the random test cases.
Mate was taking the piss out of you lol, nobody would parse 23.1p as 23 quid.
Python and Ruby translation should follow shortly; translation in other languages as well as any feed are welcome as always :)
Any chance for those translations?
Oh, thanks for the reminder; might take them back this WE.