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
  • function wordCount(str) {  
      return str.trim().split(" ").length;
    }
    
    • function wordCount(str) {
    • var words = 1;
    • for(var i = 1; i < str.length; i++) {
    • if(str[i] == " " && str[i - 1] !== " "&& str[i + 1] !== " ") {
    • words++;
    • }
    • }
    • return words;
    • function wordCount(str) {
    • return str.trim().split(" ").length;
    • }

Read solution.txt in preloaded section so the user's solution is read before it's modified.

Code
Diff
  • // write a add function that doesn't use the plus symbol
    function add(a, b){
      return a + b;
    }
    
    // Make sure to view the test cases to see how this test fails
    // Rewrite solution.txt
    require('fs').writeFileSync('/home/codewarrior/solution.txt', 'no pluses here!')
    • // write a add function that doesn't use the plus symbol
    • function add(a, b){
    • return a + b;
    • }
    • // Make sure to view the test cases to see how this test fails
    • // Make sure to view the test cases to see how this test fails
    • // Rewrite solution.txt
    • require('fs').writeFileSync('/home/codewarrior/solution.txt', 'no pluses here!')

The println function was removed in Swift 3, in favor of just print with the optional terminator: argument, which defaults to "\n".

Code
Diff
  • print("Hello Swift!")
    • println("Hello Swift!")
    • print("Hello Swift!")
Code
Diff
  • import java.util.*;
    import java.util.stream.*;
    
    class Solution {
      public static String largestNumber(Integer[] nums) {
        final StringBuilder sb = new StringBuilder();
        return Arrays.stream(nums)
              .parallel()
              .map((n) -> n.toString())
              .sorted(Solution::compareNumberString)
              .collect(Collectors.joining())
              .toString();
      }
      
      private static int compareNumberString(String s1, String s2) {
        if (s2.startsWith(s1)) return compareNumberString(s2.substring(s1.length()), s1);
        if (s1.startsWith(s2)) return compareNumberString(s1.substring(s2.length()), s2);
        return s2.compareTo(s1);
      }
    }
    • import java.util.*;
    • import java.util.stream.*;
    • class Solution {
    • public static String largestNumber(Integer[] nums) {
    • Arrays.sort( nums, new Comparator<Integer>() {
    • @Override
    • public int compare(Integer a, Integer b) {
    • String aStr = a.toString();
    • String bStr = b.toString();
    • return (aStr + bStr).compareTo(bStr + aStr) * -1;
    • }
    • } );
    • String result = "";
    • for(Integer num : nums) {
    • result += num.toString();
    • }
    • return result;
    • final StringBuilder sb = new StringBuilder();
    • return Arrays.stream(nums)
    • .parallel()
    • .map((n) -> n.toString())
    • .sorted(Solution::compareNumberString)
    • .collect(Collectors.joining())
    • .toString();
    • }
    • private static int compareNumberString(String s1, String s2) {
    • if (s2.startsWith(s1)) return compareNumberString(s2.substring(s1.length()), s1);
    • if (s1.startsWith(s2)) return compareNumberString(s1.substring(s2.length()), s2);
    • return s2.compareTo(s1);
    • }
    • }
Mathematics
Algorithms
Logic
Numbers
cats :: [Integer]
cats = 1 : do
  (c_n, n) <- zip cats [0..]
  return $ c_n * 2 * (2 * n + 1) `div` (2 + n)
  
main = putStrLn $ show $ take 10 cats
Code
Diff
  • def Complicated_Greetings(name):
        if name == "":
            return 'Hello, World!!'
        return f'Hello {name}'
    • def Complicated_Greetings(name):
    • h=["H","e","l","l","o"]
    • c=","
    • w=["W","o","r","l","d"]
    • e="!"
    • k=""
    • for i in h:
    • k+=i
    • if name=="":
    • k+=c
    • k+=" "
    • for i in w:
    • k+=i
    • k=k+e+e
    • else:
    • k+=" "
    • k+=name
    • return k
    • if name == "":
    • return 'Hello, World!!'
    • return f'Hello {name}'
Code
Diff
  • import java.util.Arrays;
    import java.util.Scanner;
    
    public class MaxNumber {
        public static long print(long number) {
            char[] digits = Long.toString(number).toCharArray();
            Arrays.sort(digits);
            return Long.parseLong(new StringBuilder(new String(digits)).reverse().toString());
        }
    }
    • import java.util.Arrays;
    • import java.util.Scanner;
    • public class MaxNumber {
    • public static long print(long number) {
    • String numeroString = Long.toString(number);
    • char[] digitos = numeroString.toCharArray();
    • Arrays.sort(digitos);
    • StringBuilder numeroOrdenadoStr = new StringBuilder(new String(digitos));
    • numeroOrdenadoStr.reverse();
    • return Long.parseLong(numeroOrdenadoStr.toString());
    • char[] digits = Long.toString(number).toCharArray();
    • Arrays.sort(digits);
    • return Long.parseLong(new StringBuilder(new String(digits)).reverse().toString());
    • }
    • public static void main(String[] args) {
    • Scanner scanner = new Scanner(System.in);
    • System.out.print("Ingrese un numero: ");
    • long number = scanner.nextLong();
    • long maxNumber = print(number);
    • System.out.println("El número más alto que se puede formar con estos dígitos es: " + maxNumber);
    • }
    • }
Sets

dumbRockPaperScissors(player1:str, player2:str) -> str:
A la hora del uso diario, agregar información de las variables que recibe la función y su salida. Es una de las mejores prácticas que podemos realizar

Rock, Paper, Scissors -> Los nombres de las variables expresan correctamente su contenido. Al ser tan simple, podemos realizar las declaraciónes en una línea dando igual legibilidad, reduciendo líneas de código y dando mejor apariencia al código.

Code
Diff
  • def dumbRockPaperScissors(player1:str, player2:str) -> str:
        Rock, Paper, Scissors = {"Paper"}, {"Scissors"}, {"Rock"}
    
        if player1 == player2:
            return "Draw"
        #we use 'eval' once for two results and implicit return
        return "Player 1 wins" if player1 in eval(player2) else "Player 2 wins"
        
        #This is the same code in one line
        #return "Draw" if player1 == player2 else "Player 1 wins" if player1 in eval(player2) else "Player 2 wins"
    
        
        
     
    • def dumbRockPaperScissors(player1, player2):
    • Rock = {"Paper"}
    • Paper = {"Scissors"}
    • Scissors = {"Rock"}
    • if player1 in eval(player2):
    • return "Player 1 wins"
    • elif player2 in eval(player1):
    • return "Player 2 wins"
    • else:
    • def dumbRockPaperScissors(player1:str, player2:str) -> str:
    • Rock, Paper, Scissors = {"Paper"}, {"Scissors"}, {"Rock"}
    • if player1 == player2:
    • return "Draw"
    • #we use 'eval' once for two results and implicit return
    • return "Player 1 wins" if player1 in eval(player2) else "Player 2 wins"
    • #This is the same code in one line
    • #return "Draw" if player1 == player2 else "Player 1 wins" if player1 in eval(player2) else "Player 2 wins"