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
  • pub struct Person {
        pub first_name: String,
        pub last_name: String
    }
    
    impl Person {
        pub fn new(first_name: String, last_name: String) -> Self {
            Self { first_name, last_name }
        }
        
        pub fn full_name(&self) -> String {
            format!("{} {}", self.first_name, self.last_name)
        }
    }
    • class Person {
    • String firstName;
    • String lastName;
    • Person(this.firstName,this.lastName);
    • pub struct Person {
    • pub first_name: String,
    • pub last_name: String
    • }
    • impl Person {
    • pub fn new(first_name: String, last_name: String) -> Self {
    • Self { first_name, last_name }
    • }
    • pub fn full_name(&self) -> String {
    • format!("{} {}", self.first_name, self.last_name)
    • }
    • }
Code
Diff
  • fn pekora<T, U>(_: T, _: U) -> &'static str {
        "candy"
    }
    
    fn add<T>(_: T) -> &'static str {
        "candy"
    }
    • pekora(a,b)=> 'candy';
    • add(a)=> 'candy';
    • fn pekora<T, U>(_: T, _: U) -> &'static str {
    • "candy"
    • }
    • fn add<T>(_: T) -> &'static str {
    • "candy"
    • }

O(n) solution

Code
Diff
  • use std::collections::BTreeSet;
    
    fn string_editor(s: &str) -> String {
        let mut present = BTreeSet::new();
        let mut doubled = BTreeSet::new();
        for c in s.chars() {
            if present.contains(&c) {
                doubled.insert(c);
            } else {
                present.insert(c);
            }
        }
     
        s.chars().filter(|c| doubled.contains(c)).collect()
    }
    • #include <stdlib.h>
    • #include <stdio.h>
    • #include <string.h>
    • use std::collections::BTreeSet;
    • char* string_editor(char* str)
    • {
    • char temp = 0;
    • char size = (char)strlen(str);
    • char *new = (char*)calloc(size,sizeof(char));
    • for (char i = 0; i < size; i++)
    • for (char j = 0; j < size; j++)
    • if ((str[i] == str[j]) && (i != j))
    • new[temp++] = str[i];
    • new[temp] ='\0';
    • return new;
    • fn string_editor(s: &str) -> String {
    • let mut present = BTreeSet::new();
    • let mut doubled = BTreeSet::new();
    • for c in s.chars() {
    • if present.contains(&c) {
    • doubled.insert(c);
    • } else {
    • present.insert(c);
    • }
    • }
    • s.chars().filter(|c| doubled.contains(c)).collect()
    • }
Code
Diff
  • mod preloaded;
    use preloaded::Instruction;
    
    use std::iter::{once, repeat};
    
    fn string_to_brainf(s: &str) -> Vec<Instruction> {
        s.chars()
            .flat_map(|c| {
                once(Instruction::Right)
                    .chain(repeat(Instruction::Increment).take(c as usize))
                    .chain(once(Instruction::Output))
            })
            .collect()
    }
    • #include <stdio.h>
    • #include <string.h>
    • // #define DEBUG
    • mod preloaded;
    • use preloaded::Instruction;
    • char s[4096] = "";
    • int s2b(int argc, char *argv[]) {
    • register int i = 0,j;
    • register int k,m;
    • register int l,last = 0;
    • if (argc != 2) {
    • printf("Usage: %s [string]",*argv);
    • return 1;
    • }
    • while (argv[1][++i]!=0)
    • continue;
    • for (j=0; j<i; j++) {
    • register int t;
    • t = argv[1][j];
    • l = k = t-last;
    • last = t;
    • #ifdef DEBUG
    • printf("\n%d, %d, %d, %d\n",last,k,j,i);
    • #endif
    • use std::iter::{once, repeat};
    • if (k >= 0) {
    • k >>= 3; // k /= 8
    • l &= 7; //在更多的机器工作,求余
    • if (k == 1)
    • strcat(s,">++++++++");
    • else {
    • if (k != 0) {
    • strcat(s,"++++++++[>");
    • for (m=0; m<k; m++)
    • strcat(s,"+");
    • strcat(s,"<-]>");
    • } else {
    • strcat(s,">");
    • }
    • }
    • for (m=0; m<l; m++)
    • strcat(s,"+");
    • strcat(s,".");
    • } else {
    • k = -k >> 3; // k /= 8
    • l = -l & 7; //在更多的机器工作,求余
    • if (k == 1)
    • strcat(s,">--------");
    • else {
    • strcat(s,"++++++++[>");
    • for (m=0; m<k; m++)
    • strcat(s,"-");
    • strcat(s,"<-]>");
    • }
    • for (m=0; m<l; m++)
    • strcat(s,"-");
    • strcat(s,".");
    • }
    • #ifdef DEBUG
    • printf("\n%d, %d, %d\n",m,k,l);
    • #endif
    • strcat(s,"<");
    • }
    • return 0;
    • fn string_to_brainf(s: &str) -> Vec<Instruction> {
    • s.chars()
    • .flat_map(|c| {
    • once(Instruction::Right)
    • .chain(repeat(Instruction::Increment).take(c as usize))
    • .chain(once(Instruction::Output))
    • })
    • .collect()
    • }
Fundamentals
Strings

This code now shows how reversing a string works. Reversing a string is just changing the order in which a string is read. New test cases have been added too. If you really wanted the shortest code possible, I am very sorry to upset you. But I can change it if you want to.

Code
Diff
  • def flip_str(string):
        idx = -1  # Start index for reversing
        new_string = ""  # Create an empty string to store the reversed string
        for val in string:
            new_string += string[idx]  # Add characters from the original string in reverse order
            idx -= 1  # Move to the previous character in the original string
        return new_string
    • reverse_string = lambda string: "".join(reversed(string))
    • def flip_str(string):
    • idx = -1 # Start index for reversing
    • new_string = "" # Create an empty string to store the reversed string
    • for val in string:
    • new_string += string[idx] # Add characters from the original string in reverse order
    • idx -= 1 # Move to the previous character in the original string
    • return new_string
Arrays

Changed function name to be more descriptive.

Changed return type to avoid representation of invalid states.

Code
Diff
  • use std::collections::BTreeMap;
    
    fn winning_set_size<T: Ord>(numbers: [T; 5]) -> Option<u8> {
        let mut counts = BTreeMap::new();
        for number in numbers {
            *counts.entry(number).or_default() += 1;
        }
        let largest_set_size = counts.into_values().max().unwrap();
        if largest_set_size >= 2 {
            Some(largest_set_size)
        } else {
            None
        }
    }
    • function isWinner(lineInfo){
    • use std::collections::BTreeMap;
    • fn winning_set_size<T: Ord>(numbers: [T; 5]) -> Option<u8> {
    • let mut counts = BTreeMap::new();
    • for number in numbers {
    • *counts.entry(number).or_default() += 1;
    • }
    • let largest_set_size = counts.into_values().max().unwrap();
    • if largest_set_size >= 2 {
    • Some(largest_set_size)
    • } else {
    • None
    • }
    • }
Data Science
Sorting
Code
Diff
  • use std::cmp::Reverse;
    
    fn sort_by_salary<'a>(workers: &[(&'a str, i32)]) -> Vec<&'a str> {
        let mut workers = workers.to_vec();
        workers.sort_by_key(|&(_, salary)| Reverse(salary));
        workers.into_iter().map(|(name, _)| name).collect()
    }
    • def sort_by_salary(workers):
    • filtered = list(filter(lambda x: x[1] != "-", workers))
    • if not filtered:
    • return tuple()
    • new = list(sorted(filtered, key=lambda x: int(x[1])))[::-1]
    • return tuple(i[0] for i in new)[:5]
    • use std::cmp::Reverse;
    • fn sort_by_salary<'a>(workers: &[(&'a str, i32)]) -> Vec<&'a str> {
    • let mut workers = workers.to_vec();
    • workers.sort_by_key(|&(_, salary)| Reverse(salary));
    • workers.into_iter().map(|(name, _)| name).collect()
    • }
