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
Code
Diff
  • def twin_sum_solutions(array)
      array.tally.each_pair.with_object([]) do | (v, count), res | 
        res << v * 2 if count == 2 
      end
    end
    
    • def twin_sum_solutions(array)
    • array.each_with_object([]) do |element, memo|
    • next if memo.include? element * 2
    • memo << element * 2 if array.count(element) > 1
    • array.tally.each_pair.with_object([]) do | (v, count), res |
    • res << v * 2 if count == 2
    • end
    • end

//Just cleaned the code up a bit.

Code
Diff
  • function closestToZero(array $ints): int|float|null
    {
        if(!isset($ints[0])) return null;
      
        $closest = $ints[0];
    
        foreach ($ints as $num) 
        {
          $absNum = abs($num);
          $absClosest = abs($closest);
    
          if ($absNum < $absClosest) 
          {
            $closest = $num;
          } 
          elseif ($absNum === $absClosest && $num > $closest) 
          {
            // Tie: prefer positive value
            $closest = $num;
          }
        }
        return $closest;
    }
    
    ?>
    • function closestToZero(array $ints) {
    • $closest = 0;
    • $result = 0;
    • $total = count($ints);
    • for($i=0; $i < $total; $i++)
    • function closestToZero(array $ints): int|float|null
    • {
    • if(!isset($ints[0])) return null;
    • $closest = $ints[0];
    • foreach ($ints as $num)
    • {
    • $n = $ints[$i];
    • $m = $n;
    • if ($n == 0)
    • $absNum = abs($num);
    • $absClosest = abs($closest);
    • if ($absNum < $absClosest)
    • {
    • return 0;
    • }
    • if ($n < 0)
    • $closest = $num;
    • }
    • elseif ($absNum === $absClosest && $num > $closest)
    • {
    • $n *= -1;
    • // Tie: prefer positive value
    • $closest = $num;
    • }
    • if ($result + $m == 0)
    • {
    • $result = $n;
    • }
    • if ($closest > $n || $i == 0) {
    • $closest = $n;
    • $result = $m;
    • }
    • }
    • return $result;
    • }
    • return $closest;
    • }
    • ?>
Fundamentals
Code
Diff
  • d=lambda:"⚀"
    • import random as r
    • class Dice:
    • def __init__(self, faces):self.faces = r.choice(faces)
    • def __call__(self):return self.faces
    • dice = Dice(["⚀", "⚁", "⚂", "⚃", "⚄", "⚅"])
    • d=lambda:"⚀"
Code
Diff
  • class IsPrimeNumber:
        """Returns True if n is a prime number, False otherwise"""
    
        def __init__(self, n):
            self.n = n
    
        def calculate(self):
            if self.n > 1:
                for i in range(2, int(self.n ** 0.5) + 1): 
                    if self.n % i == 0:
                        return False
                return True  # If no divisors found, it's prime
            return False
    
    
    class Fizz(IsPrimeNumber):
        """Returns True if n is divisible by 3, False otherwise"""
    
        def calculate(self):
            return self.n % 3 == 0
    
    
    class Buzz(IsPrimeNumber):
        """Returns True if n is divisible by 5, False otherwise"""
    
        def calculate(self):
            return self.n % 5 == 0
    
    
    class FizzBuzz(IsPrimeNumber):
        """Returns True if n is divisible by 3 and 5, False otherwise"""
    
        def calculate(self):
            return Fizz(self.n).calculate() and Buzz(self.n).calculate()
    
    
    class CodeWarKata776:
        """Executes the Fizz, Bizz, FizzBuzz Prime sequence."""
        def __init__(self, n):
            self.n = n
    
        def calculate_prime(self):
            return IsPrimeNumber(self.n).calculate()
    
        def calculate_fizz(self):
            return Fizz(self.n).calculate()
    
        def calculate_buzz(self):
            return Buzz(self.n).calculate()
    
        def calculate_fizzbuzz(self):
            return FizzBuzz(self.n).calculate()
    
        def execute(self):
            if IsPrimeNumber(self.n).calculate():
                return 'Prime'
            if FizzBuzz(self.n).calculate():
                return 'FizzBuzz'
            elif Fizz(self.n).calculate():
                return 'Fizz'
            elif Buzz(self.n).calculate():
                return 'Buzz'
            return self.n
    • class IsPrimeNumber:
    • """Returns True if n is a prime number, False otherwise"""
    • def __init__(self, n):
    • self.n = n
    • def calculate(self):
    • if self.n > 1:
    • for i in range(2, int(self.n ** 0.5) + 1):
    • if self.n % i == 0:
    • return False
    • return True # If no divisors found, it's prime
    • else:
    • return False
    • return False
    • class Fizz:
    • class Fizz(IsPrimeNumber):
    • """Returns True if n is divisible by 3, False otherwise"""
    • def __init__(self, n):
    • self.n = n
    • def calculate(self):
    • return self.n % 3 == 0
    • class Buzz:
    • class Buzz(IsPrimeNumber):
    • """Returns True if n is divisible by 5, False otherwise"""
    • def __init__(self, n):
    • self.n = n
    • def calculate(self):
    • return self.n % 5 == 0
    • class FizzBuzz:
    • class FizzBuzz(IsPrimeNumber):
    • """Returns True if n is divisible by 3 and 5, False otherwise"""
    • def __init__(self, n):
    • self.n = n
    • def calculate(self):
    • return Fizz(self.n).calculate() and Buzz(self.n).calculate()
    • class CodeWarKata776:
    • """Executes the Fizz, Bizz, FizzBuzz Prime sequence."""
    • def __init__(self, n):
    • self.n = n
    • def calculate_prime(self):
    • return IsPrimeNumber(self.n).calculate()
    • def calculate_fizz(self):
    • return Fizz(self.n).calculate()
    • def calculate_buzz(self):
    • return Buzz(self.n).calculate()
    • def calculate_fizzbuzz(self):
    • return FizzBuzz(self.n).calculate()
    • def execute(self):
    • if IsPrimeNumber(self.n).calculate():
    • return 'Prime'
    • if FizzBuzz(self.n).calculate():
    • return 'FizzBuzz'
    • elif Fizz(self.n).calculate():
    • return 'Fizz'
    • elif Buzz(self.n).calculate():
    • return 'Buzz'
    • else:
    • return self.n
    • return self.n

