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
Strings
Code
Diff
  • import java.text.ParseException;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Random;
    import java.util.concurrent.ThreadLocalRandom;
    
    public class Kata{
    public static String[] replaceLetter(String str, int n) {
    
    		ArrayList<String> arr = new ArrayList<>();
    		StringBuilder strFinal = new StringBuilder(str);
    
    		for (int i = 0; i < str.length(); i++) {
    			int nextIndex = (i + n) % str.length() ;
    
    			if (str.charAt(i) != ' ' && str.charAt(nextIndex) != ' ') {
    
    				nextIndex = (i + n) % str.length();
    				strFinal.replace(i, i + 1, String.valueOf(str.charAt(nextIndex)));
    				arr.add(strFinal.toString());
    				strFinal.replace(0, str.length(), str);
    			}
    
    		}
    
    		System.out.println(arr.toString());
    
    		String[] array = arr.toArray(new String[arr.size()]);
    
    		return array;
    
    	}
     }
    • import java.text.ParseException;
    • import java.util.ArrayList;
    • import java.util.Arrays;
    • import java.util.Random;
    • import java.util.concurrent.ThreadLocalRandom;
    • public class Kata{
    • public static String[] replaceLetter(String str, int n) {
    • ArrayList<String> arr = new ArrayList<>();
    • StringBuilder strFinal = new StringBuilder(str);
    • for (int i = 0; i < str.length(); i++) {
    • int nextIndex = 0;
    • int nextIndex = (i + n) % str.length() ;
    • if (str.charAt(i) != ' ' && str.charAt(nextIndex) != ' ') {
    • nextIndex = (i + n) % str.length();
    • strFinal.replace(i, i + 1, String.valueOf(str.charAt(nextIndex)));
    • arr.add(strFinal.toString());
    • strFinal.replace(0, str.length(), str);
    • }
    • }
    • System.out.println(arr.toString());
    • String[] array = arr.toArray(new String[arr.size()]);
    • return array;
    • }
    • }
Strings
Code
Diff
  • import java.util.*;
    
    public class Kata {
    
    public static String keyAlphabet(String str) {
    
      String[] arr = str.split(" ");
      List<String> listKey = new ArrayList<String>();
      PriorityQueue<String> listValue = new PriorityQueue<>();
      TreeMap<String, String> alphabet = new TreeMap<>();
      
      for (String item : arr) {
        if (item.length() == 1 && item.charAt(0) >= 'a' && item.charAt(0) <= 'z') {
          listKey.add(item);
        } else {
          listValue.add(item);
        }
      }
      
      List<String> values = new ArrayList<>(listValue);
      
      for (String value : values) {
        for (String s : listKey) {
          if (value.contains(s)) {
            if (alphabet.containsKey(s)) {
              alphabet.put(s, alphabet.get(s) + "," + value);
            } else {
              alphabet.put(s, value);
            }
          }
        }
      }
      StringBuilder result = new StringBuilder();
      for (Map.Entry<String, String> m : alphabet.entrySet()) {
        result.append(m.getKey()).append(":").append(m.getValue()).append(" ");
      }
      return result.toString().trim();
      }
    
    }
    • import java.util.*;
    • public class Kata {
    • public static String keyAlphabet(String str) {
    • String[] arr = str.split(" ");
    • List<String> listKey = new ArrayList<String>();
    • PriorityQueue<String> listValue = new PriorityQueue<>();
    • TreeMap<String, String> alphabet = new TreeMap<>();
    • for (String item : arr) {
    • if (item.length() == 1 && item.charAt(0) >= 'a' && item.charAt(0) <= 'z') {
    • listKey.add(item);
    • } else {
    • listValue.add(item);
    • }
    • }
    • List<String> values = new ArrayList<>(listValue);
    • for (String value : values) {
    • for (String s : listKey) {
    • if (value.contains(s)) {
    • if (alphabet.containsKey(s)) {
    • alphabet.put(s, alphabet.get(s) + "," + value);
    • } else {
    • alphabet.put(s, value);
    • }
    • }
    • }
    • }
    • return "";
    • StringBuilder result = new StringBuilder();
    • for (Map.Entry<String, String> m : alphabet.entrySet()) {
    • result.append(m.getKey()).append(":").append(m.getValue()).append(" ");
    • }
    • return result.toString().trim();
    • }
    • }
