5 kyu

Mod4 Regex

703 of 1,931wthit56
Description
Loading description...
Regular Expressions
Strings
Fundamentals
  • Please sign in or sign up to leave a comment.
  • hobovsky Avatar

    This kata is a subject to deduplication process here: https://github.com/codewars/content-issues/issues/228.
    Please join the discussion to help us identify duplicate kata and retire them.

  • ahmet_popaj Avatar

    Fancy kata...

  • Ciprian Amza Avatar

    Nice kata! :D

  • elyasafe Avatar

    Very nice kata. I compiled a regex very quickly but the 'match' function in Python gave me hell, so I learned something new today - the difference between 'match' and 'search' regex methods in Python :)

  • seniorCrutchDeveloper Avatar

    I get "No module named 'codewars_test'", am I doing something wrong?

  • mmmbi Avatar

    This kata made me feel suicidal. +1 would recommend

  • Bleuplatine Avatar

    This comment has been hidden.

  • Expurple Avatar

    Good kata, enjoyed it

  • zen15at Avatar

    Has this kata been modified? The test suite uses the "match" method on a Python re.compile object, but match only checks for matches at the start of a string. I don't think that is what the kata is asking for.

    I used the "search" method, which scans the entire string, and sure enough it is failing only on the randomized cases where the target is embedded in the middle of the string whereas any of these randomized cases pass in the code on my machine.

  • javierelpianista Avatar

    Nice kata, it would be nicer if there was a way to read the input in each test.

  • idopshik Avatar

    g flag!!! in my node 10.15.12 it's absulutely important for a decent result but on CW - not really. - I've spent a lot of time to figure out that all the deal is g flag at the end.

  • Blind4Basics Avatar

    python:

    the assertion in the random tests is strictly equivalent to the use of Test.expect, which is definitely bad. => They need to be rewritten with a "true" use of assert_equals.

  • Nima155 Avatar

    "767d98ef-edca-436a-9ce0-d3d2bb9ad675[-518]debdcec6-5c93-4790-9bb0-083533e39aeb[913]53d03fc5-1e27-4521-a5e3-018c5f74dbe4[~129]" 518 is not divisible by 4, 913 isn't either and neither is 129.

  • tortar Avatar

    This comment has been hidden.

  • agustinzavala Avatar

    could someone please explain this:

    I got this from the tests: 2504592b-156a-43d0-8f01-414f1c0c3f35[-34]bb70f6cf-edf2-4b35-8d91-e8ecbba03a78[890]7221eab8-2e54-47d4-b62b-228605826dee[~870] was incorrect: False should equal True

    I don't understand why it should be true.. what's the number that's divisible by 4 here?

  • zse4rffb Avatar

    This comment has been hidden.

  • anter69 Avatar
    • kata title is slightly misleading: it's not mod4, but divisibility checking
    • there is a code-golf version of this kata (python, ruby)
  • KataSideKick Avatar

    C# Translation added.Please review and approve~

  • StephBecquart Avatar

    Hello, I think I now have a good grasp of this kata. I pass all the tests in Python (using Jupyter Notebook) but in Codewars the following test fails: "the beginning [-0] the end" as it produces no match (but it does produce a match in my Jupyter Notebook...). Please advise, would really like to get this kata completed.

  • minhkien1809 Avatar

    I must revisit here to say thank you, it has opened my mind about regexes, you links are really helpful! Keep up the good work!

  • KKOKU Avatar

    Need explanation! My code is not passing the all valid test. It is like it failled on "the beginning [-0] the end" and "~[4]" but my output is showing something different

    PYTHON output on valid and invalid tests: valid test <_sre.SRE_Match object; span=(0, 8), match='[+05620]'> <_sre.SRE_Match object; span=(0, 8), match='[005624]'> <_sre.SRE_Match object; span=(0, 8), match='[-05628]'> <_sre.SRE_Match object; span=(0, 8), match='[005632]'> <_sre.SRE_Match object; span=(0, 8), match='[555636]'> <_sre.SRE_Match object; span=(0, 8), match='[+05640]'> <_sre.SRE_Match object; span=(0, 8), match='[005600]'> <_sre.SRE_Match object; span=(14, 18), match='[-0]'> <_sre.SRE_Match object; span=(1, 4), match='[4]'> <_sre.SRE_Match object; span=(0, 4), match='[32]'> <_sre.SRE_Match object; span=(14, 17), match='[0]'> <_sre.SRE_Match object; span=(10, 19), match='[+002016]'> invalid test None None None None None None

    So i am confused as i understood we have simply to provide the regex expression

  • AcesOfGlory Avatar

    Very clever! Didn't realise regex could work in this way!

  • eldargit Avatar

    This comment has been hidden.

  • zebulan Avatar

    I enjoyed this kata, thanks wthit56!

    I have tried many regular expression problems before but not one like this. I actually learned something new because of it.

  • kmanxo Avatar

    This comment has been hidden.

  • abort Avatar

    I suggest making a function of it in the Java version, rather than refering to the Pattern. This will still make it hard and you do not have to solve it with DFA theory. Now you have to due to the Matcher class being final and thus unable to extend.

  • bmohanraj444 Avatar

    I am Super confused of what needs to be the output. Can someone explain me with an clear example?

  • cucubau3000 Avatar

    What should I understand from this: the beginning [-0] the end is valid, but no match was made.: False should equal True? I'm passing some tests, but not this one.

  • Tamuz Avatar

    Why would you ever want to do this? I feel like this encourages bad approaches to problem solving.

  • ecocode Avatar

    Hi, I am enjoying this kata but don't understand what you want the output to be? string 'valid' or 'invalid'?

  • jake-jake-jake Avatar

    This comment has been hidden.

  • MMMAAANNN Avatar

    I suggest adding a test for '[8]' (particularly to Python, as there is at least one solution which fails it).

  • mihirk Avatar

    If there is a competition for the worst solution, I think I will win that one without a doubt for this Kata. Ashamed of my solution post seeing everyone's. This was amazingly difficult. Brilliant Kata, lots to improve for me in these places. Damn and I thought my Regex was brilliant. :(

  • mandeepb Avatar

    Does the solution need to contain a Class? Or can I write a function?

  • nav-agarwal Avatar

    I keep getting "Submission timed out. Please try again.". Is it because my regex is inefficeint? I did ran timeit for 10000 strings and it took less than .02 secs.

    I am using Python.

  • Skrewtape Avatar

    This comment has been hidden.

  • Yasumoto Avatar

    This comment has been hidden.

  • jolaf Avatar

    Wonderful kata, thank you very much!

    Probably, CodeWars should consider adding regexp as a separate kata language. ;)

  • jacobb Avatar

    I must say that this would be much easier using binary. I had an idea for a slightly harder kata around the same concept: Digital Root of a Number using Regex. There are 10 equivalence classes to deal with, so it would result in a pretty massive regular expression, whereas there are only 4 equivalence classes with this one.

  • IVBakker Avatar

    I hate regex, they never do what I want.

    I think I will need help on that because I have difficulties to understand why isn't matching. First question is why when I'm testing on some online regex testing results are sometimes different. I'm using https://www.debuggex.com/ that is really great to visualize what you are doing but on some tests it wasn't matching here but it was there.

    Rest of the question in spoiler next

  • JS01 Avatar

    Give a few more examples in the example problems as edge cases - for instance, "sdfd[4]sdfdsf" should have a match. It is stated in the description that this is possibe, but it'd be more clear if listed as an example

  • Azuaron Avatar

    I've added a kata translation to Java (so few Java katas).

  • Grey Avatar

    Fun little kata. I have two small change proposals:

    1. The description could be clearer on the fact that it should recognize strings that contain at least one such number, although I understand the .test() comment and one of the examples are meant to convey this.
    2. The examples could be tagged with "valid" (the invalid ones are already tagged)

    The given tests already contain this information (therefore I have not tagged this as an issue), but I was genuinely confused reading just the description.

  • ZozoFouchtra Avatar

    This comment has been hidden.