6 kyu

Ease the StockBroker

327 of 2,180g964
Description
Loading description...
Fundamentals
Strings
  • Please sign in or sign up to leave a comment.
  • artem-totality Avatar

    Regular expression lite kata)

  • Nusya Avatar

    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…'

  • saudiGuy Avatar
  • ejini战神 Avatar

    Crystal:

    • function name should use snake_case
  • ejini战神 Avatar

    Ruby:

    • function name should use snake_case

    • 3.0 should be enabled

  • shinthutz Avatar

    /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?

  • ejini战神 Avatar

    C#: method name should be PascalCase (Please refer to implementation of backward compatibility here )

  • PythonEnjoyer Avatar

    i have no clue what its asking

  • RustamNigmatullin Avatar

    a little bit difficult for 6 kyu

  • Splinter1984 Avatar

    in my opinion an empty string should be a bad result and be counted in the counter of Badly formed. it is logical

  • trashy_incel Avatar

    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.

  • ejini战神 Avatar

    Great kata ^^

  • eurydice5717 Avatar

    My sol passes fine but I don't submit as of now. Some remarks:

    • didn't see in instructions that the sums Sell and Buy are to be rounded to nearest int (not FLOORED...)
    • in the "bad order string" error output list, we have actually to trim the leading spaces of the bad entries. a Note to add ? Not very difficult but IMHO shoudl be ranked 5: string parsing/lexing/serializing/error detection/... and all the crap around...
  • HafintoN Avatar

    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?

  • sam3177 Avatar

    This comment has been hidden.

  • Ciprian Amza Avatar

    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'"

  • rbahlsten Avatar

    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.

  • Kees de Vreugd Avatar

    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.

  • kindofsweet Avatar

    I think that the description regarding the format of the buy and sell prices should be fixed.

    "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.

    This seems to indicate that the result should be truncated when the correct answer for the tests (in Python) should be rounded.

  • Rud1 Avatar

    Nice Kata ,funky spacing of punctuation ,though ...

  • HEXecutive Avatar

    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.

  • oleksiiB Avatar

    This comment has been hidden.

  • ArrGoN Avatar

    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"

  • FArekkusu Avatar
    test.describe("Empty")
    do("", "Buy: 0 Sell: 0")
    

    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.

  • raveneer Avatar

    needs round up/down description.

  • tlongeri Avatar

    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 expects Buy: 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 expects Buy: 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.

  • Voile Avatar

    Some languages don't have random tests, e.g Haskell.

  • The Force Avatar

    dang that was kinda really hard

  • Gianni65 Avatar

    This comment has been hidden.

  • Tue Avatar

    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.

  • RSynenko Avatar

    Idk why satisfaction rating of this kata is 75%. I enjoyed solving it and it wasn't hard. Nice kata.

  • Ronnehag Avatar

    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.

  • MrTony Avatar

    The 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.

  • TlylT Avatar

    For Python just round it with round(), as explained by the author in the comments buried below :-

  • yaa Avatar

    This comment has been hidden.

  • brandonw Avatar

    This comment has been hidden.

  • TeaJunk Avatar

    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

    ' CSCO 90 450 B, MY SPACE 78 12.8 S '
    Buy:  0
    Sell:  0
    Badly:  [CSCO 90 450 B MY SPACE 78 12.8 S]
    

    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 ;

  • tarekbadrshalaan Avatar

    [Golang]

    point1

    • first line package kat should be package kata

    point 2

    • there is clear instruction in the description Quote/space/Quantity/space/Price/space/Status
    • there is some test cases generated from "MY SPACE"

    so please try to remove this test case, or try to change the description.

    point 3

    • some how there is issue about using "math.Round" go pkg, the result is different from using "%.0f"
  • fjavierm Avatar

    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?

  • giurobrossi Avatar

    [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

  • eb110 Avatar

    Nice example of BlackBox testing plus some elements of WhiteBox testing.

  • hrrs01 Avatar

    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..

  • mmalkavian Avatar

    [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.

  • bigsee Avatar

    This comment has been hidden.

  • Nicau Avatar

    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.

  • mahoney Avatar

    I passed 15 tests and I have

    1. no idea how many tests there are
    2. I (usually) don't know what the error message was because you can't see the test and
    3. in this specific case I get this error message: Traceback: in in do in balance_statement ValueError: invalid literal for int() with base 10: '2648.64'

    Does anybody know what to do? Thanks!

  • wthit56 Avatar

    A nice kata. Pretty straightforward, but the description could be tightened up in places:

    • An explanation of what "buy" and "sell" is counting would be useful. It could be understood as the number of stocks traded or something.
    • You should say if we should stop processing when we find a badly formed order; from the examples, it looked like we just stop dead and print what we've got so far.
    • Would be nice to say you don't need a 0 for a double format, as usually this would be required.
    • Also, the "badly formed" format isn't clear.
  • trega Avatar

    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

  • yashaRO Avatar

    This comment has been hidden.

  • JoSaint13 Avatar

    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....

  • ericlavigne Avatar

    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:

    1. Include a warning in the instructions that whitespace differences will not show up in test results.

    2. 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.

  • BigQiu Avatar

    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 ;

  • Wingdings Avatar

    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.

  • ecocode Avatar

    This kata drove me mad!! Or more precisely, faffing around with whitespaces did!! I am honestly so happy this ordeal is over.

  • schwaerz Avatar

    Can anyone tell what test3 expects?

    I always get following output. Tried keeping & removing all whitespaces. No success. :(

    I'm about to go crazy.

    test3(OrdersSummaryTest)
      expected: but was:
    

    btw.: I tried using Java.

  • jacobb Avatar

    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:

    • I used any number of whitespace characters between non-whitespace elements, both for a single order and around commas delimiting multiple orders
    • It may be the case that I could have used single space characters between non-whitespace elements, not sure
    • It's otherwise well-defined

    Output without malformed orders:

    • "Buy:"
    • followed by a single space
    • followed by the rounded total price
    • followed by "Sell:"
    • followed by a single space
    • followed by the rounded total price

    Output with malformed orders:

    • Output as with no malformed orders
    • followed by a semicolon
    • followed by a single space
    • followed by "Badly formed"
    • followed by a single space
    • followed by the number of badly formed orders
    • followed by a colon
    • followed by a single space
    • followed by each malformed order string concatenated with a single space followed by a semicolon
  • user8648055 Avatar

    This comment has been hidden.

  • kevinhofmaenner Avatar

    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

  • JTorr Avatar

    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:

    #Buy: 169850 Sell: 116000; Badly formed 1: CSCO 250.0 29 B ; (test output: expected value)
    #Buy: 169850 Sell: 116000; Badly formed 1: CSCO 250.0 29 B ; (test output: actual value)
    #Buy: 169850 Sell: 116000; Badly formed 1: CSCO 250.0 29 B  ; (actual value, when code run in terminal)
    

    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.

  • JTorr Avatar

    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:

    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 ;"
    

    Here's the output again, lined up for easy comparison:

    Expected: "Buy: 169850 Sell: 116000; Badly formed 1: CSCO 250.0 29 B ;"
    Actual:   "Buy: 169850 Sell: 116000; Badly formed 1: CSCO 250.0 29 B ;"
    

    What am I missing?

  • tomao44 Avatar

    test8 is vicious, a sample should be given for price .2
    This could be even more difficult if you test 2.

  • iTZAvishay Avatar

    Really weird rounding issues, I am not really sure how to specifically express it though.

  • 5thWall Avatar

    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 ;"

  • jolaf Avatar

    I have trouble with rounding buy and sell values in Python.

    When I simply put the value into %d or use int(value) or floor(value), at some point for value 181846.0 I get error 181845, should equal 181846.

    If I use round(value), at some point for value 12700.909 I get error 12701, 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 Avatar

    Hi, I've added a Python translation, if you want to approve it, instructions for the approval process are here.

  • muehan Avatar

    hardes part is string formating with space or not space

  • Absurdated Avatar

    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.

  • Alanhslc Avatar

    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!

  • suuuzi Avatar

    This comment has been hidden.

  • suuuzi Avatar

    This comment has been hidden.

  • GaspardP Avatar

    Could you add some messages in the test cases ? I am having a problem and my only output is :

    test6(OrdersSummaryTest)
      expected: but was:
    

    So i have no ideas what my problem could be ! (and all the other test passed)