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

This variation allow infinite numbers to be tested.

Code
Diff
  • function dividedByThree(int $number): bool
    {
        while(strlen($number) > 1) {
          $number = abs(array_sum(str_split($number)));
        }
        switch ($number) {
          case 3:        
          case 6:
          case 9:
            return true;
            break;
            
          default:
            return false;
        }
    }
    
    • function dividedByThree(int $number): bool
    • {
    • $abs = abs($number);
    • if($abs < 10){
    • return $abs == 3 || $abs == 6 || $abs == 9;
    • while(strlen($number) > 1) {
    • $number = abs(array_sum(str_split($number)));
    • }
    • switch ($number) {
    • case 3:
    • case 6:
    • case 9:
    • return true;
    • break;
    • default:
    • return false;
    • }
    • $sum = array_sum(str_split($abs,1));
    • return dividedByThree($sum);
    • }

more faster

require 'benchmark'

strings = []

10000.times do
  string = Array.new(rand(500..1000)) { rand(10).to_s }.join('')
  strings << string
end

def solution1(array)
  array.each do |s|
    s.chars.sum(&:to_i)
  end
end

def solution2(array)
  array.each do |s|
    s.sum - s.size * 48
  end
end

Benchmark.bmbm do |x|
  x.report { solution1(strings) }
  x.report { solution2(strings) }
end

result

Rehearsal ------------------------------------
   1.032923   0.004906   1.037829 (  1.044178)
   0.009852   0.000544   0.010396 (  0.010945)
--------------------------- total: 1.048225sec

       user     system      total        real
   1.032176   0.006350   1.038526 (  1.045689)
   0.007727   0.000118   0.007845 (  0.007965)
Code
Diff
  • def getIDS(string)
      string.sum - string.size * 48
    end
    • def getIDS(string)
    • string.chars.sum(&:to_i)
    • string.sum - string.size * 48
    • end
Code
Diff
  • x <- c(52,73,55,26,72,45,80)
    y <- var(x)
    • c(52,73,55,26,72,45,80,62,NA,7,NA,87,54,46,85,37,94)
    • x <- c(52,73,55,26,72,45,80)
    • y <- var(x)
Code
Diff
  • #include <string.h>
    #include <stdlib.h>
    
    char *Hi(void) {
        char *ans = calloc(13, sizeof(char));
        strcpy(ans, "Hello World.");
        return ans;
    }
    • #include <string.h>
    • #include <stdlib.h>
    • char *Hi(void) {
    • char *ans = (char*) malloc(13 * sizeof(char));
    • char *ans = calloc(13, sizeof(char));
    • strcpy(ans, "Hello World.");
    • return ans;
    • }
Code
Diff
  • using System;
    
    
    public class Multiplication
    {
        public int Multiply(int a, int b) => Convert.ToInt32(Math.BigMul(a, b));
    
    }
    • using System;
    • public class Multiplication
    • {
    • // Multiply two integers
    • // Throws error if the product is outside of the int range.
    • // This would otherwise silently error and return the wrong product.
    • public int Multiply(int a, int b) {
    • long res = Math.BigMul(a, b);
    • // Convert.ToInt32 throws OverFlowException if conversion is out of the bounds of the integer.
    • return Convert.ToInt32(res);
    • }
    • public int Multiply(int a, int b) => Convert.ToInt32(Math.BigMul(a, b));
    • }
Code
Diff
  • with(Math)highAndLow=s=>max(...s=s.match(/-?\d+/g))+` `+min(...s)
    • highAndLow=a=>Math.max(...a=a.split` `)+` `+Math.min(...a)
    • with(Math)highAndLow=s=>max(...s=s.match(/-?\d+/g))+` `+min(...s)