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
Regular Expressions
Declarative Programming
Advanced Language Features
Programming Paradigms
Fundamentals
Strings

You could also just test your strings length.

Code
Diff
  • class StringParity {
      public static boolean isEvenLength(String str) {
        return str.length() % 2 == 0;
      }
    }
    • class StringParity {
    • public static boolean isEvenLength(String str) {
    • return str.replaceAll("(?s)..", "").isEmpty(); // (?s) enables DOTALL
    • return str.length() % 2 == 0;
    • }
    • }
Code
Diff
  • fn flip_the_number(x: &u64) -> u64 {
        let mut x = *x;
        let mut y = 0;
        while x != 0 {
            y = y * 10 + x % 10;
            x /= 10;
        }
        y
    }
    • fn flip_the_number(x: &u64) -> u64 {
    • x.to_string().chars().rev().collect::<String>().parse::<u64>().unwrap()
    • let mut x = *x;
    • let mut y = 0;
    • while x != 0 {
    • y = y * 10 + x % 10;
    • x /= 10;
    • }
    • y
    • }
Numbers
Data Types
Integers
Algorithms
Logic
Code
Diff
  • use std::collections::BTreeMap;
    
    fn digits(n: u64) -> usize {
        let powers = (0..20).map(|n| (
            if n == 0 { 0 } else { 10_u64.pow(n) },
            n as usize + 1
        )).collect::<BTreeMap<_, _>>();
        return *powers.range(..=n).last().unwrap().1;
    }
    • use std::collections::BTreeMap;
    • use std::ops::Bound::Unbounded;
    • use std::ops::Bound::Included;
    • fn digits(n: u64) -> usize {
    • let mut powers = BTreeMap::new();
    • powers.insert(0, 1);
    • powers.insert(10, 2);
    • powers.insert(100, 3);
    • powers.insert(1000, 4);
    • powers.insert(10000, 5);
    • powers.insert(100000, 6);
    • powers.insert(1000000, 7);
    • powers.insert(10000000, 8);
    • powers.insert(100000000, 9);
    • powers.insert(1000000000, 10);
    • powers.insert(10000000000, 11);
    • powers.insert(100000000000, 12);
    • powers.insert(1000000000000, 13);
    • powers.insert(10000000000000, 14);
    • powers.insert(100000000000000, 15);
    • powers.insert(1000000000000000, 16);
    • powers.insert(10000000000000000, 17);
    • powers.insert(100000000000000000, 18);
    • powers.insert(1000000000000000000, 19);
    • powers.insert(10000000000000000000, 20);
    • return *powers.range((Unbounded, Included(n))).last().unwrap().1;
    • let powers = (0..20).map(|n| (
    • if n == 0 { 0 } else { 10_u64.pow(n) },
    • n as usize + 1
    • )).collect::<BTreeMap<_, _>>();
    • return *powers.range(..=n).last().unwrap().1;
    • }
Mathematics
Algorithms
Logic
Numbers

Updated tests.
%timeit prime_checker(10000000019)
-> 13.4 ms ± 40.5 µs

Code
Diff
  • def prime_checker(n):
        if n < 4:
            return n > 1
        if not (n % 2 and n % 3):
            return False
        for i in range(5, int(n ** 0.5)+1, 6):
            if not ((n % i) and (n % (i + 2))):
                return False
        return True
    • """
    • Simple and fast, around 2-3ms
    • """
    • # One line removed, one is edited with wit but actually works, you really should git gud < idk >
    • def prime_checker(n):
    • for i in range(3, int(n**.5)+1 if n > 0 else 10, 2):
    • if n%i == 0: return False
    • return (n > 2 and n%2 != 0) or n == 2
    • if n < 4:
    • return n > 1
    • if not (n % 2 and n % 3):
    • return False
    • for i in range(5, int(n ** 0.5)+1, 6):
    • if not ((n % i) and (n % (i + 2))):
    • return False
    • return True
Code
Diff
  • // True, sorting could take an almost infinite number of processes... wish there was a way without 
    // using the Math class or a loop/recursion
    
    interface HighLow {
        static int[] findLargestAndSmallest(int[] nums) {
            if(nums == null || nums.length == 0) return null;
            int min = nums[0];
            int max = nums[0];
            int index = 0;
    
            while(index < nums.length) {
                min = (min < nums[index]) ? min : nums[index];
                max = (max > nums[index]) ? max : nums[index];
                index++;
            }
            
            return new int[]{min, max};
        }
    }
    
    • interface HighLow {
    • // IMHO with a function this simple and small,
    • // seperating it to even more tiny functions is just overkill and makes the code less readable,
    • // with such small functions you don't seperate for readability, but reusability. :)
    • static int[] findLargestAndSmallest(int[] nums) {
    • if (nums == null || nums.length == 0) return null;
    • // True, sorting could take an almost infinite number of processes... wish there was a way without
    • // using the Math class or a loop/recursion
    • int max = nums[0];
    • interface HighLow {
    • static int[] findLargestAndSmallest(int[] nums) {
    • if(nums == null || nums.length == 0) return null;
    • int min = nums[0];
    • int max = nums[0];
    • int index = 0;
    • for (int num : nums) {
    • if (max < num) max = num;
    • if (min > num) min = num;
    • while(index < nums.length) {
    • min = (min < nums[index]) ? min : nums[index];
    • max = (max > nums[index]) ? max : nums[index];
    • index++;
    • }
    • return new int[]{min, max};
    • }
Code
Diff
  • export function transform(source: any) {
        const target = {};
        Object.entries(source).forEach(function ([k, v]) {
            k.split("_").slice(0, -1).reduce(function (node: {[key: string]: any}, element: string) {
                return node[element] ??= {};
            }, target)[k.slice(k.lastIndexOf("_") + 1)] = v;
        });
        return target;
    }
    • export function transform(obj: any) {
    • const _RegEx = new RegExp(/_/);
    • const underscoredProp = Object.keys(obj).find(key =>
    • _RegEx.test(key)) || '';
    • const value = obj[underscoredProp];
    • const propertList = underscoredProp.split('_').reverse();
    • let toAdd = {};
    • propertList.map((prop,index) => {
    • toAdd = index==0 ?{[prop]:value} : {[prop]:toAdd}
    • })
    • return toAdd;
    • export function transform(source: any) {
    • const target = {};
    • Object.entries(source).forEach(function ([k, v]) {
    • k.split("_").slice(0, -1).reduce(function (node: {[key: string]: any}, element: string) {
    • return node[element] ??= {};
    • }, target)[k.slice(k.lastIndexOf("_") + 1)] = v;
    • });
    • return target;
    • }