Code
Diff
  • const isAnagram = (s1, s2) => s1.length === s2.length && Object.values([...s1].reduce((o, k, i) => (k in o ? ++o[k] : o[k] = 1, s2[i] in o ? --o[s2[i]] : o[s2[i]] = -1, o), {})).every(v => !v);
    • function isAnagram(str1, str2) {
    • if (str1.length !== str2.length) {
    • return false;
    • }
    • const frequency = {};
    • for (let i = 0; i < str1.length; i++) {
    • const char = str1[i];
    • if (frequency[char]) {
    • frequency[char]++;
    • } else {
    • frequency[char] = 1;
    • }
    • }
    • for (let i = 0; i < str2.length; i++) {
    • const char = str2[i];
    • if (!frequency[char]) {
    • return false;
    • } else {
    • frequency[char]--;
    • }
    • }
    • return true;
    • }
    • const isAnagram = (s1, s2) => s1.length === s2.length && Object.values([...s1].reduce((o, k, i) => (k in o ? ++o[k] : o[k] = 1, s2[i] in o ? --o[s2[i]] : o[s2[i]] = -1, o), {})).every(v => !v);
Code
Diff
  • function capitalize(sentence) {
      return sentence.split(' ').map(w => w[0].toUpperCase() + w.slice(1)).join(' ');
    }
    • function capitalize(sentence) {
    • let words = sentence.split(' ');
    • const length = words.length;
    • for (let i = 0; i < length; ++i) {
    • words[i] = words[i][0].toUpperCase() + words[i].substr(1)
    • }
    • return words.join(' ');
    • }
    • console.log(capitalize("i am a javascript programmer"));
    • return sentence.split(' ').map(w => w[0].toUpperCase() + w.slice(1)).join(' ');
    • }
Code
Diff
  • def decompose(num):
        return [int(i) for i in ''.join(map(str, num))]
    
    
    def greatest(num):
        return int(''.join(sorted(''.join(map(str, decompose(num))), reverse=True)))
    • def decompose(num):
    • return [int(i) for i in ''.join(map(str, num))]
    • def greatest(num):
    • return int(''.join(sorted([str(y) for x in [[int(z) for z in str(n)] for n in num] for y in x], reverse=True)))
    • return int(''.join(sorted(''.join(map(str, decompose(num))), reverse=True)))
Code
Diff
  • def binary_to_integer(b):
        # I didn't know that you don't need prefix '0b' for convertion, so I wrote it like this
        return int(f'0b{b}', 2)
    • def binary_to_integer(b):
    • return sum([x[0] for x in list(zip([pow(2,i) for i in range(len(b))], reversed(b))) if x[1] == '1'])
    • # I didn't know that you don't need prefix '0b' for convertion, so I wrote it like this
    • return int(f'0b{b}', 2)
Code
Diff
  • def knight_move3d(pos=(0, 0, 0)) -> bool:
        if pos == (0, 0, 0):
            return True
        return [*sorted(map(abs, pos))] == [0, 1, 2]
    • def knight_move3d(position=(0, 0, 0)) -> bool:
    • if position == (0, 0, 0):
    • def knight_move3d(pos=(0, 0, 0)) -> bool:
    • if pos == (0, 0, 0):
    • return True
    • _sum: int = 0
    • mul: int = 1
    • for i in position:
    • if i > 2 or -2 > i:
    • return False
    • _sum += abs(i)
    • mul = mul * i
    • return _sum == 3 and mul == 0
    • return [*sorted(map(abs, pos))] == [0, 1, 2]
Code
Diff
  • def pyramid_of_x(n):
        if n < 2:
            return 'Not enough building blocks!'
        return '\n'.join(['*' * i for i in range(1, n + 1)])
    • def pyramid_of_x(n):
    • if n < 2:
    • return 'Not enough building blocks!'
    • rows = ['*' * i for i in range(1, n + 1)]
    • return '\n'.join(rows)
    • return '\n'.join(['*' * i for i in range(1, n + 1)])
