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
Algorithms
Logic

here is mine updated and better

Code
Diff
  • flatten=a=>a.map?[].concat(...a.map(flatten)):a
    • const flatten = a =>
    • Array.isArray(a) ? a.reduce((acc,item) => acc.concat(flatten(item)), []) : a;
    • flatten=a=>a.map?[].concat(...a.map(flatten)):a
Code
Diff
  • import java.util.stream.*;
    
    public class Average {
       public static int averageFinder(int[] arr) {
         return (int)IntStream.of(arr).average().orElse(0);
       }
    }
    • import java.util.*;
    • import java.util.stream.*;
    • public class Average {
    • public static int averageFinder(int[] arr) {
    • return (int)Arrays.stream(arr).average().orElse(0d);
    • };
    • return (int)IntStream.of(arr).average().orElse(0);
    • }
    • }

(playing around with kumite)
for some this might be readable.

Code
Diff
  • using System;
    
    namespace Solution {
    
      class FizzBuzz {
        public static string convert(int input)
            {
                bool divisableBy3 = (input % 3 == 0);
                bool divisableBy5 = (input % 5 == 0);
                
                if (!divisableBy3 & !divisableBy5)
                  return input.ToString();
                
                return (divisableBy3 ? "Fizz" : "") +  (divisableBy5 ? "Buzz" : "");;
            }
      }
    }
    • using System;
    • namespace Solution {
    • class FizzBuzz {
    • public static string convert(int input)
    • {
    • var output = "";
    • output += (input % 3 == 0) ? "Fizz" : "";
    • output += (input % 5 == 0) ? "Buzz" : "";
    • output += (string.IsNullOrEmpty(output)) ? input.ToString() : "";
    • return output;
    • bool divisableBy3 = (input % 3 == 0);
    • bool divisableBy5 = (input % 5 == 0);
    • if (!divisableBy3 & !divisableBy5)
    • return input.ToString();
    • return (divisableBy3 ? "Fizz" : "") + (divisableBy5 ? "Buzz" : "");;
    • }
    • }
    • }
Search
Algorithms
Logic

shorther version

Code
Diff
  • import java.util.*;
    
    class Node {
      int value;
      Node left;
      Node right;
      
      public Node(int value) {
        this.value = value;
      }
    }
    
    
    class BST {
      public static boolean search(Node root, int key) {
                
        while(root != null) {
          if(root.value == key) {
            return true;
          }
          else    
          root=(root.value > key)?root.left:root.right;
          
        }
        
        return false;
      }
    }
    • import java.util.*;
    • class Node {
    • int value;
    • Node left;
    • Node right;
    • public Node(int value) {
    • this.value = value;
    • }
    • }
    • class BST {
    • public static boolean search(Node root, int key) {
    • if(root == null) {
    • return false;
    • }
    • while(root != null) {
    • if(root.value == key) {
    • return true;
    • }
    • else
    • root=(root.value > key)?root.left:root.right;
    • if(root.value > key) {
    • root = root.left;
    • } else if(root.value < key) {
    • root = root.right;
    • }
    • }
    • return false;
    • }
    • }

This is the fastest way I have found of calculating this. Approximately nine times faster than the standard solution.

Code
Diff
  • def euler(num):
        return sum(range(3,num,3)) + sum(range(5,num,5)) - sum(range(15,num,15))
    • def euler(num):
    • return sum([i for i in range(num) if i%3==0 or i%5==0])
    • return sum(range(3,num,3)) + sum(range(5,num,5)) - sum(range(15,num,15))
Fundamentals
Strings
Data Types
Code
Diff
  • const minutes = (n) => `${Math.trunc(n / 60)}:${("0" + (n % 60)).slice(-2)}`;
    • function minutes(num){
    • const minutes = num % 60
    • const hours = (num - minutes)/60
    • return `${hours}:${("0" + minutes).slice(-2)}`
    • }
    • const minutes = (n) => `${Math.trunc(n / 60)}:${("0" + (n % 60)).slice(-2)}`;
Algorithms
Logic

All equal is a property of a whole list. One of possile ways is to use folds that are more natual way to cacluate/check value/property on a foldable structures.

Also algorithm has O(n) complexity

Code
Diff
  • module AllEqual where
    
    import Data.Foldable(foldl')
    
    allEqual :: [Int] -> Bool
    allEqual []     = True
    allEqual (x:xs) = foldl' (\b a -> b && (a==x)) True xs
    • module AllEqual where
    • import Data.List
    • allEqual :: [Int] -> Bool
    • allEqual xs = length (nub xs) <= 1
    • import Data.Foldable(foldl')
    • allEqual :: [Int] -> Bool
    • allEqual [] = True
    • allEqual (x:xs) = foldl' (\b a -> b && (a==x)) True xs

Refactored to insert in order. This may run a bit faster due to no longer using sort() function.

Code
Diff
  • def divisors(n):
        fact = []
        for i in range(1, int(n**0.5) + 1):
            if not(n % i):
                v = n // i
                if v != i:
                    fact.insert(len(fact)//2,v)
                fact.insert(len(fact)//2,i)
        return fact
    • def divisors(n):
    • fact = [];
    • fact = []
    • for i in range(1, int(n**0.5) + 1):
    • if not(n % i):
    • fact.append(i)
    • if n / i != i:
    • fact.append(n / i)
    • fact.sort()
    • v = n // i
    • if v != i:
    • fact.insert(len(fact)//2,v)
    • fact.insert(len(fact)//2,i)
    • return fact