5 kyu

Luck check

692 of 4,691SundaySalsa
Description
Loading description...
Strings
Mathematics
Puzzles
  • Please sign in or sign up to leave a comment.
  • tmrevolution Avatar

    For some reason, I was getting an error message that my Ruby code was not throwing an error when I pushed "Test" although my code had this line: raise ArgumentError, "string with illegal characters" if str.empty? || str.match?(/\D/). By commenting out this line, the test passed. However, it wouldn't pass when I pushed "Attempt". So, I removed the # to uncomment the error line before pushing "Attempt", and the code was accepted.

  • ejini战神 Avatar
    • No random tests in Ruby

    • Ruby 3.0 should be enabled

  • LyakhnitskiyDP Avatar

    The overall idea is quite interesting and unique. I have to admit, though, that the requirement of an exception as a possible output seems to me unjust and unnecessary, especially in context of a FP oriented language.

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • Tom H. Lautenbacher Avatar

    Ruby Tests are broken.

  • saudiGuy Avatar

    There should be more random tests for odd number of digits to avoid solutions like this.

  • SerhiyShamshetdinov Avatar

    I really remember this fun tradission from my childhood. But author did not tell the the most interesting part of the belief: when you have such ticket you should eat that ticket for luck to work !!! )))

  • ahmet_popaj Avatar

    It would have been tougher to figure out without reading the comments, though nice kata, I do not think it sucks.

  • dylanw0lv Avatar

    The invalid tests are not working properly. I tested the same string that it was saying should return False and it does in my IDE.

  • itstudent17 Avatar

    This comment has been hidden.

  • KiplandDynamite Avatar

    Having a little trouble with a particular test case. Test case "124X212", In this test case the middle character is not apart of the arithmetic required to return if the lucky string is true or false, and therefore does not throw a python error. Does anyone know how I should handle a case like this?

    Thanks

  • SamuK Avatar

    This comment has been hidden.

  • vailcolorado13 Avatar

    I leveled up to 3 kyu with this one!

  • melike23 Avatar

    something is off with the invalid tests,they are not properly working.

  • marblemar61e Avatar

    Such a trash kata which doesn't work correct in Python 3.10 here while in PyCharm it works correct

  • luke123adams Avatar

    This kata would've taken half as much time if the description explained that the middle digit of an odd-length string needs to be ignored. I spent ages trying to figure out if I was supposed to include the middle digit on the left or right side and finally realised you're supposed to ignore it completely. Instructions could do with being a lot clearer

  • ASchreiber Avatar

    Java translation https://www.codewars.com/kumite/6377c8af0ab4f00057e3580e?sel=6377c8af0ab4f00057e3580e

    Please approve it. Thank you. I also clarified and improved the instructions, as many people here have wished.

  • Rami.Sh Avatar

    "124X212" the only test case i'm having a problem with, i tried everything but it's not working, what's the catch? btw on Py, cheers.

  • Dbeck Avatar

    I think I've run into an issue. The "6F43E8" test case passes when I "test" my code, but if I "attempt" the problem, the "6F43E8" attempt case does not pass. Why would it pass on the "test" but not on the "attempt"? Every other attempt and test case pass.

  • KayleighWasTaken Avatar
  • mo.mo. Avatar

    that's fun!

    I ate a lot of lucky tickets.

    some of them were pretty tasty (:

  • Cloud Walker Avatar

    The usual ways of error handling for integers, etc.. will not work here. So do not use them unless you want to waste a lot of time like I did. Great kata!

  • LS2008 Avatar

    what's sneaky about this kata is that: it throws an invalid character at the middle of an odd len string e.g. "54L36", so that limits what you are doing... Thanks for the great kata.

  • mike2r Avatar

    Javascript:

    Couple of conditions mentioned in the description are not checked in the test cases

    1. no test checks for a 0 length string - description says should throw an error
    2. no test checks for an illegal character at the mid point in a string with an odd number of characters - description strongly implies this should throw an error
  • Alisher Khamidov Avatar

    JS: I have a problem with '6F43E8'. The test doesn't work right at attempt stage, please fix the test. I throw error of false - it doensn't pass.

  • Nangsky Avatar

    This comment has been hidden.

  • jazzdestructor Avatar

    This comment has been hidden.

  • MaxCherya Avatar

    This comment has been hidden.

  • NiceIceEyeS Avatar

    Why my kata is wrong if function return 'Error" for test example '64BC53?

  • SavioChiu Avatar

    This comment has been hidden.

  • AproXXX Avatar

    hello, in prerequisites basic test i have a error "It should give an error for invalid input: True should equal False" but code is fine, all another tests passed. Work with Python, what do i do wrong?

  • MaxCherya Avatar

    How 181 supposed to be true?

  • X-ray-design1 Avatar

    This comment has been hidden.

  • Unnamed Avatar

    It should throw errors for empty strings or ...

    Empty strings aren't tested in Rust.

  • anton.andreytsiv Avatar

    In what cases it should throw error? I throw error when ticket is '', or it contains one digit, or it contains only spaces, or it contains any symbols that are not Number, but I still cant get pass check. expected [Function] to throw an error

  • EvgKrm Avatar

    I’ve tried this kata with Python, and the main difficulty to me was that slice indices must be integers not float (in Python). And what a surprise I got, when I looked through the Best Practices and saw that some Solutions used float as slice indices, then of course the solution can be short and nice. The problem is, that I tried to solve this kata once again using the copy of Hacker Sakana’s solution, and of course it doesn’t work, while slice indices must be integers not float. Could anybody explain this to me? Thank you!

  • dragonbiketoursvn Avatar

    Ok, so if anyone is wondering why your JavaScript code is failing the tests for non-decimal strings it's because you're not actually supposed to throw an error (despite what the description says). In the event of an empty or non-decimal string simply return false.

  • laurelis24 Avatar

    yeah not an 5. But very nice kata anyway.

  • akar-0 Avatar
  • farhanaditya Avatar

    JS: Node v14 should be used along with its appropiate assertion tools (Mocha + Chai). Refer to this and this

  • farhanaditya Avatar

    I know old katas are mostly overranked, but this one is way past the line.

  • darkmain Avatar

    This comment has been hidden.

  • pavloslav Avatar

    (Python) My first solution sometimes passes and sometimes don't: it doesn't check the middle character. It should be checked if solution handles wrong middle character correctly (raises exception) on something like "123X204" and "353f429". Add this (or similar) to test cases please.

  • jeanfrancoishayon Avatar

    Hello, i used Try/except of Python

    My program give "False" for testing 2544470768F9

    but the test says :

    Testing for 2544470768F9 It should give an error for invalid input: True should equal False

    Is it forbiden to use Try/except ??

    OK I don't see : "It should give an error for invalid input",lambda: luck_check('6F43E8')) Curious....

  • fibonaccios Avatar

    Might be the easiest 5kyu I have seen so far. I guess it is too old right?

  • FArekkusu Avatar

    Python 3 should be enabled.

  • DavidBeevaMx Avatar

    I don't understand problem description, how this number is lucky: 17935 # 1 + 7 = 3 + 5, you are not adding 9 anywhere and do not mention nothing about this. Can anybody explain, please.

  • theru Avatar

    Please fix this error in test cases:

    • It should give an error for invalid input: True should equal False
    • Python
  • Darshan97 Avatar

    Old Katas are overranked damn

  • Voile Avatar

    JS: The error checking tests were completely bonkers and hence doesn't actually check for errors at all:

    Test.expectError('6F43E8') //wait what, the luckCheck function isn't even called here
    Test.expectError("It should work for random inputs too",luckCheck(teststr)); //wrong usage, see below
    

    The correct way to use expectError is to wrap it into another function, which the test fixture then execute things inside to catch possible errors:

    Test.expectError("It should work for random inputs too",function(){luckCheck(teststr);}); //this works
    
  • bestwebua Avatar

    Hey, @SandaySalsa! Description and Ruby test cases aren't clear! Or this kata like puzzle, guess what should be: luck_check('6F43E8') == false or luck_check('6F43E8') == 'Error' or end of program :) And luck_check('') in test cases will be an error.

    Yours sincerely, FridayBachata

  • WillLearn Avatar

    Ruby: on the test's if I had raise "Error" if (wrong type,etc)...then the tests would fail. But if I put return "Error" if (wrong type,etc) they passed. The opposite is true for final submission.

  • HerrWert Avatar

    When I detect a string containing a non-numeric character, I'm using "throw" in JavaScript, but the testing framework doesn't seem to think I'm raising an exception. What's going on?

  • gonzalo Avatar

    This comment has been hidden.

  • WillLearn Avatar

    (Ruby) cannot pass the invalid string input tests (only for submit, test button works). If I return 'error' or false, I still get: "The function somehow worked with wrong input"

    "6F43E8" "Error" The function somehow worked with wrong input "1234 " "Error" The function somehow worked with wrong input "" "Error" The function somehow worked with wrong input

  • Flonk Avatar

    Pretty sure the test cases are broken. Once you get to random testing, the tests expects you to return false on invalid input instead of throwing an error. Also the description should probably be more detailed about dropping the center character on input with odd length.

  • JustinCheng12345 Avatar

    This comment has been hidden.

  • marcsantiago Avatar

    This kata is misleading. It doensn't require you to have an even string, it requires that you split the string in half evenly, for example '12345' --> '12' and '45' omitting the center number, and then checking to see if the sums are equal.

  • 36rahu Avatar

    what shuold i return for invalid input.

  • GiacomoSorbi Avatar

    And translated into JS too ;)

  • GiacomoSorbi Avatar

    Translated it into Python: once approved, answer me on this message and I'll fix the issue with the example test cases and then translate it in JS too (if I do it now, having slightly modified the description, I fear it will cause some problem).

  • GiacomoSorbi Avatar

    IMPORTANT TO PEOPLE TRYING THIS KATA: the sample test cases are broken, so the third won't work; try hitting only the "submit" button and don't waste time wondering what's wrong with your code because of it.

    And I hope a mod fixes that soon :)

  • psyfungus Avatar

    Just be aware it checks string like "123 ", number + space. That is tricky part )) Have fun )))

  • ssritt Avatar

    Something seems amiss. When I developed a code that passed all the test cases, it failed in the submit. Furthermore, the 'best practice' code passes the submit, but fails the test cases.

  • piyush108 Avatar

    Not going through because of this....?!?!

    1234 The function somehow worked with wrong input

    Test Passed

  • StraDIVar Avatar

    It's strange but tests work differently when I click 'Run test' and 'Submit'. I had my tests failed with incorrect argument when I use raise unless ... but same tests had passed when I click 'Submit'!

  • ju73s Avatar

    I've handled 4 kind of errors and it worked!

    1. You have to check that there are only digits in your string
    2. You have to check that your argument is a string
    3. You have to check that your string is not empty
    4. You haev to check that the string's length is even
  • jnv Avatar

    This comment has been hidden.

  • mayuroks Avatar

    NO FUN !! This kata is doesnt tell you exactly what cases need to be covered. I just dont think its well defined. It should give cases when it passes, when it fails ans what exceptions are suposed to be raised

  • arieh Avatar

    Like others I have no idea how to get past the error cases. Please advise.

  • hafizio Avatar

    Is there any bug in the kata? It says NoMethodError for using Array#any?

    Maybe I'll try again later.

  • mtchavez Avatar

    The instructions can/should be more explicit when defining how errors should be handled It should handle errors for empty strings or strings which don't represent a decimal number. So far returning false or raising an Exception don't appear to get through the error test cases.

  • vasspilka Avatar

    I got the main right but with error hadling the below code is wrong... What am I missing..?

    raise ArgumentError, 'String is empty' if str.empty?
    raise ArgumentError, 'String is not numeric' if str.to_i == 0

  • shawabawa Avatar

    This comment has been hidden.

  • zishe Avatar

    "543970707"

    => true

    Test Failed: the output is wrong

    Error on submit.

  • hh9 Avatar

    When a solution fails a test, it would be helpful to display the input that caused the failure.

  • sahglie Avatar

    Test suite give wrong answer for invalid string

  • mweiss Avatar

    The example test cases you provide have incorrect results. Namely, the number you initially provide is not a valid lucky number, but the test treats it as one. And the second test has the same issue.