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.
just made it shorter
public class ReverseString { public static String reverseString(String word) { StringBuilder result = new StringBuilder(word); return result.reverse().toString(); } }
- public class ReverseString {
- public static String reverseString(String word) {
StringBuilder result = new StringBuilder();result.append(word);// adds the word to the stringresult.reverse();// you know REVERSES itreturn result.toString();- StringBuilder result = new StringBuilder(word);
- return result.reverse().toString();
- }
- }
#include <iostream> #include <vector> #include <algorithm> #include <cassert> int unique_sum(const std::vector<int>& n) { auto nums = n; std::sort(nums.begin(), nums.end(), [](int a, int b) { return a < b; }); int sum = 0; for(size_t i = 0; i < nums.size(); i++) { if(nums[i] == nums[i+1] || nums[i] == nums[i-1]) { continue; } else { sum += nums[i]; } } return sum; }
- #include <iostream>
- #include <vector>
#include <unordered_map>- #include <algorithm>
- #include <cassert>
int unique_sum(const std::vector<int>& nums) {std::unordered_map<int, int> hashMap;for (int i = 0; i < nums.size(); i++) {if (hashMap.find(nums[i]) == hashMap.end()) {hashMap[nums[i]] = nums[i];- int unique_sum(const std::vector<int>& n) {
- auto nums = n;
- std::sort(nums.begin(), nums.end(), [](int a, int b) {
- return a < b;
- });
- int sum = 0;
- for(size_t i = 0; i < nums.size(); i++) {
- if(nums[i] == nums[i+1] || nums[i] == nums[i-1]) {
- continue;
- } else {
hashMap[nums[i]] = 0;- sum += nums[i];
- }
- }
int sum = 0;for (auto i: hashMap) {sum = sum + hashMap[i.first];}- return sum;
- }
// TODO: Replace examples and use TDD by writing your own tests Describe(unique_sum_of_numbers) { It(should_do_something) { Assert::That(unique_sum({1,2,3,2}), Equals(4)); Assert::That(unique_sum({1,1,2,3}), Equals(5)); Assert::That(unique_sum({-1,-1,0,1}), Equals(1)); }; It(should_do_something_other) { Assert::That(unique_sum({}), Equals(0)); Assert::That(unique_sum({5, 5, 5, 5}), Equals(0)); Assert::That(unique_sum({10, 20, 30, 20, 10}), Equals(30)); Assert::That(unique_sum({1, 2, 3, 4, 5}), Equals(15)); Assert::That(unique_sum({-5, -5, 0, 5, 5}), Equals(0)); Assert::That(unique_sum({-1, 2, -1, 3, 4, 2}), Equals(7)); Assert::That(unique_sum({1, 2, 3, 4, 5, 1, 2, 3}), Equals(9)); Assert::That(unique_sum({100, 200, 300, 300, 200, 100}), Equals(0)); } };
- // TODO: Replace examples and use TDD by writing your own tests
- Describe(unique_sum_of_numbers)
- {
- It(should_do_something)
- {
- Assert::That(unique_sum({1,2,3,2}), Equals(4));
- Assert::That(unique_sum({1,1,2,3}), Equals(5));
- Assert::That(unique_sum({-1,-1,0,1}), Equals(1));
- };
- It(should_do_something_other)
- {
- Assert::That(unique_sum({}), Equals(0));
- Assert::That(unique_sum({5, 5, 5, 5}), Equals(0));
- Assert::That(unique_sum({10, 20, 30, 20, 10}), Equals(30));
- Assert::That(unique_sum({1, 2, 3, 4, 5}), Equals(15));
- Assert::That(unique_sum({-5, -5, 0, 5, 5}), Equals(0));
- Assert::That(unique_sum({-1, 2, -1, 3, 4, 2}), Equals(7));
- Assert::That(unique_sum({1, 2, 3, 4, 5, 1, 2, 3}), Equals(9));
- Assert::That(unique_sum({100, 200, 300, 300, 200, 100}), Equals(0));
- }
import os class BitBlender: """BitBlender class""" def __init__(self, target_file, num=7, deletion=False): self.target_file = target_file self.num = num # number of times to overwrite file self.deletion = deletion self.file_size = os.path.getsize(self.target_file) if os.path.exists(self.target_file): self.file_size = os.path.getsize(self.target_file) else: raise FileNotFoundError(f"The file '{self.target_file}' does not exist.") def execute(self): try: # Overwrite the file with random data with open(self.target_file, "wb") as f: # Repeat this process num times for i in range(self.num): f.write(os.urandom(self.file_size)) # If you choose to delete: if self.deletion: os.remove(self.target_file) except Exception as e: print(f"Error: {e}")
- import os
- class BitBlender:
- """BitBlender class"""
- def __init__(self, target_file, num=7, deletion=False):
- self.target_file = target_file
- self.num = num # number of times to overwrite file
- self.deletion = deletion
- self.file_size = os.path.getsize(self.target_file)
- if os.path.exists(self.target_file):
- self.file_size = os.path.getsize(self.target_file)
- else:
- raise FileNotFoundError(f"The file '{self.target_file}' does not exist.")
- def execute(self):
pass- try:
- # Overwrite the file with random data
- with open(self.target_file, "wb") as f:
- # Repeat this process num times
- for i in range(self.num):
- f.write(os.urandom(self.file_size))
- # If you choose to delete:
- if self.deletion:
- os.remove(self.target_file)
- except Exception as e:
- print(f"Error: {e}")
import codewars_test as test import os import filecmp # used for file comparison import shutil # used to copy files from solution import BitBlender, fake_data # Create fake sample files fake_data('sample_01.txt') fake_data('sample_02.txt') fake_data('sample_03.txt') # Create copies of sample file for comparison shutil.copy('sample_01.txt', 'sample_01_copy.txt') shutil.copy('sample_02.txt', 'sample_02_copy.txt') shutil.copy('sample_03.txt', 'sample_03_copy.txt') samples = [('sample_01.txt', 'sample_01_copy.txt'), ('sample_02.txt', 'sample_02_copy.txt'), ('sample_03.txt', 'sample_03_copy.txt'), ] @test.describe("Test BitBlender") def test_group(): @test.it("Overwrite Sample Data") def test_case(): for sample in samples: # overwrite the sample files BitBlender(target_file=sample[0]).execute() # Compare orignal files with overwritten files for sample in samples: result = filecmp.cmp(sample[0], sample[1], shallow=False) test.assert_equals(result, False) @test.it("Delete Sample Data") def test_case(): for sample in samples: # overwrite the sample files + deletion BitBlender(target_file=sample[0], deletion=True).execute() # Check if file exists for sample in samples: result = os.path.exists(sample[0]) test.assert_equals(result, False) # Remove copied sample data for s in samples: os.remove(s[1])
- import codewars_test as test
- import os
- import filecmp # used for file comparison
- import shutil # used to copy files
- from solution import BitBlender, fake_data
- # Create fake sample files
- fake_data('sample_01.txt')
- fake_data('sample_02.txt')
- fake_data('sample_03.txt')
- # Create copies of sample file for comparison
- shutil.copy('sample_01.txt', 'sample_01_copy.txt')
- shutil.copy('sample_02.txt', 'sample_02_copy.txt')
- shutil.copy('sample_03.txt', 'sample_03_copy.txt')
- samples = [('sample_01.txt', 'sample_01_copy.txt'),
- ('sample_02.txt', 'sample_02_copy.txt'),
- ('sample_03.txt', 'sample_03_copy.txt'),
- ]
- @test.describe("Test BitBlender")
- def test_group():
- @test.it("Overwrite Sample Data")
- def test_case():
- for sample in samples:
# overwritte the sample files- # overwrite the sample files
- BitBlender(target_file=sample[0]).execute()
- # Compare orignal files with overwritten files
- for sample in samples:
- result = filecmp.cmp(sample[0], sample[1], shallow=False)
- test.assert_equals(result, False)
- @test.it("Delete Sample Data")
- def test_case():
- for sample in samples:
# overwritte the sample files- # overwrite the sample files + deletion
- BitBlender(target_file=sample[0], deletion=True).execute()
- # Check if file exists
- for sample in samples:
- result = os.path.exists(sample[0])
- test.assert_equals(result, False)
- # Remove copied sample data
- for s in samples:
- os.remove(s[1])
- Trimmed down the function name for minimum characters
ClosestToZero=lambda n:type("",(),{"e":lambda v=min(n,key=abs,default=0):dict(zip(n,n)).get(abs(v),v),"n":n})
ClosestToZero=lambda n:type("",(),{"execute":lambda v=min(n,key=abs,default=0):dict(zip(n,n)).get(abs(v),v),"n":n})- ClosestToZero=lambda n:type("",(),{"e":lambda v=min(n,key=abs,default=0):dict(zip(n,n)).get(abs(v),v),"n":n})
import codewars_test as test from solution import ClosestToZero @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(ClosestToZero([7, 5, 9, 1, 4]).e(), 1) test.assert_equals(ClosestToZero([7,-4, -3, -12, 5, 9, -2, 4]).e(), -2) test.assert_equals(ClosestToZero([-5, -5]).e(), -5) test.assert_equals(ClosestToZero([]).e(), 0) test.assert_equals(ClosestToZero([-5, 0, 1, 5]).e(), 0) test.assert_equals(ClosestToZero([-5, -1, 1, 5]).e(), 1)
- import codewars_test as test
- from solution import ClosestToZero
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_equals(ClosestToZero([7, 5, 9, 1, 4]).execute(), 1)test.assert_equals(ClosestToZero([7,-4, -3, -12, 5, 9, -2, 4]).execute(), -2)test.assert_equals(ClosestToZero([-5, -5]).execute(), -5)test.assert_equals(ClosestToZero([]).execute(), 0)test.assert_equals(ClosestToZero([-5, 0, 1, 5]).execute(), 0)test.assert_equals(ClosestToZero([-5, -1, 1, 5]).execute(), 1)- test.assert_equals(ClosestToZero([7, 5, 9, 1, 4]).e(), 1)
- test.assert_equals(ClosestToZero([7,-4, -3, -12, 5, 9, -2, 4]).e(), -2)
- test.assert_equals(ClosestToZero([-5, -5]).e(), -5)
- test.assert_equals(ClosestToZero([]).e(), 0)
- test.assert_equals(ClosestToZero([-5, 0, 1, 5]).e(), 0)
- test.assert_equals(ClosestToZero([-5, -1, 1, 5]).e(), 1)
- Botched the indents
class MaxDigit: def __init__(s, n):s.n = n def execute(s): return int(''.join(sorted(str(s.n), reverse=True)))
- class MaxDigit:
def __init__(s, n):s.n = ndef execute(s):return int(''.join(sorted(str(s.n), reverse=True)))- def __init__(s, n):s.n = n
- def execute(s): return int(''.join(sorted(str(s.n), reverse=True)))