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.
This variation allow infinite numbers to be tested.
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)
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)
print(x) print(y)
test_that("Variance", {expect_equal(round(var(c(52,73,55,26,72,45,80,62,NA,7,NA,87,54,46,85,37,94),na.rm=T),4),round(587.5238,4))})- print(x)
- print(y)
#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;
- }
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));
- }
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)
describe('tests', () => { Test.assertEquals(highAndLow("So, even list of 1, 3, -5, 7 and 14 is handled properly"), "14 -5") Test.assertEquals(highAndLow("1 4 2 6 1 6 1 5 2 8 9"), "9 1") Test.assertEquals(highAndLow("1 4 2 6 -10 6 1 5 2 8 9"), "9 -10") Test.assertEquals(highAndLow("5"), "5 5") Test.assertEquals(highAndLow("-13"), "-13 -13") Test.assertEquals(highAndLow("-42 -15 -16 -23 -8 -4"), "-4 -42") Test.assertEquals(highAndLow("7 2369"), "2369 7") Test.assertEquals(highAndLow("138 2945 78 0 18752 924"), "18752 0") Test.assertEquals(highAndLow("-289 0 289"), "289 -289") })
- describe('tests', () => {
- Test.assertEquals(highAndLow("So, even list of 1, 3, -5, 7 and 14 is handled properly"), "14 -5")
- Test.assertEquals(highAndLow("1 4 2 6 1 6 1 5 2 8 9"), "9 1")
- Test.assertEquals(highAndLow("1 4 2 6 -10 6 1 5 2 8 9"), "9 -10")
- Test.assertEquals(highAndLow("5"), "5 5")
- Test.assertEquals(highAndLow("-13"), "-13 -13")
- Test.assertEquals(highAndLow("-42 -15 -16 -23 -8 -4"), "-4 -42")
- Test.assertEquals(highAndLow("7 2369"), "2369 7")
- Test.assertEquals(highAndLow("138 2945 78 0 18752 924"), "18752 0")
- Test.assertEquals(highAndLow("-289 0 289"), "289 -289")
- })