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
  • fn binary_search(arr: &[i32], val: i32) -> Option<usize> {
        arr.binary_search(&val).ok()
    }
    
    • #returns the index of val if val is in the array, else -1 if val is not in the array.
    • #precondition: arr must be sorted in ascending order
    • def binary_search(arr,val):
    • i=-1
    • j=len(arr)
    • while i+1!=j:
    • m=i+(j-i)//2
    • if arr[m]<val:
    • i=m
    • elif arr[m]>val:
    • j=m
    • else:
    • return m
    • return -1
    • fn binary_search(arr: &[i32], val: i32) -> Option<usize> {
    • arr.binary_search(&val).ok()
    • }
Code
Diff
  • use rand::seq::SliceRandom;
    
    const EYES: [char; 4] = [':', ';', '=', 'X'];
    const ACCESSORIES: [char; 5] = ['\'', '.', '-', '~', '^'];
    const MOUTHS: [char; 10] = [']', '}', ')', '>', 'D', '\\', '(', '[', '{', 'O'];
    
    fn random_face() -> String {
        let mut rng = rand::thread_rng();
        format!(
            "{}{}{}",
            EYES.choose(&mut rng).unwrap(),
            ACCESSORIES.choose(&mut rng).unwrap(),
            MOUTHS.choose(&mut rng).unwrap()
        )
    }
    • from random import choice
    • eyes=":;=X"
    • accessory=["","'",".","-","~","^",""]
    • mouth="]})>D|\\([{O"
    • def random_smiley():
    • return choice(eyes)+choice(accessory)+choice(mouth)
    • use rand::seq::SliceRandom;
    • def many_faces():
    • acc=[]
    • for _ in range(100):
    • acc.append(random_smiley())
    • return " ".join(acc)
    • const EYES: [char; 4] = [':', ';', '=', 'X'];
    • const ACCESSORIES: [char; 5] = ['\'', '.', '-', '~', '^'];
    • const MOUTHS: [char; 10] = [']', '}', ')', '>', 'D', '\\', '(', '[', '{', 'O'];
    • # def garfield_the_1000_faced():
    • # acc=[]
    • # for _ in range(100)
    • fn random_face() -> String {
    • let mut rng = rand::thread_rng();
    • format!(
    • "{}{}{}",
    • EYES.choose(&mut rng).unwrap(),
    • ACCESSORIES.choose(&mut rng).unwrap(),
    • MOUTHS.choose(&mut rng).unwrap()
    • )
    • }
