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
  • public class Kumite {
      public static bool IsThree(int x) =>
        $"{x}".Contains('3');
    }
    • public class Kumite {
    • public static bool IsThree(int x) =>
    • x.ToString().Contains('3');
    • $"{x}".Contains('3');
    • }

Inlined

Code
Diff
  • inline float AreaOfTriangle(float w, float h) {return w * h / 2;} //inlined
    • float AreaOfTriangle(float w, float h) {return (w * h) / 2;} //Get one-lined
    • inline float AreaOfTriangle(float w, float h) {return w * h / 2;} //inlined

Write a function that accepts an integer (n) and calculates the multiples of 4 or 6 up to n but not including the input number n.

Return the sum of those multiples.

For example:

n = 20 ==> 64

n = 35 ==> 198

n = 120 ==> 2340

Code
Diff
  • def find_multiples(n):
        total = 0
        for i in range(0, n, 2):
            if i % 4 == 0 or i % 6 == 0:
                total += i
        return total
    
    
    • def find_multiples(n):
    • total = 0
    • for i in range(0, n, 2):
    • if i % 4 == 0 or i % 6 == 0:
    • total += i
    • return total
    • return total

Type checking??

Code
Diff
  • const isDivisible = (n, x, y) => n % x === 0 && n % y === 0;
    
    • const isDivisible = (n, x, y) => n % x == 0 && n % y == 0;
    • const isDivisible = (n, x, y) => n % x === 0 && n % y === 0;
Fundamentals
Code
Diff
  • extern printf
    
    SECTION .text
    global hello
    
    hello:
      xor rax, rax
      mov rdi, msg
      mov rsi, nasm
      call printf
      mov rax, 1
      ret
    
    SECTION .data
    msg: db "Hello %s", 10, 0
    nasm: db "NASM", 0
    • #include <iostream>
    • #include <string>
    • extern printf
    • int helloCplusplus(){
    • std::string str = "Hello, C++!";
    • std::cout << str << '\n';
    • return 0;
    • }
    • SECTION .text
    • global hello
    • hello:
    • xor rax, rax
    • mov rdi, msg
    • mov rsi, nasm
    • call printf
    • mov rax, 1
    • ret
    • SECTION .data
    • msg: db "Hello %s", 10, 0
    • nasm: db "NASM", 0
Code
Diff
  • def converter(number):
        numbers = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
        if 0 <= number and number <= 9:
            return numbers[number]
        else:
            return number
    
    • def converter(number):
    • match number:
    • case 0:
    • return 'zero'
    • case 1:
    • return 'one'
    • case 2:
    • return 'two'
    • case 3:
    • return 'three'
    • case 4:
    • return 'four'
    • case 5:
    • return 'five'
    • case 6:
    • return 'six'
    • case 7:
    • return 'seven'
    • case 8:
    • return 'eight'
    • case 9:
    • return 'nine'
    • case _:
    • return number
    • numbers = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
    • if 0 <= number and number <= 9:
    • return numbers[number]
    • else:
    • return number
Code
Diff
  • def power(n, p):
        return pow(n, p)
    
    • def power(num, p):
    • return num ** p
    • def power(n, p):
    • return pow(n, p)
Code
Diff
  • from re import findall as fa
    
    # This can all be done on one line. I expanded it to be easier to read.
    def to_camel_case(text:str, fw=False) -> str:
        out = ''
        for w in fa(r'([a-zA-Z0-9]*)', text):
            out = f'{out}{(w, w.capitalize())[fw]}'
            fw  = True
        return out
    • def to_camel_case(text: str):
    • split_chars = "-_"
    • # loop over each character above
    • for split_char in split_chars:
    • split_parts = text.split(split_char)
    • # skip if there was nothing to split on
    • if len(split_parts) == 1:
    • continue
    • parts = []
    • # break up the string in to it's parts
    • for i, item in enumerate(split_parts):
    • # save the first part but don't change the case of the first letter
    • if i == 0:
    • parts.append(item)
    • continue
    • parts.append(f"{item[0].upper()}{item[1:]}")
    • # join the parts and overwrite the text variable for the next loop
    • text = "".join(parts)
    • return text
    • from re import findall as fa
    • # This can all be done on one line. I expanded it to be easier to read.
    • def to_camel_case(text:str, fw=False) -> str:
    • out = ''
    • for w in fa(r'([a-zA-Z0-9]*)', text):
    • out = f'{out}{(w, w.capitalize())[fw]}'
    • fw = True
    • return out

Write a method that returns the largest integer in the list.
You can assume that the list has at least one element.

.... sorting the array introduced unnecessary time complexity.

Code
Diff
  • import java.util.Arrays;
    
    public class Kata {
      
      public static int findMax(int[] intArray) {
    
        return Arrays.stream(intArray).reduce(Math::max).orElseThrow();
      }
      
    }
    
    • import java.util.*;
    • import java.util.Arrays;
    • public class Kata {
    • public static int findMax(int[] my_array) {
    • // Write a method that returns the largest integer in the list.
    • // You can assume that the list has at least one element.
    • Arrays.sort(my_array);
    • return (my_array[my_array.length-1]);
    • }
    • }
    • public static int findMax(int[] intArray) {
    • return Arrays.stream(intArray).reduce(Math::max).orElseThrow();
    • }
    • }
Code
Diff
  • def meaning_of_life_is(*args): return 42
    • def meaning_of_life_is(*args): return 40 + 2
    • def meaning_of_life_is(*args): return 42