lambda goes brr

Code
Diff
  • multiply_and_add_one = lambda a, b: a * b + 1
    
        
    
    • def multiply_and_add_one(a, b): return a * b + 1
    • multiply_and_add_one = lambda a, b: a * b + 1
Ciphers
Fundamentals
Code
Diff
  • #include <ctype.h>
    #include <stdbool.h>
    #include <stdlib.h>
    #include <string.h>
    
    char *
    caesar_cypher (const char *input, int amount, bool reversed, bool encode,
                   bool ignore_special_chars, bool match_case)
    {
      char *res = malloc (strlen(input) + 1);
      char *p   = res;
      amount    = (amount % 26) * (2 * (encode ^ reversed) - 1);
      
      for (; *input; input++)
        {
          char c = *input;
          if (!isalpha (c))
            {
              if (!ignore_special_chars)
                *p++ = c;
              continue;
            }
          char s = ((toupper (c) + amount - 39) % 26) + 65;
          *p++ = match_case && islower (c) ? tolower (s) : s;
        }
      
      return *p = '\0', res;
    }
    • func caesarCypher(
    • _ input: String,
    • amount: Int,
    • reversed: Bool = false,
    • encode: Bool = true,
    • ignoreSpecialChars: Bool = false,
    • matchCase: Bool = true
    • ) -> String {
    • let alphabet = Array("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    • return input.map { character in
    • let char = Character(character.uppercased())
    • guard alphabet.contains(char) else {
    • return ignoreSpecialChars ? "" : String(char)
    • }
    • var newIndex = alphabet.firstIndex(of: char)!
    • switch encode {
    • case true:
    • newIndex += (reversed ? -amount : amount)
    • case false:
    • newIndex += (reversed ? amount : -amount)
    • #include <ctype.h>
    • #include <stdbool.h>
    • #include <stdlib.h>
    • #include <string.h>
    • char *
    • caesar_cypher (const char *input, int amount, bool reversed, bool encode,
    • bool ignore_special_chars, bool match_case)
    • {
    • char *res = malloc (strlen(input) + 1);
    • char *p = res;
    • amount = (amount % 26) * (2 * (encode ^ reversed) - 1);
    • for (; *input; input++)
    • {
    • char c = *input;
    • if (!isalpha (c))
    • {
    • if (!ignore_special_chars)
    • *p++ = c;
    • continue;
    • }
    • (newIndex < 0) ? (newIndex += 26) : ()
    • (newIndex >= 26) ? (newIndex -= 26) : ()
    • return (char.isLowercase && matchCase)
    • ? alphabet[newIndex].lowercased() : alphabet[newIndex].uppercased()
    • }.joined()
    • char s = ((toupper (c) + amount - 39) % 26) + 65;
    • *p++ = match_case && islower (c) ? tolower (s) : s;
    • }
    • return *p = '\0', res;
    • }

Return True if argument is greater than 2. Otherwise, make the argument greater than 2

Sinnlos..

Code
Diff
  • #If it is not true currently, I shall make it true
    def above_two(arg):
        if (arg < 2):
            arg = 3
        return True
    • #If it is not true currently, I shall make it true
    • def above_two(arg):
    • if not(arg > 2):
    • while not(arg > 2):
    • arg += 1
    • return True
    • if (arg < 2):
    • arg = 3
    • return True