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
Arrays

Replace Letter

Given a string and a number (n), generate an array in which each position will be that same string but modifying the letter of its first position (0) by the one in its n position.

Input:

hello, 2

Output:

[lello, hollo, hehlo, heleo, helll]

 Restrictions:

  • where n will always be a number between 0 and the length of the string.

  • It is case-insensitive and does not discriminate between letters, numbers, and special characters.

  • When current position + n is greater than the length of the string, it will return to start.

  • The spaces will be considered:

    • If there is a space, that position will not be replaced.
    • The space will not replace any letter.

For example

Given the string = "hello world" and n=1

Should return:

[eello world, Hlllo world, Hello world, Heloo world, Hello oorld, Hello wrrld, Hello wolld, Hello wordd, Hello worlH]

It would not admit:

hellowword

hell  word

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);
    			}
    
    		}
    
    
    		return arr.toArray(new String[arr.size()]);
    
    	}
     }
    • 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);
    • }
    • }
    • String[] array = arr.toArray(new String[arr.size()]);
    • return array;
    • return arr.toArray(new String[arr.size()]);
    • }
    • }

Given an array of strings and an array of ints, associate them from longest to shortest according to the length of each string. The output format must be a string with the syntax:

name1:number1,name2:number2,name3:number3... nameN:numberN

Input example:
String[]names = {"Ana", "Miguel", "Josemanuel"}
int[]numbers = {1034, 21, 537}

Output example:
"JoseManuel:1034,Miguel:537,Ana:21"

Code
Diff
  • public class NamesAndNumbers{
      
      public static String run(int[]numbers, String[] names){
        
        if (numbers.length != names.length) {
    			return "The size of the arrays are not the same";
    		}
        
        return "";
      }
      
    }//end class.
    • public class NamesAndNumbers{
    • public static String run(int[]numbers, String[] names){
    • if (numbers.length != names.length) {
    • return "The size of the arrays are not the same";
    • }
    • return "";
    • }
    • }//end class.
Strings
Fundamentals
Arrays

Added random test.

Strings
Data Structures