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
  • const wordCount = x => x.trim().split(/[^\w-]+/).filter(s => s!== "").length
    • const wordCount = x => x.trim().split` `.length
    • const wordCount = x => x.trim().split(/[^\w-]+/).filter(s => s!== "").length
Code
Diff
  • function sumOfMultiplesUnder(n) {
      return sumAll(--n,3) + sumAll(n,5) - sumAll(n,15);
    }
    function sumAll(n,m){
      return m * (Math.floor(n/m) + 1) * Math.floor(n/m)/2;
    }
    • function sumOfMultiplesUnder(n) {
    • return sumAll(--n,3)+sumAll(n,5)-sumAll(n,15)
    • return sumAll(--n,3) + sumAll(n,5) - sumAll(n,15);
    • }
    • function sumAll(n,m){
    • return m*(Math.floor(n/m)+1)*Math.floor(n/m)/2
    • return m * (Math.floor(n/m) + 1) * Math.floor(n/m)/2;
    • }

Added asserts for input validation.

Changed all int types to double

Reduced complexity by using floor() instead... test cases are still passing. (but there is some floating-point voodoo happening)

Added cout for future use.

Code
Diff
  • #include <cmath>
    #include <cassert>
    #include <iomanip>
    
    double custom_sqrt( double a, int accuracy=20 ) {
      assert( 0 <= a );
      assert( 0 <= accuracy );
      assert( 307 >= accuracy ); // evidently, values larger than 307 cause overflow
      const double ACC = std::pow( 10.0, accuracy );
      double result = sqrt( a );
      result *= ACC;
      result = std::floor( result );
      result /= ACC;
      //std::cout << std::setprecision(21) << result << std::endl;
      assert( 0 <= result );
      return result;
    }
    • #include <math.h>
    • #include <cmath>
    • #include <cassert>
    • #include <iomanip>
    • double custom_sqrt (int a,int accuracy=20) {
    • double fIntegerPart;
    • double fFloatingPart = modf((double)sqrt(a), &fIntegerPart);
    • double fTempFloat = fFloatingPart * pow(10, accuracy);
    • double fTempInt;
    • fTempFloat = modf(fTempFloat, &fTempInt);
    • fTempFloat /= pow(10, accuracy);
    • fFloatingPart -= fTempFloat;
    • return fIntegerPart+fFloatingPart;
    • double custom_sqrt( double a, int accuracy=20 ) {
    • assert( 0 <= a );
    • assert( 0 <= accuracy );
    • assert( 307 >= accuracy ); // evidently, values larger than 307 cause overflow
    • const double ACC = std::pow( 10.0, accuracy );
    • double result = sqrt( a );
    • result *= ACC;
    • result = std::floor( result );
    • result /= ACC;
    • //std::cout << std::setprecision(21) << result << std::endl;
    • assert( 0 <= result );
    • return result;
    • }
Code
Diff
  • SELECT name FROM greetings
    WHERE greeting like '%ll%';
    • SELECT name FROM greetings
    • WHERE upper(greeting) like '%HELLO%';
    • WHERE greeting like '%ll%';
Code
Diff
  • public class CountTheDigit {
    
      public static int count(int num, int digit) {
        int result = 0;
        
        do {
          if (num % 10 == digit)
            ++result;
          num /= 10;
        } while (num != 0);
        
        return result;
      }
      
    	public static int nbDig(int n, int d) {
        int result = 0;
        
        for(int i = 0; i < n; ++i)
    			result += count(i * i, d);
        
      	return result;
      }
    }
    • public class CountTheDigit {
    • public static int count(int num, int digit) {
    • int result = 0;
    • do {
    • if (num % 10 == digit)
    • ++result;
    • num /= 10;
    • } while (num != 0);
    • return result;
    • }
    • public static int nbDig(int n, int d) {
    • int count=0;
    • for(int i=0; i<n; i++) {
    • String number=(i*i)+"";
    • count += number.length() - number.replace(d+"", "").length();
    • }
    • return count;
    • int result = 0;
    • for(int i = 0; i < n; ++i)
    • result += count(i * i, d);
    • return result;
    • }
    • }

C# 7.0+ features allow for syntatic sugar to reduce coding length. As well, the tests were using Is.Equal when Is.True and Is.False exist.

Code
Diff
  • namespace Solution 
    {
      using System;
      
      public static class logic
      {
        public static bool  Or(bool i, bool j) => i.i() + j.i() >= 1;
        public static bool And(bool i, bool j) => i.i() + j.i() == 2;
        public static bool Xor(bool i, bool j) => i.i() + j.i() == 1;
      }
      
      public static class BoolExtensions
      {
        public static int i(this bool val) => Convert.ToInt32(val);
      }
    }
    • namespace Solution
    • {
    • using System;
    • public static class logic
    • {
    • public static bool Or(bool i, bool j) { return i.i() + j.i() >= 1; }
    • public static bool And(bool i, bool j) { return i.i() + j.i() == 2; }
    • public static bool Xor(bool i, bool j) { return i.i() + j.i() == 1; }
    • public static bool Or(bool i, bool j) => i.i() + j.i() >= 1;
    • public static bool And(bool i, bool j) => i.i() + j.i() == 2;
    • public static bool Xor(bool i, bool j) => i.i() + j.i() == 1;
    • }
    • public static class BoolExtensions
    • {
    • public static int i(this bool val)
    • {
    • return Convert.ToInt32(val);
    • }
    • public static int i(this bool val) => Convert.ToInt32(val);
    • }
    • }