Kumite (ko͞omiˌtā) is the practice of taking techniques learned from Kata and applying them through the act of freestyle sparring.
You can create a new kumite by providing some initial code and optionally some test cases. From there other warriors can spar with you, by enhancing, refactoring and translating your code. There is no limit to how many warriors you can spar with.
A great use for kumite is to begin an idea for a kata as one. You can collaborate with other code warriors until you have it right, then you can convert it to a kata.
reverse_string = lambda s: s[::-1]
def reverse_string(s):return s[::-1]- reverse_string = lambda s: s[::-1]
import codewars_test as test from solution import reverse_string @test.describe("Solution") def a(): @test.it("should test for something") def a(): test.assert_equals(reverse_string('abc'), 'cba') test.assert_equals(reverse_string('123'), '321') test.assert_equals(reverse_string('a1b2c3'), '3c2b1a') test.assert_equals(reverse_string('Hello World!'), '!dlroW olleH') test.assert_equals(reverse_string('Lorem ipsum dolor sit amet!'), '!tema tis rolod muspi meroL')
- import codewars_test as test
- from solution import reverse_string
- @test.describe("Solution")
- def a():
- @test.it("should test for something")
- def a():
- test.assert_equals(reverse_string('abc'), 'cba')
- test.assert_equals(reverse_string('123'), '321')
- test.assert_equals(reverse_string('a1b2c3'), '3c2b1a')
- test.assert_equals(reverse_string('Hello World!'), '!dlroW olleH')
def Greeting(n, rank='', formal=False): determinant = f'{rank} {n}' if formal and rank else f'{n}' return f"Hello, {determinant}." if formal else f"Hey, {determinant}!"
def Greeting(n, rank='', formal=0):determinant = f'{rank} {n}' if formal and rank else f'{n}'return f"Hello, {determinant}." if formal else f"Hey, {determinant}!"- def Greeting(n, rank='', formal=False):
- determinant = f'{rank} {n}' if formal and rank else f'{n}'
- return f"Hello, {determinant}." if formal else f"Hey, {determinant}!"
import re def longest_words(word_list, num_words): if not isinstance(word_list, list) or not isinstance(num_words, int) or num_words < 0: return 'Invalid Parameters' valid_words = [re.sub(r'[^A-Za-z]', '', word) for word in word_list if word and re.sub(r'[^A-Za-z]', '', word)] return sorted(valid_words, key=len, reverse=True)[:num_words] if num_words <= len(valid_words) else 'Invalid Parameters'
- import re
def longest_words(array, num):valid_words = [re.sub(r'[^A-Za-z]', '', word) for word in array if word and re.sub(r'[^A-Za-z]', '', word)]return sorted(valid_words, key=len, reverse=True)[:num] if num <= len(valid_words) else 'Invalid Parameters'- def longest_words(word_list, num_words):
- if not isinstance(word_list, list) or not isinstance(num_words, int) or num_words < 0:
- return 'Invalid Parameters'
- valid_words = [re.sub(r'[^A-Za-z]', '', word) for word in word_list if word and re.sub(r'[^A-Za-z]', '', word)]
- return sorted(valid_words, key=len, reverse=True)[:num_words] if num_words <= len(valid_words) else 'Invalid Parameters'
import codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(1 + 1, 2)
- import codewars_test as test
from solution import longest_wordsimport random- # TODO Write tests
- import solution # or from solution import example
# Working solutiondef _solve(array, num):new = [k for k in sorted([''.join([i for i in j if 97 <= ord(i) <= 122 or 65 <= ord(i) <= 90]) for j in array], key=lambda x: len(x), reverse=True) if k != '']print(new[:num] if num <= len(new) else 'Invalid Parameters')return new[:num] if num <= len(new) else 'Invalid Parameters'# Random word list generatordef gen_random(length):word_list = [('Programming', 'ƤŖø¶Ŗ@µµƗƕ¶', 'Prø¶r@mming'), ('is', 'Ɨ$', 'is'), ('often', 'øƒƮƩƕ', 'often'),('compared', '¢øµƤ@ŖƩƊ', 'comƤ@Ŗed'), ('to', 'Ʈø', 'to'), ('solving', '$øȴƔƗƕ¶', '$olvƗn¶'),('intricate', 'ƗƕƮŖƗ¢@ƮƩ', 'intri¢aƮe'), ('puzzles,', 'Ƥû§§ȴƩ$,', 'pu§§le$,'), ('', '', '',),('requiring', 'ŖƩǭûƗŖƗƕ¶', 'ŖeqûƗŖing'), ('a', '@', 'a'), ('sharp', '$ɧ@ŖƤ', 'sharp'),('analytical', '@ƕ@ȴ¥ƮƗ¢@ȴ', '@nal¥Ʈical'), ('mind', 'µƗƕƊ', 'mind'), ('to', 'Ʈø', 'tø'),('piece', 'ƤƗƩ¢Ʃ', 'piecƩ'), ('together', 'Ʈø¶ƩƮɧƩŖ', 'togetɧeŖ'), ('the', 'ƮɧƩ', 'the'),('correct', '¢øŖŖƩ¢Ʈ', 'correct'), ('code.', '¢øƊƩ.', 'code.'), ('One', 'øƕƩ', 'Oƕe'), ('of', 'øƒ', 'oƒ'),('the', 'ƮɧƩ', 'tɧe'), ('complexities', '¢øµƤȴƩ×ƗƮƗƩ$', 'cøµplexƗƮie$'), ('of', 'øƒ', 'of'),('programming', 'ƤŖø¶Ŗ@µµƗƕ¶', 'ƤrogrammƗng'), ('lies', 'ȴƗƩ$', 'liƩs'), ('in', 'Ɨƕ', 'in'),('managing', 'µ@ƕ@¶Ɨƕ¶', 'µaƕagƗn¶'), ('an', '@ƕ', '@n'), ('ever-growing', 'ƩƔƩŖ-¶ŖøƜƗƕ¶', 'eƔƩr-¶røƜing'),('body', 'ßøƊ¥', 'body'), ('of', 'øƒ', 'oƒ'), ('knowledge', 'ƙƕøƜȴƩƊ¶Ʃ', 'kƕoƜledge'), ('as', '@$', 'as'),('new', 'ƕƩƜ', 'nƩw'), ('languages', 'ȴ@ƕ¶û@¶Ʃ$', 'laƕgû@ges'), ('and', '@ƕƊ', '@nd'),('technologies', 'ƮƩ¢ɧƕøȴø¶ƗƩ$', 'technoløgies'), ('emerge.', 'ƩµƩŖ¶Ʃ.', 'emergƩ.'), ('', '', '',),('Debugging', 'ƊƩßû¶¶Ɨƕ¶', 'Ɗeßûg¶ing'), ('code', '¢øƊƩ', 'cøde'), ('can', '¢@ƕ', 'can'),('be', 'ßƩ', 'be'), ('like', 'ȴƗƙƩ', 'ȴikƩ'), ('searching', '$Ʃ@Ŗ¢ɧƗƕ¶', 'se@rcɧƗn¶'), ('for', 'ƒøŖ', 'for'),('a', '@', 'a'), ('needle', 'ƕƩƩƊȴƩ', 'ƕeƩdle'), ('in', 'Ɨƕ', 'Ɨn'), ('a', '@', 'a'),('haystack,', 'ɧ@¥$Ʈ@¢ƙ,', 'haystacƙ,'), ('as', '@$', '@s'), ('a', '@', 'a'), ('single', '$Ɨƕ¶ȴƩ', 'siƕgle'),('character', '¢ɧ@Ŗ@¢ƮƩŖ', 'cɧaŖ@cteŖ'), ('error', 'ƩŖŖøŖ', 'errør'), ('can', '¢@ƕ', 'caƕ'),('lead', 'ȴƩ@Ɗ', 'lƩ@Ɗ'), ('to', 'Ʈø', 'tø'), ('hours', 'ɧøûŖ$', 'hoûŖ$'), ('of', 'øƒ', 'oƒ'),('troubleshooting.', 'ƮŖøûßȴƩ$ɧøøƮƗƕ¶.', 'trøußlesɧooƮin¶.'), ('The', 'ƮɧƩ', 'Ʈhe'), ('', '', '',), ('', '', '',),('meticulous', 'µƩƮƗ¢ûȴøû$', 'metƗ¢uȴous'), ('attention', '@ƮƮƩƕƮƗøƕ', 'aƮtention'), ('to', 'Ʈø', 'to'),('detail', 'ƊƩƮ@Ɨȴ', 'detail'), ('needed', 'ƕƩƩƊƩƊ', 'nƩedƩd'), ('in', 'Ɨƕ', 'in'), ('', '', '',),('programming', 'ƤŖø¶Ŗ@µµƗƕ¶', 'Ƥro¶rammƗng'), ('can', '¢@ƕ', '¢an'), ('be', 'ßƩ', 'be'), ('', '', '',),('mentally', 'µƩƕƮ@ȴȴ¥', 'mƩnƮ@ȴȴy'), ('taxing,', 'Ʈ@×Ɨƕ¶,', 'Ʈ@xƗng,'), ('leading', 'ȴƩ@ƊƗƕ¶', 'ȴe@dƗng'),('to', 'Ʈø', 'to'), ('fatigue', 'ƒ@ƮƗ¶ûƩ', 'fatiguƩ'), ('and', '@ƕƊ', 'aƕd'), ('burnout.', 'ßûŖƕøûƮ.', 'ßuŖnoût.'),('Staying', '$Ʈ@¥Ɨƕ¶', '$taying'), ('updated', 'ûƤƊ@ƮƩƊ', 'upd@teƊ'), ('in', 'Ɨƕ', 'iƕ'), ('the', 'ƮɧƩ', 'tɧe'),('fast-paced', 'ƒ@$Ʈ-Ƥ@¢ƩƊ', 'fa$t-ƤacƩƊ'), ('tech', 'ƮƩ¢ɧ', 'tech'), ('world', 'ƜøŖȴƊ', 'wørȴƊ'), ('is', 'Ɨ$', 'is'),('a', '@', 'a'), ('constant', '¢øƕ$Ʈ@ƕƮ', 'con$Ʈaƕt'), ('challenge,', '¢ɧ@ȴȴƩƕ¶Ʃ,', 'ch@lleƕge,'), ('', '', '',),('with', 'ƜƗƮɧ', 'ƜiƮh'), ('new', 'ƕƩƜ', 'new'), ('frameworks', 'ƒŖ@µƩƜøŖƙ$', 'ƒŖ@meƜoŖks'), ('and', '@ƕƊ', '@nd'),('libraries', 'ȴƗßŖ@ŖƗƩ$', 'ȴƗbŖ@rƗes'), ('being', 'ßƩƗƕ¶', 'bƩƗƕ¶'), ('released', 'ŖƩȴƩ@$ƩƊ', 'rƩle@sƩƊ'),('regularly.', 'ŖƩ¶ûȴ@Ŗȴ¥.', 'ŖƩguȴarly.'), ('The', 'ƮɧƩ', 'ƮhƩ'), ('precise', 'ƤŖƩ¢Ɨ$Ʃ', 'precise'),('syntax', '$¥ƕƮ@×', 's¥nƮax'), ('and', '@ƕƊ', 'anƊ'), ('semantics', '$Ʃµ@ƕƮƗ¢$', 'seµaƕƮƗc$'), ('of', 'øƒ', 'of'),('each', 'Ʃ@¢ɧ', 'e@cɧ'), ('programming', 'ƤŖø¶Ŗ@µµƗƕ¶', 'pŖogŖamµing'), ('language', 'ȴ@ƕ¶û@¶Ʃ', 'ȴ@ngua¶e'),('add', '@ƊƊ', '@dd'), ('layers', 'ȴ@¥ƩŖ$', 'layƩr$'), ('of', 'øƒ', 'of'), ('difficulty,', 'ƊƗƒƒƗ¢ûȴƮ¥,', 'diƒfƗcûlty,'),('as', '@$', 'as'), ('small', '$µ@ȴȴ', 'smaȴȴ'), ('mistakes', 'µƗ$Ʈ@ƙƩ$', 'mƗstaƙe$'), ('can', '¢@ƕ', 'can'),('cause', '¢@û$Ʃ', 'caûsƩ'), ('major', 'µ@ǰøŖ', 'µ@ǰøŖ'), ('issues.', 'Ɨ$$ûƩ$.', 'Ɨ$sûes.'), ('', '', '',)]return [random.choice(word_list)[random.randint(0, 2)] for _ in range(length)]# Start of testing@test.describe("Example Tests")- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
@test.it("Testing...")- @test.it("test case")
- def test_case():
test.assert_equals(longest_words(["Hello", "world", "Coding", "is", "fun!"], 1), ['Coding'])test.assert_equals(longest_words(["Python", "Java", "C++", "JavaScript"], 4), ['JavaScript', 'Python', 'Java', 'C'])test.assert_equals(longest_words(["Hello", "world", "Coding", "is", "fun!"], 6), 'Invalid Parameters')@test.describe("Edge Cases")def test_group2():@test.it("Testing...")def test_edges():test.assert_equals(longest_words(["H3ll0", "w0rld", "C0d1ng", "1s", "fun!"], 4), ['wrld', 'Cdng', 'Hll', 'fun'])test.assert_equals(longest_words(["HELLO", '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], 1), ['HELLO'])test.assert_equals(longest_words(["HELLO", 'B123I123G123W123O123R123D', '1', '2', '3', '4', '5', '6', '7', '8', '9'], 2), ['BIGWORD', 'HELLO'])test.assert_equals(longest_words(["HELLO", '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], 2), 'Invalid Parameters')test.assert_equals(longest_words(['k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'], 5), ['k', 'j', 'i', 'h', 'g'])@test.describe('Random Tests')def test_random():@test.it('Small Tests')def small_rand():for _ in range(10):for i in range(5, 10):rand_words = gen_random(i)rand_num = random.randint(0, i + 1)test.assert_equals(longest_words(rand_words[:], rand_num), _solve(rand_words[:], rand_num))@test.it('Medium Tests')def med_rand():for _ in range(10):for i in range(15, 20):rand_words = gen_random(i)rand_num = random.randint(0, i + 1)test.assert_equals(longest_words(rand_words[:], rand_num), _solve(rand_words[:], rand_num))@test.it('Large Tests')def med_rand():for i in range(25, 125):rand_words = gen_random(i)rand_num = random.randint(0, i + 1)test.assert_equals(longest_words(rand_words[:], rand_num), _solve(rand_words[:], rand_num))- test.assert_equals(1 + 1, 2)
You have received 2 names.
Verify if the sum of letters of the 1 name is the same as sum of the letters of the 2 name. If the name or surname is null output NULL.
For example:
"Anna" and "Nana"
"Anna" = 65+110+110+97 = 382
"Nana" = 78+97+110+97 = 382
Result: "Anna" and "Nana" => "TRUE"
"Sebastian" and "Patricia" => "FALSE"
"John" and null => "NULL"
#include <string> #include <numeric> #include <algorithm> class StringComparer { public: static bool verifySum(const std::string& w1, const std::string& w2) { int sumW1 = sumOfCharacters(w1); int sumW2 = sumOfCharacters(w2); return sumW1 == sumW2; } static int sumOfCharacters(const std::string& word) { return std::accumulate(word.begin(), word.end(), 0, [](int sum, char ch) { return sum + static_cast<int>(ch); }); } };
- #include <string>
- #include <numeric>
- #include <algorithm>
- class StringComparer {
- public:
- static bool verifySum(const std::string& w1, const std::string& w2) {
- int sumW1 = sumOfCharacters(w1);
- int sumW2 = sumOfCharacters(w2);
std::cout << "String 1: " << w1 << " - Sum of Characters: " << sumW1 << std::endl;std::cout << "String 2: " << w2 << " - Sum of Characters: " << sumW2 << std::endl;- return sumW1 == sumW2;
- }
- static int sumOfCharacters(const std::string& word) {
- return std::accumulate(word.begin(), word.end(), 0, [](int sum, char ch) {
- return sum + static_cast<int>(ch);
- });
- }
- };