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.
Improve test cases.
#!/bin/bash if [ $# -eq 1 ]; then echo "$(dirname $1), $(basename ${1%.*}), ${1##*.}" fi
- #!/bin/bash
filename=$1echo "$(dirname $filename), $(basename ${filename%.*}), ${filename##*.}"- if [ $# -eq 1 ]; then
- echo "$(dirname $1), $(basename ${1%.*}), ${1##*.}"
- fi
test1 = run_shell args: ["/Users/Tech/Desktop/backup/Nutters_with_Putters_Revenge_of_the_Nutters2.avi"] test2 = run_shell args: ["/home/codewarrior/shell/file1.csv"] test3 = run_shell args: ["/home/codewarrior/shell/test2.txt"] test4 = run_shell args: ["/etc/file3.odf"] test5 = run_shell args: ["/boot/vmlinuz-linux"] describe "Solution" do it "Should return Comma Separated List" do expect(test1).to include("/Users/Tech/Desktop/backup, Nutters_with_Putters_Revenge_of_the_Nutters2, avi") expect(test2).to include("/home/codewarrior/shell, file1, csv") expect(test3).to include("/home/codewarrior/shell, test2, txt") expect(test4).to include("/etc, file3, odf") expect(test5).to include("/boot, vmlinuz-linux,") end end
output = run_shell args: ["/Users/Tech/Desktop/backup/Nutters_with_Putters_Revenge_of_the_Nutters2.avi"]- test1 = run_shell args: ["/Users/Tech/Desktop/backup/Nutters_with_Putters_Revenge_of_the_Nutters2.avi"]
- test2 = run_shell args: ["/home/codewarrior/shell/file1.csv"]
- test3 = run_shell args: ["/home/codewarrior/shell/test2.txt"]
- test4 = run_shell args: ["/etc/file3.odf"]
- test5 = run_shell args: ["/boot/vmlinuz-linux"]
- describe "Solution" do
- it "Should return Comma Separated List" do
expect(output).to include("/Users/Tech/Desktop/backup, Nutters_with_Putters_Revenge_of_the_Nutters2, avi")- expect(test1).to include("/Users/Tech/Desktop/backup, Nutters_with_Putters_Revenge_of_the_Nutters2, avi")
- expect(test2).to include("/home/codewarrior/shell, file1, csv")
- expect(test3).to include("/home/codewarrior/shell, test2, txt")
- expect(test4).to include("/etc, file3, odf")
- expect(test5).to include("/boot, vmlinuz-linux,")
- end
- end
output = run_shell args: ['test'] describe "Solution" do it "should not print 'csh'" do expect(output).not_to(include('csh')) end it "should print 'test'" do expect(output).to(include('test')) end end
- output = run_shell args: ['test']
- describe "Solution" do
output = run_shell(args: ['test']).strip- it "should not print 'csh'" do
- expect(output).not_to(include('csh'))
- end
- it "should print 'test'" do
- expect(output).to(include('test'))
- end
- end
#!/bin/bash # Without newline: echo -n test # With newline echo test
- #!/bin/bash
- # Without newline:
- echo -n test
- # With newline
- echo test
describe "Solution" do it "should print 'test'" do expect(run_shell.strip).to eq('testtest') end end
- describe "Solution" do
- it "should print 'test'" do
expect(run_shell.strip).to eq('test')- expect(run_shell.strip).to eq('testtest')
- end
- end
# What are all the ways to output a string in Ruby? def hello_ruby greet = "Hello Ruby!" print greet, "\n" puts greet print greet, "\n" puts greet $stdout.write greet + "\n" $stdout.puts greet $stdout.print greet, "\n" $stdout << greet + "\n" (greet+"\n").chars {|c| print c} end
- # What are all the ways to output a string in Ruby?
- def hello_ruby
- greet = "Hello Ruby!"
- print greet, "\n"
- puts greet
print "#{greet}"puts "Hello Ruby!"- print greet, "
- "
- puts greet
- $stdout.write greet + "\n"
- $stdout.puts greet
- $stdout.print greet, "\n"
- $stdout << greet + "\n"
(greet+"").each_char {|c| print c}- (greet+"
- ").chars {|c| print c}
- end
def getVillianName(birthday): return '{} {}'.format( FIRSTNAME[birthday.strftime("%B")], LASTNAME[birthday.strftime("%d")[1]])
- def getVillianName(birthday):
result = ""result = FIRSTNAME[birthday.strftime("%B")] + " "result += LASTNAME[birthday.strftime("%d")[1]]return result- return '{} {}'.format( FIRSTNAME[birthday.strftime("%B")],
- LASTNAME[birthday.strftime("%d")[1]])
import itertools def eratosthenes(): # From Coobook recipies # Credits to: Credit: David Eppstein, Tim Peters, Alex Martelli, # Wim Stolker, Kazuo Moriwaka, Hallvard Furuseth, Pierre Denis, # Tobias Klausmann, David Lees, Raymond Hettinger D = {} yield 2 for q in itertools.islice(itertools.count(3), 0, None, 2): p = D.pop(q, None) if p is None: D[q * q] = q yield q else: x = p + q while x in D or not (x & 1): x += p D[x] = p def count_primes(limit): count = 0 for prime in eratosthenes(): if prime > limit: return count count += 1
- import itertools
from itertools import *- def eratosthenes():
#From Coobook recipies#Credits to: Credit: David Eppstein, Tim Peters, Alex Martelli,#Wim Stolker, Kazuo Moriwaka, Hallvard Furuseth, Pierre Denis,#Tobias Klausmann, David Lees, Raymond HettingerD = { }- # From Coobook recipies
- # Credits to: Credit: David Eppstein, Tim Peters, Alex Martelli,
- # Wim Stolker, Kazuo Moriwaka, Hallvard Furuseth, Pierre Denis,
- # Tobias Klausmann, David Lees, Raymond Hettinger
- D = {}
- yield 2
- for q in itertools.islice(itertools.count(3), 0, None, 2):
- p = D.pop(q, None)
- if p is None:
D[q*q] = q- D[q * q] = q
- yield q
- else:
- x = p + q
while x in D or not (x&1):- while x in D or not (x & 1):
- x += p
- D[x] = p
- def count_primes(limit):
- count = 0
- for prime in eratosthenes():
if prime > limit: return count- if prime > limit:
- return count
- count += 1
import itertools def eratosthenes(): D = { } yield 2 for q in itertools.islice(itertools.count(3), 0, None, 2): p = D.pop(q, None) if p is None: D[q*q] = q yield q else: x = p + q while x in D or not (x&1): x += p D[x] = p def count_primes_sol(limit): count = 0 for prime in eratosthenes(): if prime > limit: return count count += 1 test.describe("Basic Tests") test.assert_equals(count_primes(10), 4) test.assert_equals(count_primes(20), 8) test.assert_equals(count_primes(50), 15) test.assert_equals(count_primes(100), 25) test.describe("Random Tests") from random import randint test.describe("100 <= limit <= 1000") for h in range(20): limit = randint(100, 1000) result = count_primes_sol(limit) res = count_primes(limit) test.it("Testing for limit = " + str(limit)) test.assert_equals(res, result) test.it("Result = " + str(result)) test.describe("1000 <= limit <= 5000") for h in range(20): limit = randint(1000, 5000) result = count_primes_sol(limit) res = count_primes(limit) test.it("Testing for limit = " + str(limit)) test.assert_equals(res, result) test.it("Result = " + str(result)) test.describe("5000 <= limit <= 10000") for h in range(20): limit = randint(5000, 10000) result = count_primes_sol(limit) res = count_primes(limit) test.it("Testing for limit = " + str(limit)) test.assert_equals(res, result) test.it("Result = " + str(result)) test.describe("10000 <= limit <= 50000") for h in range(20): limit = randint(10000, 50000) result = count_primes_sol(limit) res = count_primes(limit) test.it("Testing for limit = " + str(limit)) test.assert_equals(res, result) test.it("Result = " + str(result)) test.describe("1000 <= limit <= 5000") for h in range(20): limit = randint(50000, 100000) result = count_primes_sol(limit) res = count_primes(limit) test.it("Testing for limit = " + str(limit)) test.assert_equals(res, result) test.it("Result = " + str(result)) test.describe("100000 <= limit <= 500000") for h in range(10): limit = randint(100000, 500000) result = count_primes_sol(limit) res = count_primes(limit) test.it("Testing for limit = " + str(limit)) test.assert_equals(res, result) test.it("Result = " + str(result)) test.describe("500000 <= limit <= 1000000") for h in range(3): limit = randint(500000, 1000000) result = count_primes_sol(limit) res = count_primes(limit) test.it("Testing for limit = " + str(limit)) test.assert_equals(res, result) test.it("Result = " + str(result)) test.describe("1000000 <= limit <= 5000000") for h in range(2): limit = randint(1000000, 5000000) result = count_primes_sol(limit) res = count_primes(limit) test.it("Testing for limit = " + str(limit)) test.assert_equals(res, result) test.it("Result = " + str(result))
- import itertools
from itertools import *- def eratosthenes():
- D = { }
- yield 2
- for q in itertools.islice(itertools.count(3), 0, None, 2):
- p = D.pop(q, None)
- if p is None:
- D[q*q] = q
- yield q
- else:
- x = p + q
- while x in D or not (x&1):
- x += p
- D[x] = p
- def count_primes_sol(limit):
- count = 0
- for prime in eratosthenes():
- if prime > limit: return count
- count += 1
- test.describe("Basic Tests")
- test.assert_equals(count_primes(10), 4)
- test.assert_equals(count_primes(20), 8)
- test.assert_equals(count_primes(50), 15)
- test.assert_equals(count_primes(100), 25)
- test.describe("Random Tests")
- from random import randint
- test.describe("100 <= limit <= 1000")
- for h in range(20):
- limit = randint(100, 1000)
- result = count_primes_sol(limit)
- res = count_primes(limit)
- test.it("Testing for limit = " + str(limit))
- test.assert_equals(res, result)
- test.it("Result = " + str(result))
- test.describe("1000 <= limit <= 5000")
- for h in range(20):
- limit = randint(1000, 5000)
- result = count_primes_sol(limit)
- res = count_primes(limit)
- test.it("Testing for limit = " + str(limit))
- test.assert_equals(res, result)
- test.it("Result = " + str(result))
- test.describe("5000 <= limit <= 10000")
- for h in range(20):
- limit = randint(5000, 10000)
- result = count_primes_sol(limit)
- res = count_primes(limit)
- test.it("Testing for limit = " + str(limit))
- test.assert_equals(res, result)
- test.it("Result = " + str(result))
- test.describe("10000 <= limit <= 50000")
- for h in range(20):
- limit = randint(10000, 50000)
- result = count_primes_sol(limit)
- res = count_primes(limit)
- test.it("Testing for limit = " + str(limit))
- test.assert_equals(res, result)
- test.it("Result = " + str(result))
- test.describe("1000 <= limit <= 5000")
- for h in range(20):
- limit = randint(50000, 100000)
- result = count_primes_sol(limit)
- res = count_primes(limit)
- test.it("Testing for limit = " + str(limit))
- test.assert_equals(res, result)
- test.it("Result = " + str(result))
- test.describe("100000 <= limit <= 500000")
- for h in range(10):
- limit = randint(100000, 500000)
- result = count_primes_sol(limit)
- res = count_primes(limit)
- test.it("Testing for limit = " + str(limit))
- test.assert_equals(res, result)
- test.it("Result = " + str(result))
- test.describe("500000 <= limit <= 1000000")
- for h in range(3):
- limit = randint(500000, 1000000)
- result = count_primes_sol(limit)
- res = count_primes(limit)
- test.it("Testing for limit = " + str(limit))
- test.assert_equals(res, result)
- test.it("Result = " + str(result))
- test.describe("1000000 <= limit <= 5000000")
- for h in range(2):
- limit = randint(1000000, 5000000)
- result = count_primes_sol(limit)
- res = count_primes(limit)
- test.it("Testing for limit = " + str(limit))
- test.assert_equals(res, result)
- test.it("Result = " + str(result))
using System; using System.Linq; public class Kata { private const int monmeValue = 60; public static int[] PurchaseTofu(int cost, string box) { string[] boxSplited = box.Split(' '); var monCount = boxSplited.Count(x => x == "mon");//one foreach will be faster than this 2 lines but this is easier to read var monmeCount = boxSplited.Count(x => x == "monme"); var totalValue = monCount + (monmeCount * monmeValue); int monmeCounter = Math.Min(cost / monmeValue, monmeCount); cost -= monmeCounter * monmeValue; return (monCount < cost) ? new[] { 0 } : //leaving the market new[] { monCount, monmeCount, totalValue, monmeCounter + cost }; } }
- using System;
- using System.Linq;
- public class Kata
- {
- private const int monmeValue = 60;
- public static int[] PurchaseTofu(int cost, string box)
- {
string[] boxSplited = box.Split(' ');- string[] boxSplited = box.Split(' ');
- var monCount = boxSplited.Count(x => x == "mon");//one foreach will be faster than this 2 lines but this is easier to read
- var monmeCount = boxSplited.Count(x => x == "monme");
var totalValue = monCount + (monmeCount * 60);- var totalValue = monCount + (monmeCount * monmeValue);
int monmeCounter = cost / 60;if (monmeCounter > monmeCount){monmeCounter = monmeCount;}cost -= monmeCounter*60;- int monmeCounter = Math.Min(cost / monmeValue, monmeCount);
- cost -= monmeCounter * monmeValue;
if (monCount < cost){return new[] { 0 };//leaving the market}return new[] { monCount, monmeCount, totalValue, monmeCounter + cost };- return (monCount < cost) ?
- new[] { 0 } : //leaving the market
- new[] { monCount, monmeCount, totalValue, monmeCounter + cost };
- }
- }