6 kyu
Ease the StockBroker
327 of 2,180g964
Loading description...
Fundamentals
Strings
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.
Regular expression lite kata)
The error is only partially visible making it impossible to correct any formatting issues: expected 'Buy: 169850 Sell: 116000; Badly forme…' to equal 'Buy: 169850 Sell: 116000; Badly forme…'
python new test frame work
Approved
Crystal:
snake_case
Ruby:
function name should use
snake_case
3.0 should be enabled
Both done in this fork
/home/codewarrior/program.fsx(53,19): error FS1160: This token is reserved for future use
/home/codewarrior/program.fsx(100,57): error FS0035: This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use
anyone can help me?
C#: method name should be
PascalCase
(Please refer to implementation of backward compatibility here )i have no clue what its asking
a little bit difficult for 6 kyu
This comment has been hidden.
in my opinion an empty string should be a bad result and be counted in the counter of Badly formed. it is logical
that was a lot of work in C : parsing the input, validating the orders without regexps, writing code to allow for an arbitrarily growing result string...
I took the liberty of adding useful assertion messages and improving the initial solution, but random tests are still lacking.
Hope that all will go well:-) Still a bit of effort for random tests...
This comment has been hidden.
Great kata ^^
My sol passes fine but I don't submit as of now. Some remarks:
Right but I thought the note for Golang (and maybe others) at the bottom of the page was a good indication of what do (AFAIK C++ has a sprintf too).
Maybe it's not useful to add a note for everything:-) Observing the example and the "Sample tests" should be sufficient. Know how to observe is a quality worth developping... A kata doesn't need to be passed at the first go.
Sorry to not be more constructive; my point of view is not shared by everybody. Anyway thanks for your posts.
Edit:
The kyu is not given by the author but by top coders who are sometimes very smart:-)
:-) Submitted !
Good!
expected 'Buy: 169850 Sell: 116000; Badly formead 1: CSCO 250.0 29 B ;' to equal 'Buy: 169850 Sell: 116000; Badly formed 1: CSCO 250.0 29 B ;' where is problem?
You exactly get:
It seems that "Badly formed 1:" is not the same as "Badly formead 1:"...
Ah right, it just my dyslexia. But got another problem expected 'Buy: 0 Sell: 11602; Badly formed 3: CAP 1300 .2 B ;CLH16.NYM 50 56 S ;OWW 1000 11 S ;' to equal 'Buy: 260 Sell: 11602; Badly formed 2: CLH16.NYM 50 56 S ;OWW 1000 11 S ;' It says that there are only 2 badly formed inputs while I found 3. The difference is probably in this one "CAP 1300 .2 B" which really seems like wrong input unless we should take .2 as 0.2 and work with it? Thanks for answers.
ok so I took .2 as 0.2 and it works now.
This comment has been hidden.
maybe you just misplaced some brackets. ;-) To help you out, you need to share your code (under the spoiler flag).
You have to use it everywhere it is needed and you will pass this part. Moreover your code gets
Cannot read property 'includes' of undefined
which makes it fail.There is a problem in the description (python): "Notes: If the order is empty "Buy is 0 and Sell is 0"."
However: "Oh dear! balance_statement("") returned: 'Buy is 0 and Sell is 0' should equal 'Buy: 0 Sell: 0'"
'Buy is 0 and Sell is 0' is an explaining sentence, not the formatted result... Nevertheless I modified it. Thanks.
Oh, then I missread, sorry... thank you!
I didn't like this one at all. I solved the basic problem in like 1 minute, then had to spend another hour matching the required output format, which to be honest was super weird.
Formatting is a little spice on a bland dish...
I actually enjoyed the flavour of the dish, but you should have removed the whole spices before serving it ;)
I didn't like this one. The hardest part was to get the output exactly 'right'. Right in this case being plain weird. What's the deal with all those spaces/ colons/ semicolons and/or combinations of some of them? Didn't make sense at all.
Formatting is a little spice on a bland dish...
I think that the description regarding the format of the buy and sell prices should be fixed.
This seems to indicate that the result should be truncated when the correct answer for the tests (in Python) should be rounded.
Nice Kata ,funky spacing of punctuation ,though ...
Whoever created this was a bozo. The problem explanation leaves quite a bit to be desired, and the output for the test that fails, seems to indicate that my code produced the proper output. Seems like the Kotlin version is jacked.
Maybe I am a bozo but no need to be rude for posting an issue; instead you should give the input and your output.
This comment has been hidden.
Sorry, I have not seen your issue sooner. I tried your solution and effectively it doesn't work. The tests are for nothing in the recognition or not of regexes in awk...
Tere's something wierd going on with this array joining and ';' in the end probably should be joined not like this: "Buy: 263 Sell: 11802; Badly formed 2: CLH16.NYM 50 56 S ;OWW 1000 11 S ;" but like this: "Buy: 263 Sell: 11802; Badly formed 2: CLH16.NYM 50 56 S; OWW 1000 11 S"
The description says nothing about the validity of empty strings. At the same time, from "The order can be simple or multiple" we can assume that the number of items must be
>= 1
, hence either it's a "badly-formed item", or a wrong function input.I slightly modified the description. Could you have a look?
needs round up/down description.
I am getting some inconsistent rounding in the random tests in Rust when the fractional parts are 0.5.
Here are two examples:
GOOG 90 160.45 B, JPMC 67 12.8 S, MY SPACE 24.0 210 B, CITI 50 450 B, CSCO 100 55.5 S
expectsBuy: 14440 Sell: 6408; Badly formed 2: MY SPACE 24.0 210 B ;CITI 50 450 B ;
. The total buy amount is 14440.5 and 14440 is what is expected (rounds down).BoAML 15 55.5 S, APPL 67 34.8 B, GOOG 12 45.5 B, CLH16.NYM 90 5.5 S, CITI 45 210 S
expectsBuy: 2878 Sell: 1328; Badly formed 1: CITI 45 210 S ;
. The total sell amount is 1327.5 and 1328 is what is expected (rounds up).I'm pretty sure the expected answers aren't being generated correctly.
I have not solved the kata, so I am not going to resolve the issue (please someone Rust-aware confirm or dismiss it) - however the "incostistency" you encountered is not an inconsistency. Such way of rounding is commonly called banker's rounding and it's a common way of rounding monetary values, and some libraries use it as default rounding mode. If the kata requires some rounding and it does not mention how, then it's indeed an issue. But still, the rounding you see is not an "inconsistency".
You are right, it's not quite an inconsistency. In that case, I suppose the issue I'd like to raise is that, like you said, the instructions should be explicit about the rounding method.
There is no inconsistency. From the description "... double are formatted with no decimal" so there is no "direct" rounding, only the use of "format!" or "write!" in Rust.
In the first case you mmention:
"GOOG 90 160.45 B, JPMC 67 12.8 S, MY SPACE 24.0 210 B, CITI 50 450 B, CSCO 100 55.5 S"
the total "Buy" is14440.499999999998
(not 14440.5 as you wrote) in the 2nd:"BoAML 15 55.5 S, APPL 67 34.8 B, GOOG 12 45.5 B, CLH16.NYM 90 5.5 S, CITI 45 210 S"
the total "Sell" is 1327.5. So, in each case, the results are correct and consistent. I don't think that the description should mention explicitely the function to use to format without decimal or be explicit about the rounding method since the results correctly formatted don't need any explicit rounding. Sorry if I have been a bit too long in my post:-(This can still be a little bit tricky, because
I am not taking any position here and I am not fighting for any specific approach, I just want to show that there can, and will, be some some problems whatever you decide :) What you can do, is to add such test case to sample tests. It will help to verify the solution early.
I agree, kata with double or float are often tricky since different languages can have different ways of formatting. I can be wrong but I think part of the fun is finding your way to a solution that is accepted by the tests. Moreover in this kata many people have problems with the placement of white spaces all the more that CW output compresses many spaces into one. In my previous post I answered about Rust but as far as I know all 24 translations (there are several translators) give the same results with fixed tests. Anyway thank for your post.
Good idea, done in all translations. Thanks!
I am still confused, inspite of your thorough description. One of the basic tests is as follows; the raw sell value is 6407.6, but 6408 is expected?
This lead me to round, in spite of the instructions. Afterwhich I was met with this random test:
These values seem to be rounded (inconsistently) as well, not trucated.
Perhaps (most likely), I'm doing something foolish here. Any insight would be appreciated, as I've attempted format! and write! as well as rounding to no avail.
Thank you.
After some investigation and re-reading what g964 was getting at - I've learned the solution is correct and consistent. Previously I was using format but on a cast, not leveraging actual formatted display of floats. (I knew I was doing something foolish)
For those stuck on this, scratching their heads - I would encourage you to read up on this: https://users.rust-lang.org/t/formatting-floats-and-rounding/10235
Thank you for the kata, I learned something new.
Some languages don't have random tests, e.g Haskell.
dang that was kinda really hard
This comment has been hidden.
From the description "... double are formatted with no decimal" so there is no "direct" rounding, only the use of "format!" or "write!".
It would be neat if it was more transparrent what the correct order form was instead of having to figure it out by modifying the regex based on failed test cases. This: "Quote/white-space/Quantity/white-space/Price/white-space/Status" is not sufficient. Also see @wthit56 comment on here.
Idk why satisfaction rating of this kata is 75%. I enjoyed solving it and it wasn't hard. Nice kata.
Thanks!
Doing this test with C# (.NET Core 3.0, I'm passing it locally and my xUnit test is passing with a ew different scenarios I set up.
But for some reason when I run the code in the browser it adds another digit to the Buy and Sell values, e.g. Locally => Buy: 16500 Sell: 11000; Browser => Buy: 165000 Sell: 110000; I have no idea where that number comes from and there is no way to debug the code.
Why is there no way to debug it? Use
Console.WriteLine(variable)
and then you can debug o_OThe first test-case for PYTHON contains one incorrect order. I noticed however, the solution expects you to sum up the value of this incorrect order as well. Is this intented? I would have expected to exclude the value of the incorrect orders from the total values of buy/sell. After all, incorrect orders do contain errors.
If you mean the alphabetical order of stock names, they are irrelevant here.
The task asks only to compute the final
buy
andsell
values, and mark any badly formatted stocks.For Python just round it with round(), as explained by the author in the comments buried below :-
This comment has been hidden.
Hi, you should simply use round instead of ceil
This comment has been hidden.
With "math.Round" go pkg, the result is different from using "%.0f". The description says:
where b and s are 'double' formatted with no decimal
Please use a format with "%.0f" as I did as well as those who passed the Go kata. I will write a note about that for Golang. Thanks for your post.Yep that did the trick! learnt something new, thanks!
OK.
There is an issue in Golang tests with "MY SPACE" quote, which should be treated as an error per instructions (quote shouldn't contain whitespaces) However it's tested differently (somewhere it counts, somewhere it doesn't, somewhere it just disappears) One example
Expected <string>: Buy: 0 Sell: 0; Badly formed 2: CSCO 90 450 B ;MY SPACE 78 12.8 S ; to equal <string>: Buy: 0 Sell: 0; Badly formed 1: CSCO 90 450 B ;
Good catch! Thanks! I hope it is fixed now. Could you try again and mark the issue as resolved if everything is OK?
Works for me now, thank you!
Thanks!
[Golang]
point1
package kat
should bepackage kata
point 2
Quote/space/Quantity/space/Price/space/Status
"MY SPACE"
so please try to remove this test case, or try to change the description.
point 3
Quote/white-space/Quantity/white-space/Price/white-space/Status
PS: how can it be possible that your solution is exactly the same as mine?
Hi,
Using Java, solution is passing all the tests except one that returns:
expected:<Buy: 18184[6] Sell: 2816>
but was:<Buy: 18184[5] Sell: 2816>
The generated string by my code is
Buy: 18184 Sell: 2816
.Does anyone know what this can be?
meet the same problem using scala.
[Swift] After changing the Swift dialet a lot of times, I guess even lower than 4.0, I'va passed sample tests, but running the whole testsuite I got this error: but I don't understand whether is a test error or is an issue somewhere in the code. Did anybody face an issue like that ?
fatal error: Index out of range Current stack trace: 0 libswiftCore.so 0x00007f6e6b1c86b0 swift_reportError + 120 1 libswiftCore.so 0x00007f6e6b1e30d0 _swift_stdlib_reportFatalError + 62 2 libswiftCore.so 0x00007f6e6afdccb6 + 1186998 3 libswiftCore.so 0x00007f6e6b13c39d + 2626461 4 libswiftCore.so 0x00007f6e6afdccb6 + 1186998 5 libswiftCore.so 0x00007f6e6b0f7410 specialized _fatalErrorMessage(StaticString, StaticString, file : StaticString, line : UInt, flags : UInt32) -> Never + 96 6 libswiftSwiftOnoneSupport.so 0x00007f6e6b488e40 specialized Array.subscript.getter + 124 7 test 0x00000000004087c3 + 34755 8 test 0x0000000000409c89 + 40073 9 test 0x000000000040a744 + 42820 10 test 0x000000000040aefa + 44794 11 test 0x0000000000409c01 + 39937 12 test 0x000000000040ae91 + 44689 13 libXCTest.so 0x00007f6e6b43148b + 287883 14 libXCTest.so 0x00007f6e6b407502 + 115970 15 libXCTest.so 0x00007f6e6b431440 + 287808 16 test 0x000000000040549b + 21659 17 libXCTest.so 0x00007f6e6b406b20 XCTestCase.invokeTest() -> () + 112 18 libXCTest.so 0x00007f6e6b426cd0 specialized XCTestCase.perform(XCTestRun) -> () + 313 19 libXCTest.so 0x00007f6e6b406a50 XCTestCase.perform(XCTestRun) -> () + 14 20 libXCTest.so 0x00007f6e6b404520 XCTest.run() -> () + 516 21 libXCTest.so 0x00007f6e6b427250 specialized XCTestSuite.perform(XCTestRun) -> () + 892 22 libXCTest.so 0x00007f6e6b404b40 XCTestSuite.perform(XCTestRun) -> () + 14 23 libXCTest.so 0x00007f6e6b404520 XCTest.run() -> () + 516 24 libXCTest.so 0x00007f6e6b427250 specialized XCTestSuite.perform(XCTestRun) -> () + 892 25 libXCTest.so 0x00007f6e6b427250 specialized XCTestSuite.perform(XCTestRun) -> () + 2007 26 libXCTest.so 0x00007f6e6b404520 XCTest.run() -> () + 557 27 test 0x0000000000404973 + 18803 28 test 0x00000000004097da + 38874 29 libc.so.6 0x00007f6e6913f740 __libc_start_main + 240 30 test 0x0000000000404549 + 17737
I got the same error. Did you manage to solve this problem?
I struggled a bit with this kata as Swift is not my primary language, but I was able to solve it without any special crashes or errors (getting the spec right was the other thing though). So if you crash, I think the fault is somewhere in your solution.
Following line in stack trace:
6 libswiftSwiftOnoneSupport.so 0x00007f6e6b488e40 specialized Array.subscript.getter + 124
seems to suggest you perform some out-of-bounds read access on some array, so I would check operations on arrays with unexpectedly small amount of elements (for example, result of splitting an empty string, or something like that).I had the same problem, cause is some cases have less than 4 records
Nice example of BlackBox testing plus some elements of WhiteBox testing.
Expected: "Buy: 169850 Sell: 116000; Badly formed 1: CSCO 250.0 29 B ;", instead got: "Buy: 169850 Sell: 116000; Badly formed 1: CSCO 250.0 29 B ;" Well, i dont know what to do at this point..
You may be formatting the strings incorrctly eg. missing out whitespaces or putting in extra whitespaces.
I copy pasted them in a string matcher, and got a 100% match. And yeah, it does check for whitespaces. EDIT: Seems like several of g964's katas has some sort of problem with ruby
Maybe. There are 51 ruby completions though, so it seems like other people found it ok. I don't do ruby though so I can't check for you, sorry.
EDIT: There are some problems on Codewars about whitspace, because two whitespaces only show up as one for example. Maybe that is your problem?
Seems like thats the most likely problem, ill run it locally and check :) EDIT: Yup, finally got it through. Sorry to g964 for assuming its your mistake.
haha nice :)
[Python] Serious rounding problems in random tests. Try submitting more than once.
Hint to next users: use regex for numbers, don't bother using other functions. Floats can be in format ".5", the author doesn't mention this.
Not an issue, maybe a piece of advice for other Codewarriors:-)
I think having the outcome successful depending on rounding is an issue, it's always been on CW.
Do you think that 91 guys passed the Python kata with having luck when rounding or trying lots of time? The rounding of the reference solution is always the same. I am not the Python translator of this kata, but @ChristianECooper, you will find his posts far below and you can post under his name; maybe he will be notified.
I think that 90 other guys passed the Python kata like me: 2 minutes to get the almost-right values, 30 minutes trying to patch around what are details or missing information for the sake of the kata and yes, rounding and trying lots of time, until the right combination of random tests comes. :) As the 10013 code submissions for the only 503 times completed (plus the now 10 issues) show.
Same solution: once you fail after 12 tests, once you fail after 22, the next times you are successful. I beg to differ about not being an issue and have seen other users with beta katas going under 50% appreciation for such thing. Just my 2 cents.
This comment has been hidden.
Your
implode
andarray_map
function are wrong.Also, your code has rounding problems as description does not mention of doing so.
Instead, you should follow this:
As pointed out by other, this kata was very poorly explained. No indication of what constitues an invalid input was given. I spend ages figuring out manually what the expected output format was (whitespaces). Would have been fun if not for those problems.
In the description:
So negate this to have an invalid input.
In the description one clearly sees white spaces but at CW the test output removes extra white space, I didn't know that when I wrote this kata and now it is too late to change that:-(
I passed 15 tests and I have
Does anybody know what to do? Thanks!
Wow, about a week and still no reply. That's how coding is fun and that's how people who just started really enjoy it ... espeically when you spent hours on this kata for no reason. Very cool!
We don't see what You coded and in which language so we can't help You.
You explained poorly your problem.
Maybe try to print to console arguments and read carefully details of this kata.
A nice kata. Pretty straightforward, but the description could be tightened up in places:
0
for a double format, as usually this would be required.Well, I hate the fact that targeting author's white-space preferences, not listed in task description was tha main part of this kata. Apart from that it was actually quite nice regex exercise
This comment has been hidden.
There are no undefined in the arrays. Codewars has lots of problems now. Try later... I answer late but I have just been notified.
I have only one question... Why i see only one test case for development but when i run submit tests i don't see test cases witch don't passed. I am really don't understand some cases whitch not described in requirements and in tast cases....
Sounds like a lot of people had the same whitespace-related frustrations that I had. I've reported this as a bug in CodeWars.
https://github.com/Codewars/codewars.com/issues/269
Until that bug is fixed, I recommend making two changes in this kata as workarounds:
Include a warning in the instructions that whitespace differences will not show up in test results.
Change the default tests and acceptance tests to replace \s+ with a single space.
Yes, I know the bug is in CodeWars, rather than in this specific kata. However, this kata is mostly about formatting, and has odd placement of spaces. These are very frustrating attributes when the test results don't show spaces properly, so some workaround is necessary.
I will include a warning saying that due to Codewars whitespace differences will not always show up in test results. Workaround is always needed...
Perfect. Thank you, g964. :-)
i debug my code use the test8 input data, it's ok.but when i submit,it tests failed. where is the problem?
test8(OrdersSummaryTest) expected: but was:
input data: CAP 1300 .2 B, CLH16.NYM 50 56 S, OWW 1000 11 S, OGG 20 580.1 S concole in eclipse: Buy: 0 Sell: 11602; Badly formed 1: CAP 1300 .2 B ;Badly formed 2: CLH16.NYM 50 56 S ;Badly formed 3: OWW 1000 11 S ;
btw:I tried using Java.
Your answer in Eclipse is false: 1) you could see without code that "Buy" is false 2) you should have "Badly formed... " only once followed by the badly formed orders; read the description again please.
i find where it's the problem. ".2" is correct in this kata, it's ridiculous
In anglo-saxon world ".2" is common.
ok.thx very much..
This kata is obsurd. Finished it, but spent a lot of time wondering why linqpad displays 1 space, while copying and pasting it here displays 2? Test cases should focus on actual values rather than silly spaces.
This kata drove me mad!! Or more precisely, faffing around with whitespaces did!! I am honestly so happy this ordeal is over.
Can anyone tell what test3 expects?
I always get following output. Tried keeping & removing all whitespaces. No success. :(
I'm about to go crazy.
btw.: I tried using Java.
You can't have "expected: ". There must be something behind.
Unfortunately looks like I can. Don't know whether this is a bug in Codewars platform or somewhere else.
The output is exactly like this. For the other tests (except test6) I get some expected output if I change my sources. But not for number 3. Any hint?
Unless the "expected" value uses HTML tag openings (
<something>
). Which get used by some testing frameworks.Have a look at the output window source code. Right click, current frame, show source code. Copy the code here.
This comment has been hidden.
The square brackets show where you are wrong: you got a [5] instead of a [6].
This comment has been hidden.
You have a difference of
1
: a5
insted of a6
at the end of your number; maybe you could look at your rounding.Thanks, that finally was my issue. Stupid me - the rounding was already discussed quite a lot. Thanks for the support.
Thanks for the feedback!
The whitespace reqs on both input and output are ill-defined. I'm putting them here for good measure. Mark as a spoiler if you believe deriving input or output from the test cases is something you want people to learn from this kata.
Input:
Output without malformed orders:
Output with malformed orders:
I thank you for your effort! I am not sure that your caracterization of input is simple enough. One could say:
There should be some way of marking white space at Codewars. Thanks again!
Or you could provide a function that formats the stuff. By the way, I consider katas with less than 500 solutions still as "beta". I don't get why everyone approves katas these days before they have at least 100 solutions (depending on the difficulty).
That being said, I've got a solution for your whitespace problem. In your tests, add the following:
In dynamic languages (CS, Ruby, Python, JavaScript) and Hakell you have to print first, in JUnit-like frameworks, use
Before
or similar.Will add this to the codex later. (By the way, your kata was a prime example for this on GitHub).
I partly answered on Gitters.
Formatting the stuff is part of the kata I think but I should have asked for a simpler way of formating, only with some separator e.g
;
and without any space. Same thing for the input. BTW why doesn't Codewars use constantly a monospace family font for outputs? It would be more convenient for anyone, no need for "nice" font here!Raise your voice on GitHub. #55 and #159 need more attention for this.
Done.
This comment has been hidden.
Which language? It's not explicitely said but you got it! If there is nothing... it can only be empty. The problem is maybe with Codewars which don't put quotes?
Sorry, I forgot about the language. It's java.
When the input string is empty you get "expected" --> "Buy: 0 Sell: 0" but not an empty string as expected output.
I spent a lot of time messing around with white space issues. With that said, I really enjoyed this kata!
Hint: I ended up having to us lstrip
Why an issue? You passed the kata! It seems normal to have some work when passing a kata. What do you want from me? That I suppress all white spaces?:-)
Tests are too dependent on white space being correct. It is difficult to diagnose a white space issue because the test output apparently removes extra white space.
Here is an example:
In the above example, my code had an additional space before the semicolon, but the test output makes the actual and expected values appear identical.
It's not an issue for the kata but rather for CW and for you. I saw in your post below that you resolved your problem by running your code in a terminal. Do you run your code directly at CW? First thing to do: running your code in your machine; second: when you don't pass the tests look carefully at your program before thinking that there is something wrong in the tests. Think that in the last run of a loop the last white space could be too much. I consider the issue as resolved but you could send a bug report at CW in order that they better show white spaces.
My tests are failing even though the strings appear to match. I have even compared the string using the tool at http://www.textdiff.com/, and the strings show that they match.
Here is the failure message:
Here's the output again, lined up for easy comparison:
What am I missing?
I can't see any difference! Which language? Did you try several times? CW seems to have too much to do.
Ahem. You remember the discussion we just had over there on the other kata? :>. That's the other reason I don't like strings: You don't see whitespace errors in the output. One should probably file an issue (and I should add this drawback to the guide). Edit: It's already filed.
What about putting something like "-" instead of whitespaces in the resulting string?
That doesn't solve the underlying error. However, @JTorr needs to share her current solution. Maybe it's not the whitespace, but something else. Also, AFAIK, Jake needs an example in order to fix #55.
Slightly off-topic: an array of objects would be much more idiomatic in JS (other languages have similar features), like
Found the issue. I had an extra space. The test output was condensing the white space, so 2 spaces appeared to be 1. I diagnosed the issue by running my code in the terminal with a "puts" statement. After correcting the white space, my code passed all tests.
@bkaes: good idea but a bit too late for current-next kata:-(
test8 is vicious, a sample should be given for price
.2
This could be even more difficult if you test
2.
This comment has been hidden.
Really weird rounding issues, I am not really sure how to specifically express it though.
To help with the spacing issues, you should code format all input and output examples.
Example:
"GOOG 300 542.0 B"
Vs Example: "GOOG 300 542.0 B"And
"Buy: 263 Sell: 11802; Badly formed 2: CLH16.NYM 50 56 S ;OWW 1000 11 S ;"
"Buy: 100 Sell: 56041; Badly formed 1: ZNGA 1300 2.66 ;"
Vs
"Buy: 263 Sell: 11802; Badly formed 2: CLH16.NYM 50 56 S ;OWW 1000 11 S ;" "Buy: 100 Sell: 56041; Badly formed 1: ZNGA 1300 2.66 ;"
Done, thanks!
I have trouble with rounding
buy
andsell
values in Python.When I simply put the value into
%d
or useint(value)
orfloor(value)
, at some point for value 181846.0 I get error181845, should equal 181846
.If I use
round(value)
, at some point for value 12700.909 I get error12701, should equal 12700
.I managed to pass all tests by using
"%d" % (value + 10 ** -10)
but that's weird.It looks like there's a problem with tests (and kata description that's vague about what expected rounding is) that do not allow any reasonable straightforward approach to be used.
I would recommend using
round()
.@ChristianECooper: please, could you have a look?
OK, I've simplified the rounding, give it a try now! :)
It was
str(int(round(value * 100) / 100))
as there were some unusual rounding issues in the original tests, I've changed it tostr(int(round(value)))
for the sake of simplicity (and so that I don't have to explain odd and even rounding methods in the description... :D)Please conform and removed the issue flag if you're happy. :)
Works fine now, thanks!
I would also recommend replacing "b and s are 'double' formatted with no decimal" in the description with something like "b and s are rounded to integers".
I added: "rounded to integers". Thanks for the feddback!
Cool! Thanks for the nice kata. :)
Hi, I've added a Python translation, if you want to approve it, instructions for the approval process are here.
I just saw 2 of your 3 translations into Python (I wasn't notified except for the "Hidden Cubic Numbers"!). Sure I approved them! Thanks for your time. Maybe there are others?
I'm sure some are in the pipeline :)
I've just posted an issue about Python translation above, could you please look into it?
@jolaf: I didn't translate this kata into Python. I initiated it rather long ago in Java and C# but that's all. I think ChristianECooper will respond.
Should be fixed now!
hardes part is string formating with space or not space
Look carefully at given examples. You have lots of trouble today!:-) Did you finish the "Directions Reduction" kata?
It has worked here, not problem. I just say that the string formating is the hardes part :) I retry the Directions Reduction another time.
Rules for placing spaces are unclear. As written, space after comma is an error. As written, order (i.e. string between commas) should be placed in error list 'as is', but test cases add space before semicolon.
All my tests but test6 were success. What are you expecting in test6? I don't understand why this is the only one who is not working, its probably something silly. Everything is according to your instructions. Do you expect something when the entry is blank? Thanks!
I just solved. But I think you should add more examples or be more specific about what you want. Anyway it was a fun puzzle =)
You knew that at least you must return "Buy: b Sell: s" where b and s are 'double' formatted with no decimal, b representing the total price of bought stocks and s the total price of sold stocks:-) Thanks for the feedback!
This comment has been hidden.
As said in the description like the other tests: Test3 and Test6 expect a string in the form "Buy: b Sell: s" where b and s are 'double' formatted with no decimal, b representing the total price of bought stocks and s the total price of sold stocks so I don't understand why you got "expected: but was:". The alternative in some tests being: "Buy: b Sell: s; Badly formed nb: badly-formed 1st simple order ;badly-formed nth simple order ;" when orders are not well formatted. Maybe you could try anew, codewars seeming sometimes busy and tell me if you can complete the kata.
This comment has been hidden.
In all case it is said that you must return a string in the form : "Buy: b Sell: s", so it is also the case when the given string is empty ! (with b and s convenient). It is also said that: "To ease the stockbroker your task is to produce a string of type "Buy: b Sell: s" where b and s are 'double' formatted with no decimal" So if your result is "181845.99999999997" you have to take the usual rounding, no?
This comment has been hidden.
Yes as said in the examples of the description there are whitespaces before ";". Sometimes brokers don't know very well the rules of punctuation:-)
Could you add some messages in the test cases ? I am having a problem and my only output is :
So i have no ideas what my problem could be ! (and all the other test passed)
I don't see where your problem can be. As said in the details you have to report a string like this : ** "Buy: b Sell: s" ** where b and s are 'double' formatted with no decimal, b representing the total price of bought stocks and s the total price of sold stocks or like this : ** "Buy: b Sell: s; Badly formed nb: badly-formed 1st simple order ;badly-formed nth simple order ;" ** So in no test can the expected string be "". Maybe you have to look to a test that could give you a void string.