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
  • 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;
    • }
    • }
Code
Diff
  • // lovely
    //hi
    //hi
    fn calc_gpa(grades: &str) -> f64 {
        let grade_points: Vec<f64> = grades
            .split_whitespace()
            .flat_map(str::parse)
            .map(|grade| match grade {
                90..=100 => 4.0,
                80..=89 => 3.0,
                70..=79 => 2.0,
                60..=69 => 1.0,
                _ => 0.0
            })
            .collect();
        
        grade_points.iter().sum::<f64>() / grade_points.len() as f64
    }
    • // lovely
    • //hi
    • //hi
    • fn calc_gpa(grades: &str) -> f64 {
    • let grade_points: Vec<f64> = grades
    • .split_whitespace()
    • .flat_map(str::parse)
    • .map(|grade| match grade {
    • 90..=100 => 4.0,
    • 80..=89 => 3.0,
    • 70..=79 => 2.0,
    • 60..=69 => 1.0,
    • _ => 0.0
    • })
    • .collect();
    • grade_points.iter().sum::<f64>() / grade_points.len() as f64
    • }

Two pass solution. O(n) space, O(n) time

Code
Diff
  • use std::{collections::HashSet, hash::Hash};
    
    fn last_unique<T: Eq + Hash>(arr: &[T]) -> Option<&T> {
        let mut one = HashSet::new();
        let mut multiple = HashSet::new();
        for e in arr {
            if multiple.contains(e) {
                continue;
            }
            if one.remove(e) {
                multiple.insert(e);
            } else {
                one.insert(e);
            }
        }
        arr.iter().rev().find(|e| one.contains(e))
    }
    • fn last_unique<T: Eq>(arr: &[T]) -> Option<&T> {
    • arr.iter().rev().find(|e| arr.iter().filter(|n| n == e).count() == 1)
    • use std::{collections::HashSet, hash::Hash};
    • fn last_unique<T: Eq + Hash>(arr: &[T]) -> Option<&T> {
    • let mut one = HashSet::new();
    • let mut multiple = HashSet::new();
    • for e in arr {
    • if multiple.contains(e) {
    • continue;
    • }
    • if one.remove(e) {
    • multiple.insert(e);
    • } else {
    • one.insert(e);
    • }
    • }
    • arr.iter().rev().find(|e| one.contains(e))
    • }
Code
Diff
  • max_sequence = lambda arr: max(0, max((sum(arr[i:j]) for i in range(len(arr)) for j in range(i+1, len(arr)+1)), default=0))
    • max_sequence = lambda arr :max([sum(arr)] + [sum(arr[j:j+i]) for i in range(len(arr)) for j in range(len(arr) - i + 1)])
    • max_sequence = lambda arr: max(0, max((sum(arr[i:j]) for i in range(len(arr)) for j in range(i+1, len(arr)+1)), default=0))
Code
Diff
  • use itertools::Itertools;
    use std::str::from_utf8;
    
    fn insert(separator: &str, interval: usize, string: &str) -> String {
        if interval == 0 { return string.into() }
        string
            .as_bytes()
            .chunks(interval)
            .map(|bytes| from_utf8(bytes).unwrap())
            .join(separator)
    }
    • use itertools::Itertools;
    • use std::str::from_utf8;
    • fn insert(separator: &str, interval: usize, string: &str) -> String {
    • if interval == 0 { return string.into() }
    • let mut output = String::new();
    • for (index, character) in string.chars().enumerate() {
    • if index != 0 && index % interval == 0 {
    • output.push_str(separator);
    • }
    • output.push(character);
    • }
    • output
    • string
    • .as_bytes()
    • .chunks(interval)
    • .map(|bytes| from_utf8(bytes).unwrap())
    • .join(separator)
    • }