Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

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.

Ad
Ad

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
Code
Diff
  • 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 = name1
    • self.name2 = name2
    • def 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})
Code
Diff
  • 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)))

Completed your previous solution to correctly check both cases.

Code
Diff
  • 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;
    • }
    • }

regex

Code
Diff
  • 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
Code
Diff
  • 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 😎.

Code
Diff
  • 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;
    • }