Strings

Added proper handling of characters that expand when capitalized.

Ajouté la propre gestion des caractères qui se multiplient lorsqu'ils sont capitalisés.

Code
Diff
  • fn maestro_split(s: &str) -> String {
        let milieu = s.chars().count() / 2;
        let mut lettres = s.chars();
        let côté_gauche: String = (&mut lettres).take(milieu).flat_map(char::to_lowercase).collect();
        let lettre_majuscule = lettres.next().map(|c| c.to_uppercase().to_string()).unwrap_or_default();
        let côté_droite: String = lettres.flat_map(char::to_lowercase).collect();
        format!("{lettre_majuscule}{côté_droite}{côté_gauche}")
    }
    
    fn approche_naïf(s: &str) -> String {
        if s.is_empty() {
            return String::new();
        }
        let mid = s.len() / 2;
        format!("{}{}{}", s[mid..mid+1].to_uppercase(), s[mid+1..].to_lowercase(), s[..mid].to_lowercase())
    }
    • function maestroSplit(string) {
    • let newWord = string.slice(parseInt(string.length / 2)) + string.slice(0, parseInt(string.length / 2));
    • return newWord.toLowerCase().charAt(0).toUpperCase() + newWord.toLowerCase().slice(1);
    • fn maestro_split(s: &str) -> String {
    • let milieu = s.chars().count() / 2;
    • let mut lettres = s.chars();
    • let côté_gauche: String = (&mut lettres).take(milieu).flat_map(char::to_lowercase).collect();
    • let lettre_majuscule = lettres.next().map(|c| c.to_uppercase().to_string()).unwrap_or_default();
    • let côté_droite: String = lettres.flat_map(char::to_lowercase).collect();
    • format!("{lettre_majuscule}{côté_droite}{côté_gauche}")
    • }
    • fn approche_naïf(s: &str) -> String {
    • if s.is_empty() {
    • return String::new();
    • }
    • let mid = s.len() / 2;
    • format!("{}{}{}", s[mid..mid+1].to_uppercase(), s[mid+1..].to_lowercase(), s[..mid].to_lowercase())
    • }
Code
Diff
  • fn other_angle(angle1: u32, angle2: u32) -> u32 {
        180 - (angle1 + angle2)
    }
    • public class ThirdAngle {
    • public static int otherAngle(int angle1, int angle2) {
    • return 180-(angle1+angle2);
    • }
    • fn other_angle(angle1: u32, angle2: u32) -> u32 {
    • 180 - (angle1 + angle2)
    • }
Code
Diff
  • fn find_index(slice: &[i32], value: i32) -> Option<usize> {
        slice.iter().position(|&num| num == value)
    }
    • public class Kata {
    • public static int findIndex (int[] my_array, int t) {
    • // Find the index of t
    • return 4;
    • }
    • fn find_index(slice: &[i32], value: i32) -> Option<usize> {
    • slice.iter().position(|&num| num == value)
    • }