Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
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.
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.I'm sorry, but I still don't understand... ;-;
Aren't I supossed to create the logic behind it? How am I supossed to create the logic without making a function?
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 returnTrue
for multiples of 3, andFalse
otherwise (assumings
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 returnsTrue
for number0
andFalse
in all other cases).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
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
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...