Code
Diff
  • mod preloaded;
    use preloaded::Stats;
    use std::cmp::Ordering;
    
    const THRESHOLD: u32 = 8;
    
    fn compute_progress(trainee: Stats, milestone: Stats) -> &'static str {    
        let attendance = check(trainee.attendance, milestone.attendance);
        let codewars = check(milestone.codewars, trainee.codewars);
        let tests = check(trainee.tests, milestone.tests);
        let pulls = check(trainee.pull_requests, milestone.pull_requests);
        
        let sum_factors = attendance + codewars + tests + pulls;
        
        match sum_factors.cmp(&THRESHOLD) {
            Ordering::Greater => "Beyond Milestone",
            Ordering::Equal => "At Milestone",
            Ordering::Less => "Behind Milestone"
        }
    }
    
    fn check(a: u32, b: u32) -> u32 {
        match a.cmp(&b) {
            Ordering::Greater => 3,
            Ordering::Equal => 2,
            Ordering::Less => 1,
        }
    }
    • const Deepa = {
    • attendance: 100,
    • tests: 4,
    • codewars: 7,
    • pullRequests: 12
    • }
    • const Bilal = {
    • attendance: 95,
    • tests: 3,
    • codewars: 7,
    • pullRequests: 12
    • }
    • const milestoneDay = {
    • attendance: 100,
    • tests: 4,
    • codewars: 7,
    • pullRequests: 12
    • }
    • mod preloaded;
    • use preloaded::Stats;
    • use std::cmp::Ordering;
    • const computeProgress = (trainee, milestone) => {
    • const comparator = Object.entries(milestoneDay).length * 2;
    • const checkMilestone = (factor, milestone) => factor > milestone ? 3 : factor === milestone ? 2 : 1;
    • // codewars ranks go down
    • const checkCodewars = (factor, milestone) => factor < milestone ? 3 : factor === milestone ? 2 : 1;
    • const THRESHOLD: u32 = 8;
    • // 1 behind, 2 at, 3 ahead, and there are currently 4 measures
    • // therefore at each milestone 8 is the currently the comparator
    • fn compute_progress(trainee: Stats, milestone: Stats) -> &'static str {
    • let attendance = check(trainee.attendance, milestone.attendance);
    • let codewars = check(milestone.codewars, trainee.codewars);
    • let tests = check(trainee.tests, milestone.tests);
    • let pulls = check(trainee.pull_requests, milestone.pull_requests);
    • let sum_factors = attendance + codewars + tests + pulls;
    • match sum_factors.cmp(&THRESHOLD) {
    • Ordering::Greater => "Beyond Milestone",
    • Ordering::Equal => "At Milestone",
    • Ordering::Less => "Behind Milestone"
    • }
    • }
    • let attendance = checkMilestone(trainee.attendance, milestone.attendance);
    • let codewars = checkCodewars(trainee.codewars, milestone.codewars);
    • let tests = checkMilestone(trainee.tests, milestone.tests);
    • let pulls = checkMilestone(trainee.pullRequests, milestone.pullRequests);
    • const sumFactors = codewars + tests + attendance + pulls;
    • return sumFactors > comparator ? 'Beyond Milestone' : sumFactors === comparator ? 'At Milestone' : 'Behind Milestone'
    • fn check(a: u32, b: u32) -> u32 {
    • match a.cmp(&b) {
    • Ordering::Greater => 3,
    • Ordering::Equal => 2,
    • Ordering::Less => 1,
    • }
    • }
Code
Diff
  • const numMinusSeven = (num) => Math.ceil(num/7);
    
    • function numMinusSeven(num) {
    • return Math.ceil(num/7);
    • }
    • const numMinusSeven = (num) => Math.ceil(num/7);