Code
Diff
  • import java.util.Arrays;
    public class HighLow{
      public static int[] printLargestAndSmallest(int[] nums){
    		return nums == null || nums.length==0 ? null : new int[]{Arrays.stream(nums).min()
          .getAsInt(),Arrays.stream(nums).max().getAsInt()};
    	}
    }
    
    • import java.util.Arrays;
    • public class HighLow{
    • public static int[] printLargestAndSmallest(int[] nums){
    • int low[] = nums;
    • int high[] = nums;
    • int lowest = nums[0];
    • int highest = nums[0];
    • int count = 0;
    • for(int i = 0; i < nums.length;i+=2){
    • int num1 = nums[i];
    • int num2 = nums[i+1];
    • if(num1<num2){
    • low[count] = num1;
    • high[count] = num2;
    • count++;
    • }else{
    • low[count] = num2;
    • high[count] = num1;
    • count++;
    • }
    • lowest = low[0];
    • highest = high[0];
    • for(int j = 1; j < low.length; j++){
    • if(low[j] < lowest){
    • lowest = low[j];
    • }
    • }
    • for(int j = 1; j < high.length; j++){
    • if(high[j] > highest){
    • highest = high[j];
    • }
    • }
    • }
    • int[] finalHighLow = new int[2];
    • finalHighLow[0] = lowest;
    • finalHighLow[1] = highest;
    • return finalHighLow;
    • return nums == null || nums.length==0 ? null : new int[]{Arrays.stream(nums).min()
    • .getAsInt(),Arrays.stream(nums).max().getAsInt()};
    • }
    • }
Code
Diff
  • def foo(lst, i, n):
        done = i > n
        fb = not (i % 3 or i % 5)
        f = not i % 3
        b = not i % 5
        match (done, fb, f, b):
            case (1, _, _, _):
                return lst
            case (_, 1, _, _):
                return foo(lst + ["fizzbuzz"], i + 1, n)
            case (_, _, 1, _):
                return foo(lst + ["fizz"], i + 1, n)
            case (_, _, _, 1):
                return foo(lst + ["buzz"], i + 1, n)
            case _:
                return foo(lst + [str(i)], i + 1, n)
    
                    
    def fizzbuzz(n):
        return foo([],1,n)
    • def rec(acc,i,n):
    • done=i>n
    • match done:
    • case True:
    • return acc
    • def foo(lst, i, n):
    • done = i > n
    • fb = not (i % 3 or i % 5)
    • f = not i % 3
    • b = not i % 5
    • match (done, fb, f, b):
    • case (1, _, _, _):
    • return lst
    • case (_, 1, _, _):
    • return foo(lst + ["fizzbuzz"], i + 1, n)
    • case (_, _, 1, _):
    • return foo(lst + ["fizz"], i + 1, n)
    • case (_, _, _, 1):
    • return foo(lst + ["buzz"], i + 1, n)
    • case _:
    • fb=not (i%3 or i%5)
    • f=not i%3
    • b=not i%5
    • match fb:
    • case True:
    • return rec(acc+["fizzbuzz"],i+1,n)
    • case _:
    • match f:
    • case True:
    • return rec(acc+["fizz"],i+1,n)
    • case _:
    • match b:
    • case True:
    • return rec(acc+["buzz"],i+1,n)
    • case _:
    • return rec(acc+[str(i)],i+1,n)
    • return foo(lst + [str(i)], i + 1, n)
    • def fizzbuzz(n):
    • return rec([],1,n)
    • # def fizzbuzz(n):
    • # acc=[]
    • # i=1
    • # while i<=n:
    • # if not (i%3 or i%5):
    • # acc.append("fizzbuzz")
    • # elif not i%3:
    • # acc.append("fizz")
    • # elif not i%5:
    • # acc.append("buzz")
    • # else:
    • # acc.append(str(i))
    • # i+=1
    • # return acc
    • return foo([],1,n)