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
Data Types
Code
Diff
  • function lastChar(string) {
      return string.split('').pop();
    }
    • const lastChar=s=>[...s].pop()
    • function lastChar(string) {
    • return string.split('').pop();
    • }
Fundamentals
Strings
Data Types

Better than a loop! Still using padStart one the minutes.

Code
Diff
  • function minutes(minutes){
      var hours = Math.floor(minutes/60);
      minutes = minutes - hours*60;
        return hours.toString() + ":" + minutes.toString().padStart(2, 0);
    }
    • function minutes(minutes){
    • var hours = 0;
    • while (minutes >= 60){
    • minutes -= 60;
    • hours += 1;
    • };
    • var hours = Math.floor(minutes/60);
    • minutes = minutes - hours*60;
    • return hours.toString() + ":" + minutes.toString().padStart(2, 0);
    • }

Another one-line version - using lambda, filter rather than a comprehension. Can anyone think of any more one-liners?

Code
Diff
  • def mul():
        return sum(filter(lambda x:x%3==0 or x%5==0,range(1000)))
        
    • def mul():
    • return sum(i for i in range(1000) if i % 3 == 0 or i % 5 == 0)
    • return sum(filter(lambda x:x%3==0 or x%5==0,range(1000)))

Works for unknown number of int[]

Code
Diff
  • using System;
    using System.Linq;
    
    public static class Kata
    {
      public static int ArraySum(params int[][] arrs)
      {
        int sum = 0;
        foreach (int[] arr in arrs)
        {
            sum += arr.Sum();
        }
        return sum;
      }
    }
    
    • using System;
    • using System;
    • using System.Linq;
    • public static class Kata
    • {
    • public static int ArraySum(int[] arr1, int[] arr2, int[] arr3)
    • {
    • int[] newArray1 = arr1.Concat(arr2).ToArray();
    • int[] newArray2 = newArray1.Concat(arr3).ToArray();
    • int sum = newArray2.Sum();
    • return sum;
    • }
    • public static class Kata
    • {
    • public static int ArraySum(params int[][] arrs)
    • {
    • int sum = 0;
    • foreach (int[] arr in arrs)
    • {
    • sum += arr.Sum();
    • }
    • return sum;
    • }
    • }
Code
Diff
  • type Gender = Male | Female    
    type Person = { Name : string; Gender : Gender }
    
    let alice = { Name = "Alice"; Gender = Female }
    let bob = { Name = "Bob"; Gender = Male }
    
    let femaleOrMale = function 
      | { Name = name; Gender = Female } -> name + " is female."
      | { Name = name; Gender = Male } -> name + " is male."
    • type Gender = Male | Female
    • type Person = { Name : string; Gender : Gender }
    • let alice = { Name = "Alice"; Gender = Female }
    • let bob = { Name = "Bob"; Gender = Male }
    • let femaleOrMale p =
    • match p.Gender with
    • | Female -> p.Name + " is female."
    • | Male -> p.Name + " is male."
    • let femaleOrMale = function
    • | { Name = name; Gender = Female } -> name + " is female."
    • | { Name = name; Gender = Male } -> name + " is male."
Code
Diff
  • #!/bin/bash
    for (( i=1; i <= $3; i++)); do
      (( $i % ($1 * $2) )) || echo $i
    done
    • #!/bin/bash
    • for i in $(eval echo {1..$3});
    • do
    • if [ $(( $i % ( $1*$2) )) -eq 0 ]
    • then
    • echo $i
    • fi
    • for (( i=1; i <= $3; i++)); do
    • (( $i % ($1 * $2) )) || echo $i
    • done
Code
Diff
  • using System;
    class Kata {
        public static string Main(string greeting, string language)     
          => $"{greeting} {language}!".Tee(Console.WriteLine);    
    }
    
    public static class Extensions
    {
      public static T Tee<T>(this T @this, Action<T> action)
      {
        action(@this);
        return(@this);
      }
    }
    • using System;
    • class Kata {
    • public static string Main(string greeting, string language) {
    • Console.WriteLine(Greeting(greeting, language));
    • return Greeting(greeting, language);
    • }
    • public static string Greeting(string greeting, string language) => $"{greeting} {language}!";
    • public static string Main(string greeting, string language)
    • => $"{greeting} {language}!".Tee(Console.WriteLine);
    • }
    • public static class Extensions
    • {
    • public static T Tee<T>(this T @this, Action<T> action)
    • {
    • action(@this);
    • return(@this);
    • }
    • }
Testing
Code
Diff
  • def replicate(times, num):
        if times <= 0: return []
        return [num] + replicate(times-1, num)
    replicate(8,5)
    • def replicate(times, num):
    • if times <= 0: return []
    • return [num] + replicate(times-1, num)
    • replicate(8,5)
Algorithms
Logic
Code
Diff
  • const flatten = a => [...a]
    • const flatten = a => [].concat.apply([], a)
    • const flatten = a => [...a]