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.
smol
You have received two names.
Verify if the sum of the ASCII codes of the letters of the first name is the same as sum of the ASCII codes of the letters of the second name. If the either name is none or an empty string, output None.
For example:
'''
"Anna" = 65 + 110 + 110 + 97 = 382
"Nana" = 78 + 97 + 110 + 97 = 382
'''
print(Kumite("Anna", "Nana").solve()) # True
print(Kumite("Sebastian","Patricia").solve()) # False
print(Kumite("John", None).solve()) # None
print(Kumite("", "Albert").solve()) # None
Kumite=lambda*a:type("",(),{"solve":lambda f=lambda b:sum(map(lambda c:ord(c),a[b])):not f(0)-f(1)if set([None,""]).isdisjoint(a)else None})
class Kumite:def __init__(self, name1, name2):self.name1 = name1self.name2 = name2def solve(self):return None if not self.name1 or not self.name2 else (sum([ord(t)for t in self.name1]) == sum([ord(t) for t in self.name2]))- Kumite=lambda*a:type("",(),{"solve":lambda f=lambda b:sum(map(lambda c:ord(c),a[b])):not f(0)-f(1)if set([None,""]).isdisjoint(a)else None})
class MaxDigit: def __init__(s, n): s.n = n def execute(s): return int(''.join(sorted(str(s.n), reverse=True)))
- class MaxDigit:
def __init__(self, n):self.n = n- def __init__(s, n):
- s.n = n
def execute(self):return int(''.join(sorted(str(self.n), reverse=True)))- def execute(s):
- return int(''.join(sorted(str(s.n), reverse=True)))
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { @Test void testSomething() { // assertEquals("expected", "actual"); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- // TODO: Replace examples and use TDD by writing your own tests
- class SolutionTest {
- @Test
- void testSomething() {
- // assertEquals("expected", "actual");
- }
- }
Completed your previous solution to correctly check both cases.
public class Kata { public static int SameCase(char a, char b) { if (!char.IsLetter(a) || !char.IsLetter(b)) { return -1; } return (char.IsUpper(a) && char.IsUpper(b)) || (char.IsLower(a) && char.IsLower(b)) ? 1 : 0; } }
- public class Kata
- {
- public static int SameCase(char a, char b)
- {
- if (!char.IsLetter(a) || !char.IsLetter(b))
- {
- return -1;
- }
return (char.IsUpper(a) == char.IsUpper(b)) ? 1 : 0;- return (char.IsUpper(a) && char.IsUpper(b)) || (char.IsLower(a) && char.IsLower(b)) ? 1 : 0;
- }
- }
namespace Solution { using NUnit.Framework; using System; [TestFixture] public class SolutionTest { [Test] public void TrueTests() { Assert.AreEqual(1, Kata.SameCase('a', 'u')); Assert.AreEqual(1, Kata.SameCase('A', 'U')); Assert.AreEqual(1, Kata.SameCase('Q', 'P')); Assert.AreEqual(1, Kata.SameCase('w', 'y')); Assert.AreEqual(1, Kata.SameCase('c', 'm')); Assert.AreEqual(1, Kata.SameCase('N', 'W')); } [Test] public void FalseTests() { Assert.AreEqual(0, Kata.SameCase('a', 'U')); Assert.AreEqual(0, Kata.SameCase('A', 'u')); Assert.AreEqual(0, Kata.SameCase('Q', 'p')); Assert.AreEqual(0, Kata.SameCase('w', 'Y')); Assert.AreEqual(0, Kata.SameCase('c', 'M')); Assert.AreEqual(0, Kata.SameCase('N', 'w')); } [Test] public void NotLetters() { Assert.AreEqual(-1, Kata.SameCase('a', '*')); Assert.AreEqual(-1, Kata.SameCase('A', '%')); Assert.AreEqual(-1, Kata.SameCase('Q', '1')); Assert.AreEqual(-1, Kata.SameCase('w', '-')); Assert.AreEqual(-1, Kata.SameCase('c', '8')); Assert.AreEqual(-1, Kata.SameCase('N', ':')); } [Test] public void RandomTest() { string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz1234567890~/*-+:.,><.#@!&"; Random rand = new Random(); char char1 = 'a'; char char2 = 'a'; for (int i = 0; i < 200; i++) { char1 = chars[rand.Next(0,76)]; char2 = chars[rand.Next(0,76)]; Assert.AreEqual(SameCaseSolution(char1,char2), Kata.SameCase(char1, char2)); } } private static int SameCaseSolution(char a, char b) { if (!char.IsLetter(a) || !char.IsLetter(b)) return -1; if ((a >= 97) == (b >= 97)) return 1; return 0; } } }
- namespace Solution {
- using NUnit.Framework;
- using System;
- [TestFixture]
- public class SolutionTest
- {
- [Test]
- public void TrueTests()
- {
- Assert.AreEqual(1, Kata.SameCase('a', 'u'));
- Assert.AreEqual(1, Kata.SameCase('A', 'U'));
- Assert.AreEqual(1, Kata.SameCase('Q', 'P'));
- Assert.AreEqual(1, Kata.SameCase('w', 'y'));
- Assert.AreEqual(1, Kata.SameCase('c', 'm'));
- Assert.AreEqual(1, Kata.SameCase('N', 'W'));
- }
- [Test]
- public void FalseTests()
- {
- Assert.AreEqual(0, Kata.SameCase('a', 'U'));
- Assert.AreEqual(0, Kata.SameCase('A', 'u'));
- Assert.AreEqual(0, Kata.SameCase('Q', 'p'));
- Assert.AreEqual(0, Kata.SameCase('w', 'Y'));
- Assert.AreEqual(0, Kata.SameCase('c', 'M'));
- Assert.AreEqual(0, Kata.SameCase('N', 'w'));
- }
- [Test]
- public void NotLetters()
- {
- Assert.AreEqual(-1, Kata.SameCase('a', '*'));
- Assert.AreEqual(-1, Kata.SameCase('A', '%'));
- Assert.AreEqual(-1, Kata.SameCase('Q', '1'));
- Assert.AreEqual(-1, Kata.SameCase('w', '-'));
- Assert.AreEqual(-1, Kata.SameCase('c', '8'));
- Assert.AreEqual(-1, Kata.SameCase('N', ':'));
- }
- [Test]
- public void RandomTest() {
- string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz1234567890~/*-+:.,><.#@!&";
- Random rand = new Random();
- char char1 = 'a';
- char char2 = 'a';
- for (int i = 0; i < 200; i++) {
- char1 = chars[rand.Next(0,76)];
- char2 = chars[rand.Next(0,76)];
- Assert.AreEqual(SameCaseSolution(char1,char2), Kata.SameCase(char1, char2));
- }
- }
- private static int SameCaseSolution(char a, char b) {
- if (!char.IsLetter(a) || !char.IsLetter(b)) return -1;
- if ((a >= 97) == (b >= 97)) return 1;
- return 0;
- }
- }
- }
regex
test_password=lambda s:__import__("re").search('(?=.{8,})(?=.*[A-Z])(?=.*[0-9])(?=.*[!"#\$%&\'\(\)\*\+\'\-./;:<>=\?])',s)!=None
test_password=lambda s:all([len(s)>7,any(c.isupper()for c in s),any(c.isdigit()for c in s),any(c in __import__("string").punctuation for c in s)])- test_password=lambda s:__import__("re").search('(?=.{8,})(?=.*[A-Z])(?=.*[0-9])(?=.*[!"#\$%&\'\(\)\*\+\'\-./;:<>=\?])',s)!=None
import java.util.*; import java.util.stream.Collectors; public class MaxNumber { public static long print(long number) { return Long.parseLong( String.valueOf(number) .chars() .mapToObj(ch -> String.valueOf((char) ch)) .sorted(Comparator.reverseOrder()) .collect(Collectors.joining()) ); } }
- import java.util.*;
- import java.util.stream.Collectors;
- public class MaxNumber {
- public static long print(long number) {
- return Long.parseLong(
- String.valueOf(number)
- .chars()
.mapToObj(ch -> String.valueOf(Character.getNumericValue(ch)))- .mapToObj(ch -> String.valueOf((char) ch))
- .sorted(Comparator.reverseOrder())
- .collect(Collectors.joining())
- );
- }
- }
Why use Python when we can use Assembly 😎.
int multiply(int a, int b) { int res; __asm__ ( "imull %1, %2 \n\t" "movl %2, %0" : "=r" (res) : "r" (a), "r" (b) ); return res; }
def multiply(a, b):return a*b- int multiply(int a, int b)
- {
- int res;
- __asm__
- (
- "imull %1, %2 \n\t"
- "movl %2, %0"
- : "=r" (res)
- : "r" (a), "r" (b)
- );
- return res;
- }
// TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example. #include <criterion/criterion.h> // replace with the actual method being tested int multiply(int a, int b); Test(the_multiply_function, should_pass_all_the_tests_provided) { cr_assert_eq(multiply(1, 1), 1); cr_assert_eq(multiply(2, 2), 4); cr_assert_eq(multiply(3, 7), 21); }
import codewars_test as test# TODO Write testsimport solution # or from solution import example- // TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example.
# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")def test_group():@test.it("test case")def test_case():test.assert_equals(multiply(1, 1), 1)test.assert_equals(multiply(1, 1), 1)test.assert_equals(multiply(2, 2), 4)test.assert_equals(multiply(2, -2), -4)test.assert_equals(multiply(-2, 2), -4)test.assert_equals(multiply(-2, -2), 4)test.assert_equals(multiply(3, 7), 21)test.assert_equals(multiply(3, -7), -21)test.assert_equals(multiply(-3, -7), 21)- #include <criterion/criterion.h>
- // replace with the actual method being tested
- int multiply(int a, int b);
- Test(the_multiply_function, should_pass_all_the_tests_provided)
- {
- cr_assert_eq(multiply(1, 1), 1);
- cr_assert_eq(multiply(2, 2), 4);
- cr_assert_eq(multiply(3, 7), 21);
- }