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 Kumite {
      public static int powerOfPrimes(int num) {
    
        if(num <= 0) return 0;
        String numStr = Integer.toString(num);
    
        int sumEven = 0;
        int sumOdd = 0;
        int base = 0;
        int exponent = 0;
        int result = 0;
    
        for (int i = 0; i < numStr.length(); i++) {
    
          int digit = Character.getNumericValue(numStr.charAt(i));
          
          if(digit % 2 == 0) {
            sumEven += digit;
          } else {
            sumOdd += digit;
          }
    
          int[] primes = {2, 3, 5, 7};
          
          if(Arrays.binarySearch(primes, digit) >= 0) {
            exponent ++;
          }
          
        }
        
        base = sumEven - sumOdd;
        result = (int) Math.pow(base, exponent);
    
        return result;
      }
    }
    
    
    • import java.util.Arrays;
    • public class Kumite {
    • public static int powerOfPrimes(int num) {
    • if(num <= 0) return 0;
    • String numStr = Integer.toString(num);
    • int sumEven = 0;
    • int sumOdd = 0;
    • int base = 0;
    • int exponent = 0;
    • int result = 0;
    • for (int i = 0; i < numStr.length(); i++) {
    • int digit = Character.getNumericValue(numStr.charAt(i));
    • if(digit % 2 == 0) {
    • sumEven += digit;
    • } else {
    • sumOdd += digit;
    • }
    • int[] primes = {2, 3, 5, 7};
    • if(Arrays.binarySearch(primes, digit) >= 0) {
    • exponent ++;
    • }
    • }
    • base = sumEven - sumOdd;
    • result = (int) Math.pow(base, exponent);
    • return result;
    • }
    • }
Strings

INTRODUCTION

Welcome soldiers, we need your help! The enemy army is going to attack and we have to get ready.

 

Get together quickly by battalions!

 

TASK

Your task as a colonel is to order your lieutenants with their respective battalion, for each lieutenant a letter is assigned and each battalion is formed by numbers and the letter corresponding to its lieutenant. Your duty is to assign them in such a way that you return a string like the following: "a:11a1 b:b22 c:33c".

 

EXAMPLES

keyAlphabet( "a b c 11a b22 c33" ) => returns "a:11a b:b22 c:c33"
keyAlphabet( "a b c 11a1 2b2 33c3 13a1 12a1" ) => returns "a:11a1,12a1,13a1 b:2b2 c:33c3"

NOTES

  • There may be more than one battalion for the same lieutenant.
  • Both lieutenants and battalions must be ordered.
  • Be careful with the spaces.
Code
Diff
  • import java.util.*;
    
    public class Kata {
    
    public static String keyAlphabet(String str) {
    
      String[] arr = str.toLowerCase().split(" ");
      TreeSet<String> listKey = new TreeSet<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>();
    • String[] arr = str.toLowerCase().split(" ");
    • TreeSet<String> listKey = new TreeSet<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();
    • }
    • }
Strings
Code
Diff
  • import java.text.ParseException;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Random;
    import java.util.concurrent.ThreadLocalRandom;
    
    
    class Kata {
      public static String[] replaceLetter(String str) {
    
    			// Hola -> oola, Hlla, Hoaa, HolH
          // Prueba añadir descripción
    			ArrayList<String> arr = new ArrayList<>();
    
    			StringBuilder strFinal = new StringBuilder(str);
    
    			for (int i = 0; i < str.length() - 1; i++) {
    
    				if (str.charAt(i) != ' ') {
    
    					strFinal.replace(i, i + 1, String.valueOf(str.charAt(i + 1)));
    
    					arr.add(strFinal.toString());
    
    					strFinal.replace(0, str.length(), str);
    				}
    
    			}
    
    			strFinal.setCharAt(str.length() - 1, str.charAt(0));
    
    			arr.add(strFinal.toString());
    			
    			System.out.println(arr.toArray().toString());
    			
    			// Convertimos ArrayList a Array
    		    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;
    • class Kata {
    • public static String[] replaceLetter(String str) {
    • // Hola -> oola, Hlla, Hoaa, HolH
    • // Prueba añadir descripción
    • //Prueba
    • ArrayList<String> arr = new ArrayList<>();
    • StringBuilder strFinal = new StringBuilder(str);
    • for (int i = 0; i < str.length() - 1; i++) {
    • if (str.charAt(i) != ' ') {
    • strFinal.replace(i, i + 1, String.valueOf(str.charAt(i + 1)));
    • arr.add(strFinal.toString());
    • strFinal.replace(0, str.length(), str);
    • }
    • }
    • strFinal.setCharAt(str.length() - 1, str.charAt(0));
    • arr.add(strFinal.toString());
    • System.out.println(arr.toArray().toString());
    • // Convertimos ArrayList a Array
    • String[] array = arr.toArray(new String[arr.size()]);
    • return array;
    • }
    • }
Code
Diff
  • public class Encrypt {
      
      public static String encryptByVocals(String str) {
        
        return null;
      }
    }
    • public class Encrypt {
    • public static String encryptByVocals(String str) {
    • return null;
    • }
    • }