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
  • struct Developer {
        language: Language
        /* left out the rest because it would just generate unused warnings */
    }
    
    enum Language {
        Python,
        Ruby,
        JavaScript
    }
    
    fn is_language_diverse(list: &[Developer]) -> bool {
        let (mut python, mut ruby, mut javascript) = (0, 0, 0);
        for developer in list {
            match developer.language {
                Language::Python => python += 1,
                Language::Ruby => ruby += 1,
                Language::JavaScript => javascript += 1,
            }
        }
        python.max(ruby).max(javascript) <= 2 * python.min(ruby).min(javascript)
    }
    
    
    • function isLanguageDiverse(list) {
    • const counts = {};
    • for (let i = 0; i < list.length; i++) { // ho usato un ciclo for per contare quante volte appare un linguaggio
    • const language = list[i].language; // ho assegnato il linguaggio corrente a una variabile
    • counts[language] = counts[language] ? counts[language] + 1 : 1; // ho usato un operatore ternario per incrementare il contatore
    • }
    • const countsValues = Object.values(counts); // ho usato Object.values per ottenere i valori dell'oggetto counts
    • const maxCount = Math.max(...countsValues); // ho usato Math.max per trovare il valore massimo
    • const minCount = Math.min(...countsValues); // ho usato Math.min per trovare il valore minimo
    • return maxCount <= 2 * minCount; // ho usato un operatore ternario per restituire true o false
    • }
    • //Test cases
    • struct Developer {
    • language: Language
    • /* left out the rest because it would just generate unused warnings */
    • }
    • const list1 = [{ firstName: 'Daniel', lastName: 'J.', country: 'Aruba', continent: 'Americas', age: 42, language: 'Python' },
    • { firstName: 'Kseniya', lastName: 'T.', country: 'Belarus', continent: 'Europe', age: 22, language: 'Ruby' },
    • { firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 43, language: 'Ruby' },
    • { firstName: 'Hanna', lastName: 'L.', country: 'Hungary', continent: 'Europe', age: 95, language: 'JavaScript' },
    • { firstName: 'Jayden', lastName: 'P.', country: 'Jamaica', continent: 'Americas', age: 18, language: 'JavaScript' },
    • { firstName: 'Joao', lastName: 'D.', country: 'Portugal', continent: 'Europe', age: 25, language: 'JavaScript' }];
    • enum Language {
    • Python,
    • Ruby,
    • JavaScript
    • }
    • const list2 = [{ firstName: 'Daniel', lastName: 'J.', country: 'Aruba', continent: 'Americas', age: 42, language: 'Python' },
    • { firstName: 'Kseniya', lastName: 'T.', country: 'Belarus', continent: 'Europe', age: 22, language: 'Ruby' },
    • { firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 43, language: 'Ruby' },
    • { firstName: 'Hanna', lastName: 'L.', country: 'Hungary', continent: 'Europe', age: 95, language: 'JavaScript' },
    • { firstName: 'Jayden', lastName: 'P.', country: 'Jamaica', continent: 'Americas', age: 18, language: 'JavaScript' },
    • { firstName: 'Joao', lastName: 'D.', country: 'Portugal', continent: 'Europe', age: 25, language: 'JavaScript' },
    • { firstName: 'Joao', lastName: 'D.', country: 'Portugal', continent: 'Europe', age: 25, language: 'JavaScript' }];
    • fn is_language_diverse(list: &[Developer]) -> bool {
    • let (mut python, mut ruby, mut javascript) = (0, 0, 0);
    • for developer in list {
    • match developer.language {
    • Language::Python => python += 1,
    • Language::Ruby => ruby += 1,
    • Language::JavaScript => javascript += 1,
    • }
    • }
    • python.max(ruby).max(javascript) <= 2 * python.min(ruby).min(javascript)
    • }
    • console.log(isLanguageDiverse(list1)); // false
    • console.log(isLanguageDiverse(list2)); // true