Code
Diff
  • mod preloaded;
    
    use preloaded::*;
    
    fn total_age_younger_than(people: &[Person], age: u32) -> u32 {
        people_younger_than(people, age)
            .map(|person| person.age)
            .sum()
    }
    
    fn hair_colors_younger_than(people: &[Person], age: u32) -> Vec<HairColor> {
        people_younger_than(people, age)
            .map(|person| person.hair_color)
            .collect()
    }
    
    fn people_younger_than(people: &[Person], age: u32) -> impl Iterator<Item = &Person> {
        people.iter().filter(move |person| person.age < age)
    }
    • // this code should fail the tests
    • // const totalAgeYoungerThan = (people, age) => {
    • // let totalAge = 0;
    • // for (let i = 0; i < people.length; i++) {
    • // if (people[i].age < age) totalAge += people[i].age;
    • // }
    • // return totalAge;
    • // }
    • mod preloaded;
    • // this code should fail the tests
    • // const totalAgeYoungerThan = (people, age) => {
    • // let totalAge = 0;
    • // for (let person of people) {
    • // if (person < age) totalAge += person.age;
    • // }
    • // return totalAge;
    • // }
    • use preloaded::*;
    • // this code should fail the tests
    • // const totalAgeYoungerThan = (people, age) => {
    • // if (people.length === 0) return 0;
    • // const [first, ...rest] = people;
    • // return (first.age < age ? first.age : 0) + totalAgeYoungerThan(rest, age);
    • // }
    • // this code should theoretically pass the tests
    • // it includes the word `for` but not in a for loop
    • // const totalAgeYoungerThan = (people, age) => {
    • // return people
    • // .filter(person => person.age < age)
    • // .reduce((formula, person) => formula + person.age, 0)
    • // }
    • fn total_age_younger_than(people: &[Person], age: u32) -> u32 {
    • people_younger_than(people, age)
    • .map(|person| person.age)
    • .sum()
    • }
    • const totalAgeYoungerThan = (people, age) => {
    • return people
    • .filter(person => person.age < age)
    • .reduce((sum, person) => sum + person.age, 0)
    • fn hair_colors_younger_than(people: &[Person], age: u32) -> Vec<HairColor> {
    • people_younger_than(people, age)
    • .map(|person| person.hair_color)
    • .collect()
    • }
    • const hairColorsYoungerThan = (people, age) => {
    • return people
    • .filter(person => person.age < age)
    • .map(person => person.hairColor)
    • fn people_younger_than(people: &[Person], age: u32) -> impl Iterator<Item = &Person> {
    • people.iter().filter(move |person| person.age < age)
    • }
Code
Diff
  • fn amongus(s: &str) -> Vec<usize> {
        (0..s.len().saturating_sub(2))
            .filter(|&i| s[i..i+3].to_ascii_lowercase() == "sus")
            .collect()
    }
    • def amongus(sus):
    • i=0
    • acc=[]
    • while i<len(sus)-2:
    • if sus[i:i+3].lower()=="sus":
    • acc.append(i)
    • i+=1
    • return acc
    • fn amongus(s: &str) -> Vec<usize> {
    • (0..s.len().saturating_sub(2))
    • .filter(|&i| s[i..i+3].to_ascii_lowercase() == "sus")
    • .collect()
    • }
Fundamentals
Strings
Code
Diff
  • def reverse_string(string):
        return string[::-1]
    
    • def reverse_string(string):
    • reversed_list = [string[letter] for letter in range(len(string) - 1, -1, -1)]
    • return "".join(reversed_list)
    • return string[::-1]
Code
Diff
  • fn to_upper_first(xs: &str) -> String {
        if xs.is_empty() {
            String::new()
        } else {
            xs[..1].to_uppercase() + &xs[1..]    
        }
    }
    
    • module ToupperFirst where
    • import Data.Char
    • toUpperFirst "" = ""
    • toUpperFirst xs = [toUpper (x) | x <- xs, x == head (xs)] ++ tail (xs)
    • fn to_upper_first(xs: &str) -> String {
    • if xs.is_empty() {
    • String::new()
    • } else {
    • xs[..1].to_uppercase() + &xs[1..]
    • }
    • }
Code
Diff
  • use std::iter::Sum;
    
    fn sum<T: Copy + Sum>(arr: &[T]) -> T {
        arr.iter().copied().sum()
    }
    
    • module Sum (Sum.sum) where
    • use std::iter::Sum;
    • import Prelude hiding (sum)
    • sum :: [Word] -> Word
    • sum = foldr1 (+)
    • fn sum<T: Copy + Sum>(arr: &[T]) -> T {
    • arr.iter().copied().sum()
    • }
Code
Diff
  • fn fibonacci(n: usize) -> u128 {
        let (mut n1, mut n2) = (1, 1);
        for _ in 2..n {
            (n1, n2) = (n2, n1 + n2);
        }
        n2
    }
    • import java.util.HashMap;
    • import java.util.Map;
    • public class Fibonacci {
    • private static Map<Integer, Long> memoizationMap = new HashMap<>();
    • public static long calcFibo(int n) {
    • if (n <= 1) {
    • return n;
    • }
    • if (memoizationMap.containsKey(n)) {
    • return memoizationMap.get(n);
    • }
    • long fiboValue = calcFibo(n - 1) + calcFibo(n - 2);
    • memoizationMap.put(n, fiboValue);
    • return fiboValue;
    • }
    • fn fibonacci(n: usize) -> u128 {
    • let (mut n1, mut n2) = (1, 1);
    • for _ in 2..n {
    • (n1, n2) = (n2, n1 + n2);
    • }
    • n2
    • }