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.
A bit cleaner
# from random import choice # adj = ("Leviathian","Gargantuan","Greedy","Fallen","Horrible","Twisted","Depraved","Hungry","Evil","Vengeful","Empty","Vile","Terrible", "Gluttonous") # def im_sorry(): # first = choice(adj) # second = choice(adj) # last = choice(adj) # while last==first or last==second or first==second: # last=choice(adj) # first=choice(adj) # return first+" "+second+" Garfield, The "+last + " One" from numpy.random import choice adjs = ("Leviathian","Gargantuan","Greedy","Fallen","Horrible","Twisted","Depraved","Hungry","Evil","Vengeful","Empty","Vile","Terrible", "Gluttonous") def im_sorry(): choices = choice(adjs, 3, replace=False) return f"{choices[0]} {choices[1]} Garfield, The {choices[2]} One"
from random import choice- # from random import choice
adj = ("Leviathian","Gargantuan","Greedy","Fallen","Horrible","Twisted","Depraved","Hungry","Evil","Vengeful","Empty","Vile","Terrible", "Gluttonous")- # adj = ("Leviathian","Gargantuan","Greedy","Fallen","Horrible","Twisted","Depraved","Hungry","Evil","Vengeful","Empty","Vile","Terrible", "Gluttonous")
- # def im_sorry():
- # first = choice(adj)
- # second = choice(adj)
- # last = choice(adj)
- # while last==first or last==second or first==second:
- # last=choice(adj)
- # first=choice(adj)
- # return first+" "+second+" Garfield, The "+last + " One"
- from numpy.random import choice
- adjs = ("Leviathian","Gargantuan","Greedy","Fallen","Horrible","Twisted","Depraved","Hungry","Evil","Vengeful","Empty","Vile","Terrible", "Gluttonous")
- def im_sorry():
first = choice(adj)second = choice(adj)last = choice(adj)while last==first or last==second or first==second:last=choice(adj)first=choice(adj)return first+" "+second+" Garfield, The "+last + " One"- choices = choice(adjs, 3, replace=False)
- return f"{choices[0]} {choices[1]} Garfield, The {choices[2]} One"
#include<iostream> int doubleValue(int x) { return x * 2; }
- #include<iostream>
- int doubleValue(int x) {
- return x * 2;
- }
int main(){int x = 5; //example valueint result = doubleValue(x);std::cout << "The double of " << x << " is " << result << std::endl;return 0;}
// TODO: Replace examples and use TDD by writing your own tests Describe(sampleTests) { It(shouldBe) { Assert::That(doubleValue(5), Equals(10)); } };
- // TODO: Replace examples and use TDD by writing your own tests
Describe(any_group_name_you_want){It(should_do_something){Assert::That("some value", Equals("another value"));}};- Describe(sampleTests) {
- It(shouldBe) {
- Assert::That(doubleValue(5), Equals(10));
- }
- };
requires O(n) extra space
memo={0:"Even"} curr=0 isEven=True def even_or_odd(n): def enclosed(): global memo global curr global isEven nonlocal n if n in memo: return memo[n] while curr<=n: memo[curr]= "Even" if isEven else "Odd" curr+=1 isEven=not isEven return memo[n] return enclosed() # memo={} # def even_or_odd(n): # def enclosed(): # global memo # nonlocal n # if n in memo: # return memo[n] # memo[n]= "Odd" if n&1 else "Even" # return memo[n] # print(memo) # return enclosed() # memo={0:"Even"} # curr=0 # isEven=True # def even_or_odd(n): # global isEven # global curr # if n in memo: # return memo[n] # while curr<=n: # memo[curr]="Even" if isEven else "Odd" # curr+=1 # isEven=not isEven # return memo[n] #
even_or_odd = lambda x: "Even" if x%2==0 else "Odd"- memo={0:"Even"}
- curr=0
- isEven=True
- def even_or_odd(n):
- def enclosed():
- global memo
- global curr
- global isEven
- nonlocal n
- if n in memo:
- return memo[n]
- while curr<=n:
- memo[curr]= "Even" if isEven else "Odd"
- curr+=1
- isEven=not isEven
- return memo[n]
- return enclosed()
- # memo={}
- # def even_or_odd(n):
- # def enclosed():
- # global memo
- # nonlocal n
- # if n in memo:
- # return memo[n]
- # memo[n]= "Odd" if n&1 else "Even"
- # return memo[n]
- # print(memo)
- # return enclosed()
- # memo={0:"Even"}
- # curr=0
- # isEven=True
- # def even_or_odd(n):
- # global isEven
- # global curr
- # if n in memo:
- # return memo[n]
- # while curr<=n:
- # memo[curr]="Even" if isEven else "Odd"
- # curr+=1
- # isEven=not isEven
- # return memo[n]
- #
import codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(even_or_odd(0), "Even", "0 is even") test.assert_equals(even_or_odd(2), "Even", "2 is even") test.assert_equals(even_or_odd(3), "Odd", "3 is odd") test.assert_equals(even_or_odd(24), "Even", "24 is even") test.assert_equals(even_or_odd(25), "Odd", "25 is odd") test.assert_equals(even_or_odd(115), "Odd", "115 is odd") test.assert_equals(even_or_odd(98), "Even", "98 is even") test.assert_equals(even_or_odd(1048576), "Even", "98 is even") # test.assert_equals(even_or_odd(18446744073709551615), "Odd", "the number is even you baka") #fails test.assert_equals(even_or_odd(18446744073709551616), "Even", "98 is even")
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(even_or_odd(0), "Even", "0 is even")
- test.assert_equals(even_or_odd(2), "Even", "2 is even")
- test.assert_equals(even_or_odd(3), "Odd", "3 is odd")
- test.assert_equals(even_or_odd(24), "Even", "24 is even")
- test.assert_equals(even_or_odd(25), "Odd", "25 is odd")
- test.assert_equals(even_or_odd(115), "Odd", "115 is odd")
- test.assert_equals(even_or_odd(98), "Even", "98 is even")
- test.assert_equals(even_or_odd(1048576), "Even", "98 is even")
test.assert_equals(even_or_odd(18446744073709551615), "Odd", "the number is even you baka")- # test.assert_equals(even_or_odd(18446744073709551615), "Odd", "the number is even you baka")
- #fails test.assert_equals(even_or_odd(18446744073709551616), "Even", "98 is even")
It ain't getting any smaller than this (I think)
better lol
public static class Kata { public static int SameCase(char a, char b) => !char.IsLetter(a) || !char.IsLetter(b) ? -1 : char.IsUpper(a) == char.IsUpper(b) ? 1 : 0; }
- public static class Kata
- {
public static int SameCase(char a, char b){if (!char.IsLetter(a) || !char.IsLetter(b))return -1;return char.IsUpper(a) == char.IsUpper(b) ? 1 : 0;}- public static int SameCase(char a, char b) =>
- !char.IsLetter(a) || !char.IsLetter(b) ? -1 :
- char.IsUpper(a) == char.IsUpper(b) ? 1 : 0;
- }
function returnhundred(clаss = "-🤓") { return Math.floor( doMath(f, 0.0504, Math.PI ** (clаss.length - 1) * Math.E - Math.log(gamma(10.7))) ); }; const gamma = x => { if (x < 0.5) { return Math.PI / (Math.sin(Math.PI * x) * gamma(1 - x)); } else { x -= 1; let l = 0.99999999999980993; const l0 = [ 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7, ]; for (let i = 0; i < 8; i++) { l += l0[i] / (x + i + 1); } const t = x + 7.5; return Math.sqrt(2 * Math.PI) * Math.pow(t, x + 0.5) * Math.exp(-t) * l; } }; const doMath = (f, start, end) => { let res = 0; const base = (end - start) / gamma(0.0000001); for (let i = start; i < end; i += base) { const [left, right] = [f(i), f(i + base)]; res += (left + right) / "🤓".length; } return Math.ceil(base * res); }; const f = x => { return Math.abs( Math.exp( "�".length * Math.sinh( 2 * Math.cos( (Math.tan(x) % gamma(Math.PI)) * Math.sqrt(314) ) ) ) / ((1 / 20) * 16) ); }
returnhundred=ಠ_ಠ=>100- function returnhundred(clаss = "-🤓") {
- return Math.floor(
- doMath(f, 0.0504, Math.PI ** (clаss.length - 1) * Math.E - Math.log(gamma(10.7)))
- );
- };
- const gamma = x => {
- if (x < 0.5) {
- return Math.PI / (Math.sin(Math.PI * x) * gamma(1 - x));
- } else {
- x -= 1;
- let l = 0.99999999999980993;
- const l0 = [
- 676.5203681218851, -1259.1392167224028, 771.32342877765313,
- -176.61502916214059, 12.507343278686905, -0.13857109526572012,
- 9.9843695780195716e-6, 1.5056327351493116e-7,
- ];
- for (let i = 0; i < 8; i++) {
- l += l0[i] / (x + i + 1);
- }
- const t = x + 7.5;
- return Math.sqrt(2 * Math.PI) * Math.pow(t, x + 0.5) * Math.exp(-t) * l;
- }
- };
- const doMath = (f, start, end) => {
- let res = 0;
- const base = (end - start) / gamma(0.0000001);
- for (let i = start; i < end; i += base) {
- const [left, right] = [f(i), f(i + base)];
- res += (left + right) / "🤓".length;
- }
- return Math.ceil(base * res);
- };
- const f = x => {
- return Math.abs(
- Math.exp(
- "�".length *
- Math.sinh(
- 2 *
- Math.cos(
- (Math.tan(x) % gamma(Math.PI)) * Math.sqrt(314)
- )
- )
- ) /
- ((1 / 20) * 16)
- );
- }
const { assert: { strictEqual } } = require('chai'); describe("100", () => it("One hundred.", () => strictEqual(returnhundred(), 100)));
// TODO: Add your tests here// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)// are still available for now.//// For new tests, using [Chai](https://chaijs.com/) is recommended.// You can use it by requiring:// const assert = require("chai").assert;// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.const assert = require("chai").assert;describe("Solution", function() {it("should test for something", function() {assert.strictEqual(returnhundred(),100)})})- const { assert: { strictEqual } } = require('chai');
- describe("100", () => it("One hundred.", () => strictEqual(returnhundred(), 100)));
Avoid arbitary code execution
function Calculator { param ( [int]$n1, [ValidateSet("+", "*", "-")] [string]$s, [int]$n2 ) Invoke-Expression ("$n1 $s $n2") }
function Calculator ($n1,$s,$n2 ){Invoke-Expression ("$n1 $s $n2")- function Calculator {
- param (
- [int]$n1,
- [ValidateSet("+", "*", "-")]
- [string]$s,
- [int]$n2
- )
- Invoke-Expression ("$n1 $s $n2")
- }
Describe 'Calculator' { BeforeAll { # Easy breezy tests $test1 = Calculator -n1 4 -n2 5 -s '+' $test2 = Calculator -n1 12 -n2 5 -s '-' $test3 = Calculator -n1 20 -n2 3 -s '*' $test4 = { Calculator "Write-Host" "Hello World" } } Context 'FixedTests' { It "Should pass" { $test1 | Should -Be 9 } It "Should pass" { $test2 | Should -Be 7 } It "Should pass" { $test3 | Should -Be 60 } It "Should throw" { { $test4.Invoke() } | Should -Throw } } Context 'RandomTests' { function ans($n1, $s, $n2 ) { Invoke-Expression ("$n1 $s $n2") } 0..100 | ForEach-Object { $s = '+', '-', '*' | Get-Random $n1 = Get-Random -Maximum 1000 $n2 = Get-Random -Maximum 1000 $ans = ans($n1, $s, $n2) It "Should pass" { Calculator $n1 $s $n2 | Should -be $ans } } } }
# Easy breezy tests$test1 = Calculator -n1 4 -n2 5 -s '+'$test2 = Calculator -n1 12 -n2 5 -s '-'$test3 = Calculator -n1 20 -n2 3 -s '*'Describe 'FixedTests' {It "Should pass" {$test1 | Should be 9}It "Should pass" {$test2 | Should be 7}It "Should pass" {$test3 | Should be 60}}Describe 'RandomTests' {function ans($n1,$s,$n2 ){Invoke-Expression ("$n1 $s $n2")}for($i =0; $i -lt 100; $i++){$s = '+','-','*' | Get-Random$n1 = Get-Random -Maximum 1000$n2 = Get-Random -Maximum 1000$ans = ans($n1,$s,$n2)It "Should pass" {Calculator ($n1,$s,$n2)| Should be $ans- Describe 'Calculator' {
- BeforeAll {
- # Easy breezy tests
- $test1 = Calculator -n1 4 -n2 5 -s '+'
- $test2 = Calculator -n1 12 -n2 5 -s '-'
- $test3 = Calculator -n1 20 -n2 3 -s '*'
- $test4 = { Calculator "Write-Host" "Hello World" }
- }
- Context 'FixedTests' {
- It "Should pass" {
- $test1 | Should -Be 9
- }
- It "Should pass" {
- $test2 | Should -Be 7
- }
- It "Should pass" {
- $test3 | Should -Be 60
- }
- It "Should throw" {
- { $test4.Invoke() } | Should -Throw
- }
- }
}}- Context 'RandomTests' {
- function ans($n1, $s, $n2 ) {
- Invoke-Expression ("$n1 $s $n2")
- }
- 0..100 | ForEach-Object {
- $s = '+', '-', '*' | Get-Random
- $n1 = Get-Random -Maximum 1000
- $n2 = Get-Random -Maximum 1000
- $ans = ans($n1, $s, $n2)
- It "Should pass" {
- Calculator $n1 $s $n2 | Should -be $ans
- }
- }
- }
- }