Code
Diff
  • trait HasAge {
        fn age(&self) -> i32;
    }
    
    fn find_oldest<T: HasAge + Clone>(list: &[T]) -> Vec<T> {
        if let Some(max_age) = list.iter().map(T::age).max() {
            list.iter().filter(|e| e.age() == max_age).cloned().collect()        
        } else {
            Vec::new()
        }
    }
    • mod preloaded;
    • use preloaded::Developer;
    • trait HasAge {
    • fn age(&self) -> i32;
    • }
    • fn find_senior(list: &[Developer]) -> Vec<Developer> {
    • let max_age = list.iter().map(|d| d.age).max().unwrap();
    • list.iter().filter(|d| d.age == max_age).copied().collect()
    • fn find_oldest<T: HasAge + Clone>(list: &[T]) -> Vec<T> {
    • if let Some(max_age) = list.iter().map(T::age).max() {
    • list.iter().filter(|e| e.age() == max_age).cloned().collect()
    • } else {
    • Vec::new()
    • }
    • }
Code
Diff
  • function calculateEvenNumbers(array $numbers): int {
      return count(array_filter($numbers, function($num) { return $num % 2 === 0; }));
    }
    • function calculateEvenNumbers(array $numbers): int {
    • $count = 0;
    • foreach ($numbers as $number) {
    • if ($number % 2 === 0) {
    • $count++;
    • }
    • }
    • return $count;
    • return count(array_filter($numbers, function($num) { return $num % 2 === 0; }));
    • }

fix the code lol

Code
Diff
  • #include <stdio.h>
    
    int prnt_mltply(int m, int n) {
        int i = 1;
        while(i <= m) {
            int j = 1;
            while(j <= n) {
                printf("%d * %d = %d \n", i, j, i * j);
                j++;
            }
            i++;
            printf("\n");
        }
        return m - n;
    }
    • #include<stdio.h>
    • int main()
    • {
    • int i=1;
    • while(i<=5)
    • {
    • int j=1;
    • while(j<=12)
    • {
    • printf("%d * %d =%d
    • ", i,j, i*j);
    • j++;
    • #include <stdio.h>
    • int prnt_mltply(int m, int n) {
    • int i = 1;
    • while(i <= m) {
    • int j = 1;
    • while(j <= n) {
    • printf("%d * %d = %d
    • ", i, j, i * j);
    • j++;
    • }
    • i++;
    • printf("\n");
    • }
    • i++;
    • printf("\n");
    • }
    • return(0);
    • return m - n;
    • }
Code
Diff
  • Greeting=lambda name,rank="",formal=0: f"He{('y','llo')[formal]}, {rank*formal}{' '*bool(rank and formal)}{name}{'!.'[formal]}"
    • greeting=Greeting=lambda name,rank='',formal=False:"He{0}, {1}{2}{3}{4}".format(('y','llo')[formal],rank*formal,' '*bool(rank and formal),name,'!.'[formal])
    • Greeting=lambda name,rank="",formal=0: f"He{('y','llo')[formal]}, {rank*formal}{' '*bool(rank and formal)}{name}{'!.'[formal]}"

with some machine code!

Code
Diff
  • import ctypes
    import mmap
    
    buf = mmap.mmap(-1, mmap.PAGESIZE, prot=mmap.PROT_READ | mmap.PROT_WRITE | mmap.PROT_EXEC)
    
    ftype = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int)
    fpointer = ctypes.c_void_p.from_buffer(buf)
    
    multiply = ftype(ctypes.addressof(fpointer))
    
    buf.write( 
        b'\x89\xf8' # mov eax, esi
        b'\xf7\xe6' # mul esi
        b'\xc3'     # ret
    )
    
    
    
    • def multiply(a,b):
    • return a*b
    • import ctypes
    • import mmap
    • buf = mmap.mmap(-1, mmap.PAGESIZE, prot=mmap.PROT_READ | mmap.PROT_WRITE | mmap.PROT_EXEC)
    • ftype = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int)
    • fpointer = ctypes.c_void_p.from_buffer(buf)
    • multiply = ftype(ctypes.addressof(fpointer))
    • buf.write(
    • b'\x89\xf8' # mov eax, esi
    • b'\xf7\xe6' # mul esi
    • b'\xc3' # ret
    • )
    • result = multiply(5,10)
    • print(result)
Code
Diff
  • import java.util.Arrays;
    
    public class MaxNumber {
        public static long print(long number) {
            long result = 0;
    
            String digitsString = String.valueOf(number);
            long digits[] = new long[digitsString.length()];
    
            for (int i = 0; i < digitsString.length(); i++){
              long digit = Character.getNumericValue(digitsString.charAt(i));
              digits[i] = digit;
            }
    
            Arrays.sort(digits);
    
            for (int i = 0; i < digits.length; i ++){
              result = result + digits[i] * (long)(Math.pow(10, i));
            }
            return result;    
        }
    }
    • import java.util.Arrays;
    • public class MaxNumber {
    • public static long print(long number) {
    • return number
    • long result = 0;
    • String digitsString = String.valueOf(number);
    • long digits[] = new long[digitsString.length()];
    • for (int i = 0; i < digitsString.length(); i++){
    • long digit = Character.getNumericValue(digitsString.charAt(i));
    • digits[i] = digit;
    • }
    • Arrays.sort(digits);
    • for (int i = 0; i < digits.length; i ++){
    • result = result + digits[i] * (long)(Math.pow(10, i));
    • }
    • return result;
    • }
    • }