Datasets:

inputs
stringlengths
50
14k
targets
stringlengths
4
655k
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): if name != '': return f"Hello, {name.title()}!" else: return f"Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = 'World'): name = name.lower() return 'Hello, ' + name.title() + '!' if name != '' else 'Hello, World!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): if name == None or name == '': return f'Hello, World!' else: name = name.lower() name = name.capitalize() return f'Hello, {name}!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = None): if name == None or name =="": return "Hello, World!" else: name = name.lower() name = name.capitalize() return f"Hello, {name}!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name='World'): if len(name)==0: return "Hello, World!" retval = '' for i in range(len(name)): if i==0: retval += name[i].upper() else: retval += name[i].lower() return f"Hello, {retval}!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name='World'): # I don't understand why 'World' default name doesn't work here (it does locally), so I neet to add those two lines if not name: name = 'World' return 'Hello, ' + name.title() + '!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=""): return "Hello, {}".format(name[0].upper()+name[1:].lower()+"!") if len(name) > 0 else "Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=""): return "Hello, {}!".format((name or "World").title())
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
hello = lambda n = "World": "Hello, %s!" % (n.capitalize() if n != "" else "World")
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = 'World'): if name == '': name = 'World' return "Hello, {}!".format(name.lower().capitalize())
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = ""): if name != "": name = name.capitalize() return ("Hello, %s!" % name) else: return "Hello, World!" pass
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name='World'): if name in ('', ' '): name = 'World' return(f'Hello, {name.title()}!')
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): name = name.capitalize() if name == '': return ("Hello, World!") else: return ("Hello, {}!".format(name))
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): if name =='': txt = 'Hello, World!' return txt elif len(name) == 1: naam = name.upper() txt = f'Hello, {naam}!' elif len(name) > 1: naam = name[0].upper() + name[1:].lower() txt = f'Hello, {naam}!' else: txt = 'Hello, World!' return txt return txt
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = 'World'): return 'Hello, ' + (f'{name.lower().title()}!' if name else 'World!')
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = ''): if(name != ''): return "Hello, " + name.lower().title() + "!" return "Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = ""): n = name.lower().capitalize() if len(name) == 0: return "Hello, World!" else: return "Hello, {}!".format(n)
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=None): if name: return f"Hello, {name.lower().title()}!" else: return f"Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=""): return f"Hello, {(name.lower().title() if name else 'World')}!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): return "Hello, World!" if name == '' else "Hello, "+ name[0].upper() + name[1:len(name)].lower() + "!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = "World"): #check if we passed empty string '' if len(name) == 0: return "Hello, World!" else: new_name = name[0].upper() + name[1:].lower() return "Hello, " + new_name + "!"
According to Gary Chapman, marriage counselor and the author of ["The Five Love Languages"](https://en.wikipedia.org/wiki/The_Five_Love_Languages) books, there are five major ways to express our love towards someone: *words of affirmation, quality time, gifts, acts of service,* and *physical touch*. These are called the love languages. Usually, everyone has a main language: the one that he/she "speaks" and understands best. In a relationship, it's import to find your partner's main love language, so that you get along better with each other. ## Your task Unfortunately, your relationship got worse lately... After a long discussion with your partner, you agreed to give yourself a few weeks to improve it, otherwise you split up... You will be given a `partner` instance, and `n` weeks. The `partner` has a `.response` method, and the responses may be: `"positive"` or `"neutral"`. You can try to get a response once a day, thus you have `n * 7` tries in total to find the main love language of your partner! ```if-not:haskell The love languages are: `"words", "acts", "gifts", "time", "touch"` (available predefined as `LOVE_LANGUAGES`) ``` ```if:haskell The love languages are: `Words, Acts, Gifts, Time, Touch` ( available `Preloaded` as `LoveLanguage` ) ``` Note: your partner may (and will) sometimes give a positive response to any love language ("false positive"), but the main one has a much higher possibility. On the other hand, you may get a neutral response even for the main language, but with a low possibility ("false negative"). There will be 50 tests. Although it's difficult to fail, in case you get unlucky, just run the tests again. After all, a few weeks may not be enough... ## Examples ```python main love language: "words" partner.response("words") ==> "positive" partner.response("acts") ==> "neutral" partner.response("words") ==> "positive" partner.response("time") ==> "neutral" partner.response("acts") ==> "positive" # false positive partner.response("gifts") ==> "neutral" partner.response("words") ==> "neutral" # false negative etc. ``` ~~~if:haskell ## Notes `Preloaded` exports the following: ~~~ Happy coding, and **DO** try this at home! :-) --- ## My other katas If you enjoyed this kata then please try [my other katas](https://www.codewars.com/collections/katas-created-by-anter69)! :-) #### *Translations are welcome!*
import random def love_language(partner, weeks): rst = [0,0,0,0,0] for i in range (0, weeks*7): if(partner.response(LOVE_LANGUAGES[i%5]) == 'positive'): rst[i%5]+=1 return LOVE_LANGUAGES[rst.index(max(rst))]
According to Gary Chapman, marriage counselor and the author of ["The Five Love Languages"](https://en.wikipedia.org/wiki/The_Five_Love_Languages) books, there are five major ways to express our love towards someone: *words of affirmation, quality time, gifts, acts of service,* and *physical touch*. These are called the love languages. Usually, everyone has a main language: the one that he/she "speaks" and understands best. In a relationship, it's import to find your partner's main love language, so that you get along better with each other. ## Your task Unfortunately, your relationship got worse lately... After a long discussion with your partner, you agreed to give yourself a few weeks to improve it, otherwise you split up... You will be given a `partner` instance, and `n` weeks. The `partner` has a `.response` method, and the responses may be: `"positive"` or `"neutral"`. You can try to get a response once a day, thus you have `n * 7` tries in total to find the main love language of your partner! ```if-not:haskell The love languages are: `"words", "acts", "gifts", "time", "touch"` (available predefined as `LOVE_LANGUAGES`) ``` ```if:haskell The love languages are: `Words, Acts, Gifts, Time, Touch` ( available `Preloaded` as `LoveLanguage` ) ``` Note: your partner may (and will) sometimes give a positive response to any love language ("false positive"), but the main one has a much higher possibility. On the other hand, you may get a neutral response even for the main language, but with a low possibility ("false negative"). There will be 50 tests. Although it's difficult to fail, in case you get unlucky, just run the tests again. After all, a few weeks may not be enough... ## Examples ```python main love language: "words" partner.response("words") ==> "positive" partner.response("acts") ==> "neutral" partner.response("words") ==> "positive" partner.response("time") ==> "neutral" partner.response("acts") ==> "positive" # false positive partner.response("gifts") ==> "neutral" partner.response("words") ==> "neutral" # false negative etc. ``` ~~~if:haskell ## Notes `Preloaded` exports the following: ~~~ Happy coding, and **DO** try this at home! :-) --- ## My other katas If you enjoyed this kata then please try [my other katas](https://www.codewars.com/collections/katas-created-by-anter69)! :-) #### *Translations are welcome!*
def love_language(partner, weeks): n = len(LOVE_LANGUAGES) count = [0] * n for i in range (0, weeks * 7): response = partner.response(LOVE_LANGUAGES[i % n]) count[i % n] += 1 if response == 'positive' else 0 return LOVE_LANGUAGES[count.index(max(count))]
According to Gary Chapman, marriage counselor and the author of ["The Five Love Languages"](https://en.wikipedia.org/wiki/The_Five_Love_Languages) books, there are five major ways to express our love towards someone: *words of affirmation, quality time, gifts, acts of service,* and *physical touch*. These are called the love languages. Usually, everyone has a main language: the one that he/she "speaks" and understands best. In a relationship, it's import to find your partner's main love language, so that you get along better with each other. ## Your task Unfortunately, your relationship got worse lately... After a long discussion with your partner, you agreed to give yourself a few weeks to improve it, otherwise you split up... You will be given a `partner` instance, and `n` weeks. The `partner` has a `.response` method, and the responses may be: `"positive"` or `"neutral"`. You can try to get a response once a day, thus you have `n * 7` tries in total to find the main love language of your partner! ```if-not:haskell The love languages are: `"words", "acts", "gifts", "time", "touch"` (available predefined as `LOVE_LANGUAGES`) ``` ```if:haskell The love languages are: `Words, Acts, Gifts, Time, Touch` ( available `Preloaded` as `LoveLanguage` ) ``` Note: your partner may (and will) sometimes give a positive response to any love language ("false positive"), but the main one has a much higher possibility. On the other hand, you may get a neutral response even for the main language, but with a low possibility ("false negative"). There will be 50 tests. Although it's difficult to fail, in case you get unlucky, just run the tests again. After all, a few weeks may not be enough... ## Examples ```python main love language: "words" partner.response("words") ==> "positive" partner.response("acts") ==> "neutral" partner.response("words") ==> "positive" partner.response("time") ==> "neutral" partner.response("acts") ==> "positive" # false positive partner.response("gifts") ==> "neutral" partner.response("words") ==> "neutral" # false negative etc. ``` ~~~if:haskell ## Notes `Preloaded` exports the following: ~~~ Happy coding, and **DO** try this at home! :-) --- ## My other katas If you enjoyed this kata then please try [my other katas](https://www.codewars.com/collections/katas-created-by-anter69)! :-) #### *Translations are welcome!*
def love_language(partner, weeks): return max(LOVE_LANGUAGES, key=lambda word:sum(partner.response(word) == "positive" for _ in range(weeks)))
According to Gary Chapman, marriage counselor and the author of ["The Five Love Languages"](https://en.wikipedia.org/wiki/The_Five_Love_Languages) books, there are five major ways to express our love towards someone: *words of affirmation, quality time, gifts, acts of service,* and *physical touch*. These are called the love languages. Usually, everyone has a main language: the one that he/she "speaks" and understands best. In a relationship, it's import to find your partner's main love language, so that you get along better with each other. ## Your task Unfortunately, your relationship got worse lately... After a long discussion with your partner, you agreed to give yourself a few weeks to improve it, otherwise you split up... You will be given a `partner` instance, and `n` weeks. The `partner` has a `.response` method, and the responses may be: `"positive"` or `"neutral"`. You can try to get a response once a day, thus you have `n * 7` tries in total to find the main love language of your partner! ```if-not:haskell The love languages are: `"words", "acts", "gifts", "time", "touch"` (available predefined as `LOVE_LANGUAGES`) ``` ```if:haskell The love languages are: `Words, Acts, Gifts, Time, Touch` ( available `Preloaded` as `LoveLanguage` ) ``` Note: your partner may (and will) sometimes give a positive response to any love language ("false positive"), but the main one has a much higher possibility. On the other hand, you may get a neutral response even for the main language, but with a low possibility ("false negative"). There will be 50 tests. Although it's difficult to fail, in case you get unlucky, just run the tests again. After all, a few weeks may not be enough... ## Examples ```python main love language: "words" partner.response("words") ==> "positive" partner.response("acts") ==> "neutral" partner.response("words") ==> "positive" partner.response("time") ==> "neutral" partner.response("acts") ==> "positive" # false positive partner.response("gifts") ==> "neutral" partner.response("words") ==> "neutral" # false negative etc. ``` ~~~if:haskell ## Notes `Preloaded` exports the following: ~~~ Happy coding, and **DO** try this at home! :-) --- ## My other katas If you enjoyed this kata then please try [my other katas](https://www.codewars.com/collections/katas-created-by-anter69)! :-) #### *Translations are welcome!*
from collections import Counter def love_language(partner, weeks): c = Counter() for i in range(7 * weeks // 5): for lang in ["words", "acts", "gifts", "time", "touch"]: if partner.response(lang) == 'positive': c[lang] += 1 return max(c, key=c.get)
According to Gary Chapman, marriage counselor and the author of ["The Five Love Languages"](https://en.wikipedia.org/wiki/The_Five_Love_Languages) books, there are five major ways to express our love towards someone: *words of affirmation, quality time, gifts, acts of service,* and *physical touch*. These are called the love languages. Usually, everyone has a main language: the one that he/she "speaks" and understands best. In a relationship, it's import to find your partner's main love language, so that you get along better with each other. ## Your task Unfortunately, your relationship got worse lately... After a long discussion with your partner, you agreed to give yourself a few weeks to improve it, otherwise you split up... You will be given a `partner` instance, and `n` weeks. The `partner` has a `.response` method, and the responses may be: `"positive"` or `"neutral"`. You can try to get a response once a day, thus you have `n * 7` tries in total to find the main love language of your partner! ```if-not:haskell The love languages are: `"words", "acts", "gifts", "time", "touch"` (available predefined as `LOVE_LANGUAGES`) ``` ```if:haskell The love languages are: `Words, Acts, Gifts, Time, Touch` ( available `Preloaded` as `LoveLanguage` ) ``` Note: your partner may (and will) sometimes give a positive response to any love language ("false positive"), but the main one has a much higher possibility. On the other hand, you may get a neutral response even for the main language, but with a low possibility ("false negative"). There will be 50 tests. Although it's difficult to fail, in case you get unlucky, just run the tests again. After all, a few weeks may not be enough... ## Examples ```python main love language: "words" partner.response("words") ==> "positive" partner.response("acts") ==> "neutral" partner.response("words") ==> "positive" partner.response("time") ==> "neutral" partner.response("acts") ==> "positive" # false positive partner.response("gifts") ==> "neutral" partner.response("words") ==> "neutral" # false negative etc. ``` ~~~if:haskell ## Notes `Preloaded` exports the following: ~~~ Happy coding, and **DO** try this at home! :-) --- ## My other katas If you enjoyed this kata then please try [my other katas](https://www.codewars.com/collections/katas-created-by-anter69)! :-) #### *Translations are welcome!*
def love_language(partner, weeks): d = {'words': 0, 'acts': 0, 'gifts': 0, 'time': 0, 'touch': 0} for w in range(weeks): for k in d.keys(): if partner.response(k) == 'positive': d[k] += 1 return max(d, key=d.get)
According to Gary Chapman, marriage counselor and the author of ["The Five Love Languages"](https://en.wikipedia.org/wiki/The_Five_Love_Languages) books, there are five major ways to express our love towards someone: *words of affirmation, quality time, gifts, acts of service,* and *physical touch*. These are called the love languages. Usually, everyone has a main language: the one that he/she "speaks" and understands best. In a relationship, it's import to find your partner's main love language, so that you get along better with each other. ## Your task Unfortunately, your relationship got worse lately... After a long discussion with your partner, you agreed to give yourself a few weeks to improve it, otherwise you split up... You will be given a `partner` instance, and `n` weeks. The `partner` has a `.response` method, and the responses may be: `"positive"` or `"neutral"`. You can try to get a response once a day, thus you have `n * 7` tries in total to find the main love language of your partner! ```if-not:haskell The love languages are: `"words", "acts", "gifts", "time", "touch"` (available predefined as `LOVE_LANGUAGES`) ``` ```if:haskell The love languages are: `Words, Acts, Gifts, Time, Touch` ( available `Preloaded` as `LoveLanguage` ) ``` Note: your partner may (and will) sometimes give a positive response to any love language ("false positive"), but the main one has a much higher possibility. On the other hand, you may get a neutral response even for the main language, but with a low possibility ("false negative"). There will be 50 tests. Although it's difficult to fail, in case you get unlucky, just run the tests again. After all, a few weeks may not be enough... ## Examples ```python main love language: "words" partner.response("words") ==> "positive" partner.response("acts") ==> "neutral" partner.response("words") ==> "positive" partner.response("time") ==> "neutral" partner.response("acts") ==> "positive" # false positive partner.response("gifts") ==> "neutral" partner.response("words") ==> "neutral" # false negative etc. ``` ~~~if:haskell ## Notes `Preloaded` exports the following: ~~~ Happy coding, and **DO** try this at home! :-) --- ## My other katas If you enjoyed this kata then please try [my other katas](https://www.codewars.com/collections/katas-created-by-anter69)! :-) #### *Translations are welcome!*
def love_language(p, w): return max(LOVE_LANGUAGES, key=lambda x: sorted(map(p.response, w * [x])))
According to Gary Chapman, marriage counselor and the author of ["The Five Love Languages"](https://en.wikipedia.org/wiki/The_Five_Love_Languages) books, there are five major ways to express our love towards someone: *words of affirmation, quality time, gifts, acts of service,* and *physical touch*. These are called the love languages. Usually, everyone has a main language: the one that he/she "speaks" and understands best. In a relationship, it's import to find your partner's main love language, so that you get along better with each other. ## Your task Unfortunately, your relationship got worse lately... After a long discussion with your partner, you agreed to give yourself a few weeks to improve it, otherwise you split up... You will be given a `partner` instance, and `n` weeks. The `partner` has a `.response` method, and the responses may be: `"positive"` or `"neutral"`. You can try to get a response once a day, thus you have `n * 7` tries in total to find the main love language of your partner! ```if-not:haskell The love languages are: `"words", "acts", "gifts", "time", "touch"` (available predefined as `LOVE_LANGUAGES`) ``` ```if:haskell The love languages are: `Words, Acts, Gifts, Time, Touch` ( available `Preloaded` as `LoveLanguage` ) ``` Note: your partner may (and will) sometimes give a positive response to any love language ("false positive"), but the main one has a much higher possibility. On the other hand, you may get a neutral response even for the main language, but with a low possibility ("false negative"). There will be 50 tests. Although it's difficult to fail, in case you get unlucky, just run the tests again. After all, a few weeks may not be enough... ## Examples ```python main love language: "words" partner.response("words") ==> "positive" partner.response("acts") ==> "neutral" partner.response("words") ==> "positive" partner.response("time") ==> "neutral" partner.response("acts") ==> "positive" # false positive partner.response("gifts") ==> "neutral" partner.response("words") ==> "neutral" # false negative etc. ``` ~~~if:haskell ## Notes `Preloaded` exports the following: ~~~ Happy coding, and **DO** try this at home! :-) --- ## My other katas If you enjoyed this kata then please try [my other katas](https://www.codewars.com/collections/katas-created-by-anter69)! :-) #### *Translations are welcome!*
def love_language(partner, weeks: int): import random for l in LOVE_LANGUAGES: random.seed(3) # Discard false positives and false negatives if partner.response(l) == 'positive': return l
According to Gary Chapman, marriage counselor and the author of ["The Five Love Languages"](https://en.wikipedia.org/wiki/The_Five_Love_Languages) books, there are five major ways to express our love towards someone: *words of affirmation, quality time, gifts, acts of service,* and *physical touch*. These are called the love languages. Usually, everyone has a main language: the one that he/she "speaks" and understands best. In a relationship, it's import to find your partner's main love language, so that you get along better with each other. ## Your task Unfortunately, your relationship got worse lately... After a long discussion with your partner, you agreed to give yourself a few weeks to improve it, otherwise you split up... You will be given a `partner` instance, and `n` weeks. The `partner` has a `.response` method, and the responses may be: `"positive"` or `"neutral"`. You can try to get a response once a day, thus you have `n * 7` tries in total to find the main love language of your partner! ```if-not:haskell The love languages are: `"words", "acts", "gifts", "time", "touch"` (available predefined as `LOVE_LANGUAGES`) ``` ```if:haskell The love languages are: `Words, Acts, Gifts, Time, Touch` ( available `Preloaded` as `LoveLanguage` ) ``` Note: your partner may (and will) sometimes give a positive response to any love language ("false positive"), but the main one has a much higher possibility. On the other hand, you may get a neutral response even for the main language, but with a low possibility ("false negative"). There will be 50 tests. Although it's difficult to fail, in case you get unlucky, just run the tests again. After all, a few weeks may not be enough... ## Examples ```python main love language: "words" partner.response("words") ==> "positive" partner.response("acts") ==> "neutral" partner.response("words") ==> "positive" partner.response("time") ==> "neutral" partner.response("acts") ==> "positive" # false positive partner.response("gifts") ==> "neutral" partner.response("words") ==> "neutral" # false negative etc. ``` ~~~if:haskell ## Notes `Preloaded` exports the following: ~~~ Happy coding, and **DO** try this at home! :-) --- ## My other katas If you enjoyed this kata then please try [my other katas](https://www.codewars.com/collections/katas-created-by-anter69)! :-) #### *Translations are welcome!*
import itertools as it def love_language(partner, weeks): for lang in it.cycle(LOVE_LANGUAGES): if partner.response(lang) == "positive": if partner.response(lang) == "positive": if partner.response(lang) == "positive": return lang
According to Gary Chapman, marriage counselor and the author of ["The Five Love Languages"](https://en.wikipedia.org/wiki/The_Five_Love_Languages) books, there are five major ways to express our love towards someone: *words of affirmation, quality time, gifts, acts of service,* and *physical touch*. These are called the love languages. Usually, everyone has a main language: the one that he/she "speaks" and understands best. In a relationship, it's import to find your partner's main love language, so that you get along better with each other. ## Your task Unfortunately, your relationship got worse lately... After a long discussion with your partner, you agreed to give yourself a few weeks to improve it, otherwise you split up... You will be given a `partner` instance, and `n` weeks. The `partner` has a `.response` method, and the responses may be: `"positive"` or `"neutral"`. You can try to get a response once a day, thus you have `n * 7` tries in total to find the main love language of your partner! ```if-not:haskell The love languages are: `"words", "acts", "gifts", "time", "touch"` (available predefined as `LOVE_LANGUAGES`) ``` ```if:haskell The love languages are: `Words, Acts, Gifts, Time, Touch` ( available `Preloaded` as `LoveLanguage` ) ``` Note: your partner may (and will) sometimes give a positive response to any love language ("false positive"), but the main one has a much higher possibility. On the other hand, you may get a neutral response even for the main language, but with a low possibility ("false negative"). There will be 50 tests. Although it's difficult to fail, in case you get unlucky, just run the tests again. After all, a few weeks may not be enough... ## Examples ```python main love language: "words" partner.response("words") ==> "positive" partner.response("acts") ==> "neutral" partner.response("words") ==> "positive" partner.response("time") ==> "neutral" partner.response("acts") ==> "positive" # false positive partner.response("gifts") ==> "neutral" partner.response("words") ==> "neutral" # false negative etc. ``` ~~~if:haskell ## Notes `Preloaded` exports the following: ~~~ Happy coding, and **DO** try this at home! :-) --- ## My other katas If you enjoyed this kata then please try [my other katas](https://www.codewars.com/collections/katas-created-by-anter69)! :-) #### *Translations are welcome!*
from collections import Counter from itertools import cycle, islice RESPONSE_POS = 'positive' WEEK_LEN = 7 def love_language (partner, weeks): def positive (response): return response == RESPONSE_POS queries = islice(cycle(LOVE_LANGUAGES), weeks * WEEK_LEN) tests = ((query, partner.response(query)) for query in queries) stats = Counter(query for query, response in tests if positive(response)) [(winner, count)] = stats.most_common(1) return winner
According to Gary Chapman, marriage counselor and the author of ["The Five Love Languages"](https://en.wikipedia.org/wiki/The_Five_Love_Languages) books, there are five major ways to express our love towards someone: *words of affirmation, quality time, gifts, acts of service,* and *physical touch*. These are called the love languages. Usually, everyone has a main language: the one that he/she "speaks" and understands best. In a relationship, it's import to find your partner's main love language, so that you get along better with each other. ## Your task Unfortunately, your relationship got worse lately... After a long discussion with your partner, you agreed to give yourself a few weeks to improve it, otherwise you split up... You will be given a `partner` instance, and `n` weeks. The `partner` has a `.response` method, and the responses may be: `"positive"` or `"neutral"`. You can try to get a response once a day, thus you have `n * 7` tries in total to find the main love language of your partner! ```if-not:haskell The love languages are: `"words", "acts", "gifts", "time", "touch"` (available predefined as `LOVE_LANGUAGES`) ``` ```if:haskell The love languages are: `Words, Acts, Gifts, Time, Touch` ( available `Preloaded` as `LoveLanguage` ) ``` Note: your partner may (and will) sometimes give a positive response to any love language ("false positive"), but the main one has a much higher possibility. On the other hand, you may get a neutral response even for the main language, but with a low possibility ("false negative"). There will be 50 tests. Although it's difficult to fail, in case you get unlucky, just run the tests again. After all, a few weeks may not be enough... ## Examples ```python main love language: "words" partner.response("words") ==> "positive" partner.response("acts") ==> "neutral" partner.response("words") ==> "positive" partner.response("time") ==> "neutral" partner.response("acts") ==> "positive" # false positive partner.response("gifts") ==> "neutral" partner.response("words") ==> "neutral" # false negative etc. ``` ~~~if:haskell ## Notes `Preloaded` exports the following: ~~~ Happy coding, and **DO** try this at home! :-) --- ## My other katas If you enjoyed this kata then please try [my other katas](https://www.codewars.com/collections/katas-created-by-anter69)! :-) #### *Translations are welcome!*
from itertools import cycle import operator def love_language(partner, weeks): counts = {} for l in LOVE_LANGUAGES: counts[l] = 0 for lang,week in zip(cycle(LOVE_LANGUAGES), range(weeks * 7)): counts[lang] += int(partner.response(lang) == "positive") return max(counts.items(), key=operator.itemgetter(1))[0]
My third kata, write a function `check_generator` that examines the status of a Python generator expression `gen` and returns `'Created'`, `'Started'` or `'Finished'`. For example: `gen = (i for i in range(1))` >>> returns `'Created'` (the generator has been initiated) `gen = (i for i in range(1)); next(gen, None)` >>> returns `'Started'` (the generator has yielded a value) `gen = (i for i in range(1)); next(gen, None); next(gen, None)` >>> returns `'Finished'` (the generator has been exhuasted) For an introduction to Python generators, read: https://wiki.python.org/moin/Generators. Please do vote and rank the kata, and provide any feedback. Hint: you can solve this if you know the right module to use.
def check_generator(gen): if gen.gi_frame is None: return "Finished" if gen.gi_frame.f_lasti == -1: return "Created" return "Started"
My third kata, write a function `check_generator` that examines the status of a Python generator expression `gen` and returns `'Created'`, `'Started'` or `'Finished'`. For example: `gen = (i for i in range(1))` >>> returns `'Created'` (the generator has been initiated) `gen = (i for i in range(1)); next(gen, None)` >>> returns `'Started'` (the generator has yielded a value) `gen = (i for i in range(1)); next(gen, None); next(gen, None)` >>> returns `'Finished'` (the generator has been exhuasted) For an introduction to Python generators, read: https://wiki.python.org/moin/Generators. Please do vote and rank the kata, and provide any feedback. Hint: you can solve this if you know the right module to use.
from inspect import getgeneratorstate as gt d = {'GEN_CREATED':'Created', 'GEN_SUSPENDED':'Started'} def check_generator(gen): return d.get(gt(gen), 'Finished')
My third kata, write a function `check_generator` that examines the status of a Python generator expression `gen` and returns `'Created'`, `'Started'` or `'Finished'`. For example: `gen = (i for i in range(1))` >>> returns `'Created'` (the generator has been initiated) `gen = (i for i in range(1)); next(gen, None)` >>> returns `'Started'` (the generator has yielded a value) `gen = (i for i in range(1)); next(gen, None); next(gen, None)` >>> returns `'Finished'` (the generator has been exhuasted) For an introduction to Python generators, read: https://wiki.python.org/moin/Generators. Please do vote and rank the kata, and provide any feedback. Hint: you can solve this if you know the right module to use.
import inspect def check_generator(gen): state = inspect.getgeneratorstate(gen) return [['Created','Started'][state=='GEN_SUSPENDED'],'Finished'][state=='GEN_CLOSED']
My third kata, write a function `check_generator` that examines the status of a Python generator expression `gen` and returns `'Created'`, `'Started'` or `'Finished'`. For example: `gen = (i for i in range(1))` >>> returns `'Created'` (the generator has been initiated) `gen = (i for i in range(1)); next(gen, None)` >>> returns `'Started'` (the generator has yielded a value) `gen = (i for i in range(1)); next(gen, None); next(gen, None)` >>> returns `'Finished'` (the generator has been exhuasted) For an introduction to Python generators, read: https://wiki.python.org/moin/Generators. Please do vote and rank the kata, and provide any feedback. Hint: you can solve this if you know the right module to use.
from inspect import getgeneratorstate def check_generator(gen): _ = getgeneratorstate(gen) if _ == "GEN_CREATED": return "Created" if _ == "GEN_RUNNING" or _ == "GEN_SUSPENDED": return "Started" else: return "Finished"
My third kata, write a function `check_generator` that examines the status of a Python generator expression `gen` and returns `'Created'`, `'Started'` or `'Finished'`. For example: `gen = (i for i in range(1))` >>> returns `'Created'` (the generator has been initiated) `gen = (i for i in range(1)); next(gen, None)` >>> returns `'Started'` (the generator has yielded a value) `gen = (i for i in range(1)); next(gen, None); next(gen, None)` >>> returns `'Finished'` (the generator has been exhuasted) For an introduction to Python generators, read: https://wiki.python.org/moin/Generators. Please do vote and rank the kata, and provide any feedback. Hint: you can solve this if you know the right module to use.
from inspect import getgeneratorstate def check_generator(g): return {'R':'Created','U':'Started','L':'Finished'}[getgeneratorstate(g)[5]]
My third kata, write a function `check_generator` that examines the status of a Python generator expression `gen` and returns `'Created'`, `'Started'` or `'Finished'`. For example: `gen = (i for i in range(1))` >>> returns `'Created'` (the generator has been initiated) `gen = (i for i in range(1)); next(gen, None)` >>> returns `'Started'` (the generator has yielded a value) `gen = (i for i in range(1)); next(gen, None); next(gen, None)` >>> returns `'Finished'` (the generator has been exhuasted) For an introduction to Python generators, read: https://wiki.python.org/moin/Generators. Please do vote and rank the kata, and provide any feedback. Hint: you can solve this if you know the right module to use.
def check_generator(gen): if not gen.gi_frame: return "Finished" if gen.gi_frame.f_lasti == -1: return "Created" return "Started"
My third kata, write a function `check_generator` that examines the status of a Python generator expression `gen` and returns `'Created'`, `'Started'` or `'Finished'`. For example: `gen = (i for i in range(1))` >>> returns `'Created'` (the generator has been initiated) `gen = (i for i in range(1)); next(gen, None)` >>> returns `'Started'` (the generator has yielded a value) `gen = (i for i in range(1)); next(gen, None); next(gen, None)` >>> returns `'Finished'` (the generator has been exhuasted) For an introduction to Python generators, read: https://wiki.python.org/moin/Generators. Please do vote and rank the kata, and provide any feedback. Hint: you can solve this if you know the right module to use.
check_generator=lambda g:{'GEN_CREATED':'Created','GEN_CLOSED':'Finished'}.get(__import__('inspect').getgeneratorstate(g),'Started')
My third kata, write a function `check_generator` that examines the status of a Python generator expression `gen` and returns `'Created'`, `'Started'` or `'Finished'`. For example: `gen = (i for i in range(1))` >>> returns `'Created'` (the generator has been initiated) `gen = (i for i in range(1)); next(gen, None)` >>> returns `'Started'` (the generator has yielded a value) `gen = (i for i in range(1)); next(gen, None); next(gen, None)` >>> returns `'Finished'` (the generator has been exhuasted) For an introduction to Python generators, read: https://wiki.python.org/moin/Generators. Please do vote and rank the kata, and provide any feedback. Hint: you can solve this if you know the right module to use.
from inspect import getgeneratorstate def check_generator(gen): state = getgeneratorstate(gen) if state == 'GEN_CREATED': return 'Created' elif state == 'GEN_SUSPENDED': return 'Started' else: return 'Finished'
My third kata, write a function `check_generator` that examines the status of a Python generator expression `gen` and returns `'Created'`, `'Started'` or `'Finished'`. For example: `gen = (i for i in range(1))` >>> returns `'Created'` (the generator has been initiated) `gen = (i for i in range(1)); next(gen, None)` >>> returns `'Started'` (the generator has yielded a value) `gen = (i for i in range(1)); next(gen, None); next(gen, None)` >>> returns `'Finished'` (the generator has been exhuasted) For an introduction to Python generators, read: https://wiki.python.org/moin/Generators. Please do vote and rank the kata, and provide any feedback. Hint: you can solve this if you know the right module to use.
from inspect import getgeneratorstate as gg def check_generator(gen): return {'GEN_CREATED': 'Created', 'GEN_SUSPENDED': 'Started', 'GEN_CLOSED': 'Finished'}[gg(gen)]
My third kata, write a function `check_generator` that examines the status of a Python generator expression `gen` and returns `'Created'`, `'Started'` or `'Finished'`. For example: `gen = (i for i in range(1))` >>> returns `'Created'` (the generator has been initiated) `gen = (i for i in range(1)); next(gen, None)` >>> returns `'Started'` (the generator has yielded a value) `gen = (i for i in range(1)); next(gen, None); next(gen, None)` >>> returns `'Finished'` (the generator has been exhuasted) For an introduction to Python generators, read: https://wiki.python.org/moin/Generators. Please do vote and rank the kata, and provide any feedback. Hint: you can solve this if you know the right module to use.
def check_generator(gen): if gen.gi_frame != None: if len(gen.gi_frame.f_locals.keys()) == 1: return 'Created' else: return 'Started' if gen.gi_frame == None: return 'Finished'
When we have a 2x2 square matrix we may have up to 24 different ones changing the positions of the elements. We show some of them ``` a b a b a c a c a d a d b a b a c d d c d b b d b c c b c d d c ``` You may think to generate the remaining ones until completing the set of 24 matrices. Given a certain matrix of numbers, that may be repeated or not, calculate the total number of possible matrices that may be generated, changing the position of the elements. E.g: Case one ``` A = [[1,2,3], [3,4,5]] #a 2x3 rectangle matrix with number 3 twice ``` generates a set of ```360``` different matrices Case two ``` A = [[1,1,1], [2,2,3], [3,3,3]] ``` generates a set of ```1260``` different matrices. Case three ``` A = [[1,2,3], [4,5,6], [7,8,9]] ``` generates a set of ```362880``` different matrices This kata is not meant to apply a brute force algorithm to try to count the total amount of marices. Features of The Random Tests ``` number of tests = 100 2 ≤ m ≤ 9 2 ≤ n ≤ 9 ``` Enjoy it! Available only in Python 2, Javascript and Ruby by the moment.
from collections import Counter from math import factorial def count_perms(matrix): m, n = len(matrix), len(matrix[0]) c = Counter([x for row in matrix for x in row]) factors = [] for x, count in c.most_common(): if count > 1: factors.append(factorial(count)) return factorial(m * n) / reduce(lambda a, b: a * b, factors, 1)
When we have a 2x2 square matrix we may have up to 24 different ones changing the positions of the elements. We show some of them ``` a b a b a c a c a d a d b a b a c d d c d b b d b c c b c d d c ``` You may think to generate the remaining ones until completing the set of 24 matrices. Given a certain matrix of numbers, that may be repeated or not, calculate the total number of possible matrices that may be generated, changing the position of the elements. E.g: Case one ``` A = [[1,2,3], [3,4,5]] #a 2x3 rectangle matrix with number 3 twice ``` generates a set of ```360``` different matrices Case two ``` A = [[1,1,1], [2,2,3], [3,3,3]] ``` generates a set of ```1260``` different matrices. Case three ``` A = [[1,2,3], [4,5,6], [7,8,9]] ``` generates a set of ```362880``` different matrices This kata is not meant to apply a brute force algorithm to try to count the total amount of marices. Features of The Random Tests ``` number of tests = 100 2 ≤ m ≤ 9 2 ≤ n ≤ 9 ``` Enjoy it! Available only in Python 2, Javascript and Ruby by the moment.
from math import factorial as fact from functools import reduce from collections import Counter def count_perms(matrix): m = [elt for line in matrix for elt in line] return fact(len(m)) / reduce(lambda a,b: a*b, map(fact, Counter(m).values()), 1)
When we have a 2x2 square matrix we may have up to 24 different ones changing the positions of the elements. We show some of them ``` a b a b a c a c a d a d b a b a c d d c d b b d b c c b c d d c ``` You may think to generate the remaining ones until completing the set of 24 matrices. Given a certain matrix of numbers, that may be repeated or not, calculate the total number of possible matrices that may be generated, changing the position of the elements. E.g: Case one ``` A = [[1,2,3], [3,4,5]] #a 2x3 rectangle matrix with number 3 twice ``` generates a set of ```360``` different matrices Case two ``` A = [[1,1,1], [2,2,3], [3,3,3]] ``` generates a set of ```1260``` different matrices. Case three ``` A = [[1,2,3], [4,5,6], [7,8,9]] ``` generates a set of ```362880``` different matrices This kata is not meant to apply a brute force algorithm to try to count the total amount of marices. Features of The Random Tests ``` number of tests = 100 2 ≤ m ≤ 9 2 ≤ n ≤ 9 ``` Enjoy it! Available only in Python 2, Javascript and Ruby by the moment.
from collections import Counter from itertools import chain, imap from math import factorial from operator import floordiv def count_perms(matrix): xs = list(chain.from_iterable(matrix)) return reduce(floordiv, imap(factorial, Counter(xs).itervalues()), factorial(len(xs)))
When we have a 2x2 square matrix we may have up to 24 different ones changing the positions of the elements. We show some of them ``` a b a b a c a c a d a d b a b a c d d c d b b d b c c b c d d c ``` You may think to generate the remaining ones until completing the set of 24 matrices. Given a certain matrix of numbers, that may be repeated or not, calculate the total number of possible matrices that may be generated, changing the position of the elements. E.g: Case one ``` A = [[1,2,3], [3,4,5]] #a 2x3 rectangle matrix with number 3 twice ``` generates a set of ```360``` different matrices Case two ``` A = [[1,1,1], [2,2,3], [3,3,3]] ``` generates a set of ```1260``` different matrices. Case three ``` A = [[1,2,3], [4,5,6], [7,8,9]] ``` generates a set of ```362880``` different matrices This kata is not meant to apply a brute force algorithm to try to count the total amount of marices. Features of The Random Tests ``` number of tests = 100 2 ≤ m ≤ 9 2 ≤ n ≤ 9 ``` Enjoy it! Available only in Python 2, Javascript and Ruby by the moment.
from collections import Counter from functools import reduce from math import factorial from operator import mul def count_perms(matrix): return factorial(len(matrix) * len(matrix[0])) // reduce(mul, map(factorial, Counter(sum(matrix, [])).values()))
When we have a 2x2 square matrix we may have up to 24 different ones changing the positions of the elements. We show some of them ``` a b a b a c a c a d a d b a b a c d d c d b b d b c c b c d d c ``` You may think to generate the remaining ones until completing the set of 24 matrices. Given a certain matrix of numbers, that may be repeated or not, calculate the total number of possible matrices that may be generated, changing the position of the elements. E.g: Case one ``` A = [[1,2,3], [3,4,5]] #a 2x3 rectangle matrix with number 3 twice ``` generates a set of ```360``` different matrices Case two ``` A = [[1,1,1], [2,2,3], [3,3,3]] ``` generates a set of ```1260``` different matrices. Case three ``` A = [[1,2,3], [4,5,6], [7,8,9]] ``` generates a set of ```362880``` different matrices This kata is not meant to apply a brute force algorithm to try to count the total amount of marices. Features of The Random Tests ``` number of tests = 100 2 ≤ m ≤ 9 2 ≤ n ≤ 9 ``` Enjoy it! Available only in Python 2, Javascript and Ruby by the moment.
from math import factorial as f from functools import reduce from collections import Counter from operator import mul def count_perms(m): m = sum(m,[]) return f(len(m)) / reduce(mul,map(f,Counter(m).values()))
When we have a 2x2 square matrix we may have up to 24 different ones changing the positions of the elements. We show some of them ``` a b a b a c a c a d a d b a b a c d d c d b b d b c c b c d d c ``` You may think to generate the remaining ones until completing the set of 24 matrices. Given a certain matrix of numbers, that may be repeated or not, calculate the total number of possible matrices that may be generated, changing the position of the elements. E.g: Case one ``` A = [[1,2,3], [3,4,5]] #a 2x3 rectangle matrix with number 3 twice ``` generates a set of ```360``` different matrices Case two ``` A = [[1,1,1], [2,2,3], [3,3,3]] ``` generates a set of ```1260``` different matrices. Case three ``` A = [[1,2,3], [4,5,6], [7,8,9]] ``` generates a set of ```362880``` different matrices This kata is not meant to apply a brute force algorithm to try to count the total amount of marices. Features of The Random Tests ``` number of tests = 100 2 ≤ m ≤ 9 2 ≤ n ≤ 9 ``` Enjoy it! Available only in Python 2, Javascript and Ruby by the moment.
from collections import Counter from itertools import chain from operator import mul from math import factorial def count_perms(matrix): n = len(matrix) * len(matrix[0]) c = Counter(chain.from_iterable(matrix)) return factorial(n) / reduce(mul, map(factorial, c.itervalues()))
When we have a 2x2 square matrix we may have up to 24 different ones changing the positions of the elements. We show some of them ``` a b a b a c a c a d a d b a b a c d d c d b b d b c c b c d d c ``` You may think to generate the remaining ones until completing the set of 24 matrices. Given a certain matrix of numbers, that may be repeated or not, calculate the total number of possible matrices that may be generated, changing the position of the elements. E.g: Case one ``` A = [[1,2,3], [3,4,5]] #a 2x3 rectangle matrix with number 3 twice ``` generates a set of ```360``` different matrices Case two ``` A = [[1,1,1], [2,2,3], [3,3,3]] ``` generates a set of ```1260``` different matrices. Case three ``` A = [[1,2,3], [4,5,6], [7,8,9]] ``` generates a set of ```362880``` different matrices This kata is not meant to apply a brute force algorithm to try to count the total amount of marices. Features of The Random Tests ``` number of tests = 100 2 ≤ m ≤ 9 2 ≤ n ≤ 9 ``` Enjoy it! Available only in Python 2, Javascript and Ruby by the moment.
from math import factorial from collections import Counter from functools import reduce def count_perms(matrix): items = [a for b in matrix for a in b] return factorial(len(items)) // reduce(lambda x,y: x*y, list(map(factorial, list(Counter(items).values()))), 1)
When we have a 2x2 square matrix we may have up to 24 different ones changing the positions of the elements. We show some of them ``` a b a b a c a c a d a d b a b a c d d c d b b d b c c b c d d c ``` You may think to generate the remaining ones until completing the set of 24 matrices. Given a certain matrix of numbers, that may be repeated or not, calculate the total number of possible matrices that may be generated, changing the position of the elements. E.g: Case one ``` A = [[1,2,3], [3,4,5]] #a 2x3 rectangle matrix with number 3 twice ``` generates a set of ```360``` different matrices Case two ``` A = [[1,1,1], [2,2,3], [3,3,3]] ``` generates a set of ```1260``` different matrices. Case three ``` A = [[1,2,3], [4,5,6], [7,8,9]] ``` generates a set of ```362880``` different matrices This kata is not meant to apply a brute force algorithm to try to count the total amount of marices. Features of The Random Tests ``` number of tests = 100 2 ≤ m ≤ 9 2 ≤ n ≤ 9 ``` Enjoy it! Available only in Python 2, Javascript and Ruby by the moment.
import math def count_perms(matrix): freq = dict() for sub_matrix in matrix: for elem in sub_matrix: if freq.get(elem) is not None: freq[elem] = freq[elem] + 1 else: freq[elem] = 1 denominator = 1 for frequency in freq.values(): denominator = denominator * math.factorial(frequency) return math.factorial(sum(freq.values())) / denominator
When we have a 2x2 square matrix we may have up to 24 different ones changing the positions of the elements. We show some of them ``` a b a b a c a c a d a d b a b a c d d c d b b d b c c b c d d c ``` You may think to generate the remaining ones until completing the set of 24 matrices. Given a certain matrix of numbers, that may be repeated or not, calculate the total number of possible matrices that may be generated, changing the position of the elements. E.g: Case one ``` A = [[1,2,3], [3,4,5]] #a 2x3 rectangle matrix with number 3 twice ``` generates a set of ```360``` different matrices Case two ``` A = [[1,1,1], [2,2,3], [3,3,3]] ``` generates a set of ```1260``` different matrices. Case three ``` A = [[1,2,3], [4,5,6], [7,8,9]] ``` generates a set of ```362880``` different matrices This kata is not meant to apply a brute force algorithm to try to count the total amount of marices. Features of The Random Tests ``` number of tests = 100 2 ≤ m ≤ 9 2 ≤ n ≤ 9 ``` Enjoy it! Available only in Python 2, Javascript and Ruby by the moment.
from math import factorial as f from operator import mul def count_perms(m): rep = [[i for s in m for i in s].count(j) for j in set([i for s in m for i in s])] rep = [f(i) for i in rep] tot = (len(m)*len(m[0])) return f(tot)/reduce(mul, rep, 1)
When we have a 2x2 square matrix we may have up to 24 different ones changing the positions of the elements. We show some of them ``` a b a b a c a c a d a d b a b a c d d c d b b d b c c b c d d c ``` You may think to generate the remaining ones until completing the set of 24 matrices. Given a certain matrix of numbers, that may be repeated or not, calculate the total number of possible matrices that may be generated, changing the position of the elements. E.g: Case one ``` A = [[1,2,3], [3,4,5]] #a 2x3 rectangle matrix with number 3 twice ``` generates a set of ```360``` different matrices Case two ``` A = [[1,1,1], [2,2,3], [3,3,3]] ``` generates a set of ```1260``` different matrices. Case three ``` A = [[1,2,3], [4,5,6], [7,8,9]] ``` generates a set of ```362880``` different matrices This kata is not meant to apply a brute force algorithm to try to count the total amount of marices. Features of The Random Tests ``` number of tests = 100 2 ≤ m ≤ 9 2 ≤ n ≤ 9 ``` Enjoy it! Available only in Python 2, Javascript and Ruby by the moment.
f,count_perms=lambda n:n<1or n*f(n-1),lambda m:(lambda l:reduce(lambda x,y:x/f(l.count(y)),set(l),f(len(l))))(sum(m,[]))
What is the answer to life the universe and everything Create a function that will make anything true ```python anything({}) != [], 'True' anything('Hello') < 'World', 'True' anything(80) > 81, 'True' anything(re) >= re, 'True' anything(re) <= math, 'True' anything(5) == ord, 'True' ``` Source: [CheckIO](https://checkio.org/mission/solution-for-anything/)
class anything(object): def __init__(self, foo): pass def __eq__(self, other): return True __ne__ = __lt__ = __le__ = __gt__ = __ge__ = __eq__
What is the answer to life the universe and everything Create a function that will make anything true ```python anything({}) != [], 'True' anything('Hello') < 'World', 'True' anything(80) > 81, 'True' anything(re) >= re, 'True' anything(re) <= math, 'True' anything(5) == ord, 'True' ``` Source: [CheckIO](https://checkio.org/mission/solution-for-anything/)
class anything: def __init__(self,*args,**kwargs): pass anything.__eq__ = anything.__neq__ = anything.__gt__ = anything.__ge__ = anything.__lt__ = anything.__le__ = lambda *x:True
What is the answer to life the universe and everything Create a function that will make anything true ```python anything({}) != [], 'True' anything('Hello') < 'World', 'True' anything(80) > 81, 'True' anything(re) >= re, 'True' anything(re) <= math, 'True' anything(5) == ord, 'True' ``` Source: [CheckIO](https://checkio.org/mission/solution-for-anything/)
class anything: def __init__(self, x): pass __lt__ = __le__ = __gt__ = __ge__ = __eq__ = lambda self, other: True
What is the answer to life the universe and everything Create a function that will make anything true ```python anything({}) != [], 'True' anything('Hello') < 'World', 'True' anything(80) > 81, 'True' anything(re) >= re, 'True' anything(re) <= math, 'True' anything(5) == ord, 'True' ``` Source: [CheckIO](https://checkio.org/mission/solution-for-anything/)
class anything: def __init__(self, _): pass def __eq__(self, other): return True __ne__ = __lt__ = __le__ = __ge__ = __gt__ = __eq__
What is the answer to life the universe and everything Create a function that will make anything true ```python anything({}) != [], 'True' anything('Hello') < 'World', 'True' anything(80) > 81, 'True' anything(re) >= re, 'True' anything(re) <= math, 'True' anything(5) == ord, 'True' ``` Source: [CheckIO](https://checkio.org/mission/solution-for-anything/)
class anything: def __init__(self, value): pass __eq__=__ne__=__lt__=__le__=__gt__=__ge__ = lambda self,second: True
You must create a method that can convert a string from any format into CamelCase. This must support symbols too. *Don't presume the separators too much or you could be surprised.* ### Tests ```python camelize("example name") # => ExampleName camelize("your-NaMe-here") # => YourNameHere camelize("testing ABC") # => TestingAbc ```
import re def camelize(s): return "".join([w.capitalize() for w in re.split("\W|_", s)])
You must create a method that can convert a string from any format into CamelCase. This must support symbols too. *Don't presume the separators too much or you could be surprised.* ### Tests ```python camelize("example name") # => ExampleName camelize("your-NaMe-here") # => YourNameHere camelize("testing ABC") # => TestingAbc ```
import re def camelize(s): return "".join(map(str.capitalize, re.split("\W|_", s)))
You must create a method that can convert a string from any format into CamelCase. This must support symbols too. *Don't presume the separators too much or you could be surprised.* ### Tests ```python camelize("example name") # => ExampleName camelize("your-NaMe-here") # => YourNameHere camelize("testing ABC") # => TestingAbc ```
import re def camelize(s): return "".join(map(str.capitalize, re.findall(r"[a-zA-Z0-9]+", s)))
You must create a method that can convert a string from any format into CamelCase. This must support symbols too. *Don't presume the separators too much or you could be surprised.* ### Tests ```python camelize("example name") # => ExampleName camelize("your-NaMe-here") # => YourNameHere camelize("testing ABC") # => TestingAbc ```
def camelize(str_): new_str = '' new_word = True for elem in str_: if elem.isalnum(): new_str += elem.upper() if new_word else elem.lower() new_word = False else: new_word = True return new_str
You must create a method that can convert a string from any format into CamelCase. This must support symbols too. *Don't presume the separators too much or you could be surprised.* ### Tests ```python camelize("example name") # => ExampleName camelize("your-NaMe-here") # => YourNameHere camelize("testing ABC") # => TestingAbc ```
def camelize(str_): k = '' str_ = str_.lower() for x in str_: if x.isalnum(): k += x else: k += ' ' return ''.join(x.capitalize() for x in k.split())
You must create a method that can convert a string from any format into CamelCase. This must support symbols too. *Don't presume the separators too much or you could be surprised.* ### Tests ```python camelize("example name") # => ExampleName camelize("your-NaMe-here") # => YourNameHere camelize("testing ABC") # => TestingAbc ```
import re def camelize(str_): return ''.join(x.capitalize() for x in re.split(r'[\W_]', str_))
You must create a method that can convert a string from any format into CamelCase. This must support symbols too. *Don't presume the separators too much or you could be surprised.* ### Tests ```python camelize("example name") # => ExampleName camelize("your-NaMe-here") # => YourNameHere camelize("testing ABC") # => TestingAbc ```
import re def camelize(str_): words = re.findall(r'[a-z0-9]+', str_, flags=re.I) return ''.join(word.capitalize() for word in words)
You must create a method that can convert a string from any format into CamelCase. This must support symbols too. *Don't presume the separators too much or you could be surprised.* ### Tests ```python camelize("example name") # => ExampleName camelize("your-NaMe-here") # => YourNameHere camelize("testing ABC") # => TestingAbc ```
import re def camelize(str_): return "".join([i.capitalize() for i in re.findall(r"[A-Za-z0-9]*",str_)])
You must create a method that can convert a string from any format into CamelCase. This must support symbols too. *Don't presume the separators too much or you could be surprised.* ### Tests ```python camelize("example name") # => ExampleName camelize("your-NaMe-here") # => YourNameHere camelize("testing ABC") # => TestingAbc ```
from string import punctuation as p; camelize = lambda s: ''.join([x.capitalize() for x in reduce(lambda a, kv: a.replace(*kv), [(x, ' ') for x in p], s).split(' ')])
You must create a method that can convert a string from any format into CamelCase. This must support symbols too. *Don't presume the separators too much or you could be surprised.* ### Tests ```python camelize("example name") # => ExampleName camelize("your-NaMe-here") # => YourNameHere camelize("testing ABC") # => TestingAbc ```
def camelize(string): s = "" for i in string.lower(): if i in "qwertyuiopasdfghjklzxcvbnm1234567890": s += i else: s += " " s = s.split() lst = [] for i in s: lst.append(i[0].upper() + i[1:]) return "".join(lst)
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): return n + (5 - n) % 5
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): while n%5!=0: n+=1 return n
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
import math def round_to_next5(n): # Your code here return math.ceil(n/5.0) * 5
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): return 5 * ((n+4)/5)
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): # Your code here rem = n % 5 return n + ((5 - rem) if rem else 0)
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): # Your code here return n + -n % 5
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): return n if n%5 == 0 else round_to_next5(n+1)
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): return (n+4)//5*5
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
from math import ceil def round_to_next5(n): return ceil(n/5) * 5
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): x, y = divmod(n, 5) return (x + (y > 0)) * 5
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
import math def round_to_next5(n): return math.ceil(n/5)*5
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): while (n !=0 and n%5 !=0): n+= 1 return n
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
from itertools import count def round_to_next5(n): return next(val for val in count(n) if val % 5 == 0)
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
round_to_next5 = lambda n: n if n % 5 == 0 else ((n / 5) + 1) * 5
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): r=n%5 return 5+(n-r) if r!=0 else n
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): if n%5 == 0: return n if n%5 != 0: while n%5 != 0: n += 1 return n
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
from math import ceil # And others, take your pick def round_to_next5(n): return 5*ceil(n/5) return n + 5 - (n%5 or 5) return (n+4)//5*5
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): return (n // 5 + (1 if n%5 != 0 else 0)) *5
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
import math def round_to_next5(n): return int(math.ceil(n / 5)) * 5
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): if n%5: return n+(5-(n%5)) else: return n
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
round_to_next5=lambda n:n+-n%5
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): return n / 5 * 5 + 5 * bool(n % 5)
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): return ((n/5)+(n%5!=0))*5
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): return -(-n // 5 * 5)
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): # Your code here if n == 0: return 0 elif n % 5 == 0: return n else: return round_to_next5(n+1)
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): # Your code here if n % 5 == 0: return n elif n % 5 != 0: while (n % 5) != 0: n = n + 1 if (n % 5) == 0: return n break print(round_to_next5(30))
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): return (round((n/5)+0.49)*5)
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): return (n - 1) - (n - 1) % 5 + 5
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
import math def round_to_next5(n): x = math.ceil(n / 5) * 5 return x
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
from math import ceil def round_to_next5(n): return 5*round(ceil(float(n)/5))
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): if not n % 5: return n else: return round_to_next5(n + 1)
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): return (n-1)//5*5+5
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): # Your code here # bool(n % 5) returns False if n is equally divisible, True if it isn't. # int(False) = 0; int(True) = 1 return 5 * (n//5 + int(bool(n % 5)))
Given an integer as input, can you round it to the next (meaning, "higher") multiple of 5? Examples: input: output: 0 -> 0 2 -> 5 3 -> 5 12 -> 15 21 -> 25 30 -> 30 -2 -> 0 -5 -> -5 etc. Input may be any positive or negative integer (including 0). You can assume that all inputs are valid integers.
def round_to_next5(n): # Your code here return n if n%10 == 0 else n+(-n%5)