Ad
  • Custom User Avatar

    You don't need a function. You could do it in an interpreter. The only logic is to write a regular expression that will match the pattern for binary numbers multiples of 3.

    Try to learn about regular expressions in Python. There are many easier katas available about that. If you know nothing about that this kata is not the right place to learn.

  • Custom User Avatar

    Aren't I supossed to create the logic behind it? How am I supossed to create the logic without making a function?

    This is exactly the point of this kata: realize the logic of the task not with a function, but with something else (namely, a regular expression pattern).
    You create a regular expression, and tests use it to verify whether it can realize the task.

    The kata is not as easy as just return parseInt(input) % 3 == 0. The task is not trivial and requires some knowledge about how regular expressions work, what they are based on, and how to use these facts to solve the task. If you do not know what regular expressions are, or you don't know how to use them in this kata, then don't worry - the first time I saw this kata I also went like "WTF how would this be even possible" but after studying the topic a bit I managed to connect all the dots and get things right. Just leave the kata for later, or search for help on the web, or on Codewars Discord. Someone might be able to nudge you in a right direction.

  • Custom User Avatar

    I'm sorry, but I still don't understand... ;-;

  • Custom User Avatar

    Aren't I supossed to create the logic behind it? How am I supossed to create the logic without making a function?

  • Custom User Avatar

    You must not write a function. You must write a regular expression and put it in PATTERN (inside the quotes). Then the tests compile it and check if it works fine.

    To test it locally, you must do like the tests: bool(PATTERN.match(s)) should return True for multiples of 3, and False otherwise (assuming s is the binary representation of the number tested). Don't forget to import the regular expression library: import re.

    For example, with PATTERN = re.compile(r'0'), you can see it doesn't work (this returns True for number 0 and False in all other cases).

  • Custom User Avatar

    I've tested my solution in pycharm and it works perfectly, the problem is I don't know how to add my code to the solution

  • Custom User Avatar

    I created a function that returns true or false, but I don't know how to add it in the current code: PATTERN = re.compile(r'')

    Could someone please explain how I post my function in this code so that the tests work

  • Custom User Avatar

    The function is suposed to return "True" if the number is divisable by 3 and "False" if it isn't. So that means your function is returning the wrong answer, it's probably not correct...