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.
#include <string> #include <fmt/ranges.h> auto digest(const std::string& param) { if (param.empty()) return param; // Oh... should check there !! return fmt::format("{}", fmt::join(param, " ")); }
- #include <string>
#include <numeric>- #include <fmt/ranges.h>
- auto digest(const std::string& param) {
- if (param.empty()) return param; // Oh... should check there !!
return std::accumulate(std::next(param.cbegin()),param.cend(),std::string(1,param[0]), // Char initializer[](auto &s, auto c) {return s+std::string{{' ',c}}; // initializer_list string initializer});- return fmt::format("{}", fmt::join(param, " "));
- }
The main change is that the file attribute is initialized to None instead of being conditionally set to an open file. Instead, the file is opened in the write_to_file method if it hasn't been opened yet. This makes the code more explicit and easier to reason about. Additionally, I added some whitespace and changed the indentation to conform to PEP 8 style guidelines.
class Solution: def __init__(self, data, filename='kumite776.txt', preopen=False): self.data = data self.filename = filename self.file = None if preopen: self.file = open(self.filename, 'w') def write_to_file(self): if not self.file: self.file = open(self.filename, 'w') self.file.write(self.data)
- class Solution:
- def __init__(self, data, filename='kumite776.txt', preopen=False):
- self.data = data
- self.filename = filename
self.file = open(self.filename, 'w') if preopen else None- self.file = None
- if preopen:
- self.file = open(self.filename, 'w')
- def write_to_file(self):
if not self.file: self.file = open(self.filename, 'w')- if not self.file:
- self.file = open(self.filename, 'w')
- self.file.write(self.data)
made more test cases so that the idiots who write one-line regex scripts need to write more to deal with Bool, Int, and NoneType :3
import random import codewars_test as test from solution import Connection, where_were_you_when_codewars_died import string locations = ["House", "Bar", "88.131.626.98:25565", random.randint(1,10), "Haus", "There", "Their", "They're", None] # test.assert_equals(actual, expected, [optional] message) @test.describe("Basic Cases") def test_group(): @test.it("test case") def test_case(): test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location='127.0.0.1', food_source='coffee'), 'I was at 127.0.0.1 consuming coffee when codewars died.') test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location='Phantom Forces', food_source='pizza'), 'I was at Phantom Forces consuming pizza when codewars died.') test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location='Phantom Forces', food_source=9), 'I was at Phantom Forces consuming 9 when codewars died.') @test.it("random cases") def randomcases(): for i in range(100): findtester = random.randint(1, 1000000) location = random.choice(locations) test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location=location, food_source=findtester), f'I was at {location} consuming {findtester} when codewars died.') @test.describe("Additional Test Cases") def test_group(): @test.it("empty strings") def test_empty_strings(): test.assert_equals(where_were_you_when_codewars_died(activity='', location='', food_source=''), 'I was at consuming when died.') @test.it("long strings") def test_long_strings(): activity = 'a' * 1000 location = 'b' * 1000 food_source = 'c' * 1000 expected = f"I was at {location} consuming {food_source} when {activity} died." test.assert_equals(where_were_you_when_codewars_died(activity=activity, location=location, food_source=food_source), expected) @test.it("special characters") def test_special_characters(): activity = 'c@de#wars' location = '127.0.0.1' food_source = 'coff$e!' expected = f"I was at {location} consuming {food_source} when {activity} died." test.assert_equals(where_were_you_when_codewars_died(activity=activity, location=location, food_source=food_source), expected) @test.it("different data types") def test_different_data_types(): test.assert_equals(where_were_you_when_codewars_died(activity=True, location=123, food_source=3.14), 'I was at 123 consuming 3.14 when True died.') test.assert_equals(where_were_you_when_codewars_died(activity=None, location=None, food_source=None), 'I was at None consuming None when None died.') @test.it("large number of random inputs") def test_large_number_of_random_inputs(): for i in range(100): activity = ''.join(random.choices(string.ascii_letters + string.digits, k=random.randint(1, 10))) location = random.choice(locations) food_source = random.choice(['coffee', 'pizza', 'burger', 'soda', 'water']) expected = f"I was at {location} consuming {food_source} when {activity} died." test.assert_equals(where_were_you_when_codewars_died(activity=activity, location=location, food_source=food_source), expected) @test.it("None inputs") def test_none_inputs(): test.assert_equals(where_were_you_when_codewars_died(activity=None, location=None, food_source=None), 'I was at None consuming None when None died.') @test.it("integer inputs") def test_integer_inputs(): test.assert_equals(where_were_you_when_codewars_died(activity=123, location=456, food_source=789), 'I was at 456 consuming 789 when 123 died.') @test.it("float inputs") def test_float_inputs(): test.assert_equals(where_were_you_when_codewars_died(activity=3.14, location=2.71, food_source=1.618), 'I was at 2.71 consuming 1.618 when 3.14 died.') @test.it("boolean inputs") def test_boolean_inputs(): test.assert_equals(where_were_you_when_codewars_died(activity=True, location=False, food_source=True), 'I was at False consuming True when True died.') @test.it("random inputs with special characters") def test_random_inputs_with_special_characters(): for i in range(100): activity = ''.join(random.choices(string.ascii_letters + string.digits + string.punctuation, k=random.randint(1, 10))) location = random.choice(locations) food_source = ''.join(random.choices(string.ascii_letters + string.digits + string.punctuation, k=random.randint(1, 10))) expected = f"I was at {location} consuming {food_source} when {activity} died." test.assert_equals(where_were_you_when_codewars_died(activity=activity, location=location, food_source=food_source), expected)
- import random
- import codewars_test as test
- from solution import Connection, where_were_you_when_codewars_died
- import string
- locations = ["House", "Bar", "88.131.626.98:25565", random.randint(1,10), "Haus", "There", "Their", "They're", None]
- # test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")- @test.describe("Basic Cases")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location='127.0.0.1', food_source='coffee'), 'I was at 127.0.0.1 consuming coffee when codewars died.')
- test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location='Phantom Forces', food_source='pizza'), 'I was at Phantom Forces consuming pizza when codewars died.')
- test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location='Phantom Forces', food_source=9), 'I was at Phantom Forces consuming 9 when codewars died.')
- @test.it("random cases")
- def randomcases():
locations = ["House", "Bar", "88.131.626.98:25565", random.randint(1,10), "Haus", "There", "Their", "They're", None]- for i in range(100):
- findtester = random.randint(1, 1000000)
- location = random.choice(locations)
- test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location=location, food_source=findtester), f'I was at {location} consuming {findtester} when codewars died.')
- @test.describe("Additional Test Cases")
- def test_group():
- @test.it("empty strings")
- def test_empty_strings():
- test.assert_equals(where_were_you_when_codewars_died(activity='', location='', food_source=''), 'I was at consuming when died.')
- @test.it("long strings")
- def test_long_strings():
- activity = 'a' * 1000
- location = 'b' * 1000
- food_source = 'c' * 1000
- expected = f"I was at {location} consuming {food_source} when {activity} died."
- test.assert_equals(where_were_you_when_codewars_died(activity=activity, location=location, food_source=food_source), expected)
- @test.it("special characters")
- def test_special_characters():
- activity = 'c@de#wars'
- location = '127.0.0.1'
- food_source = 'coff$e!'
- expected = f"I was at {location} consuming {food_source} when {activity} died."
- test.assert_equals(where_were_you_when_codewars_died(activity=activity, location=location, food_source=food_source), expected)
- @test.it("different data types")
- def test_different_data_types():
- test.assert_equals(where_were_you_when_codewars_died(activity=True, location=123, food_source=3.14), 'I was at 123 consuming 3.14 when True died.')
- test.assert_equals(where_were_you_when_codewars_died(activity=None, location=None, food_source=None), 'I was at None consuming None when None died.')
- @test.it("large number of random inputs")
- def test_large_number_of_random_inputs():
- for i in range(100):
- activity = ''.join(random.choices(string.ascii_letters + string.digits, k=random.randint(1, 10)))
- location = random.choice(locations)
- food_source = random.choice(['coffee', 'pizza', 'burger', 'soda', 'water'])
- expected = f"I was at {location} consuming {food_source} when {activity} died."
- test.assert_equals(where_were_you_when_codewars_died(activity=activity, location=location, food_source=food_source), expected)
- @test.it("None inputs")
- def test_none_inputs():
- test.assert_equals(where_were_you_when_codewars_died(activity=None, location=None, food_source=None), 'I was at None consuming None when None died.')
- @test.it("integer inputs")
- def test_integer_inputs():
- test.assert_equals(where_were_you_when_codewars_died(activity=123, location=456, food_source=789), 'I was at 456 consuming 789 when 123 died.')
- @test.it("float inputs")
- def test_float_inputs():
- test.assert_equals(where_were_you_when_codewars_died(activity=3.14, location=2.71, food_source=1.618), 'I was at 2.71 consuming 1.618 when 3.14 died.')
- @test.it("boolean inputs")
- def test_boolean_inputs():
- test.assert_equals(where_were_you_when_codewars_died(activity=True, location=False, food_source=True), 'I was at False consuming True when True died.')
- @test.it("random inputs with special characters")
- def test_random_inputs_with_special_characters():
- for i in range(100):
- activity = ''.join(random.choices(string.ascii_letters + string.digits + string.punctuation, k=random.randint(1, 10)))
- location = random.choice(locations)
- food_source = ''.join(random.choices(string.ascii_letters + string.digits + string.punctuation, k=random.randint(1, 10)))
- expected = f"I was at {location} consuming {food_source} when {activity} died."
- test.assert_equals(where_were_you_when_codewars_died(activity=activity, location=location, food_source=food_source), expected)
Now sorts intergers with length greater than 1 in the array.
def greatest(num): return int(''.join(sorted([str(y) for x in [[int(z) for z in str(n)] for n in num] for y in x], reverse=True)))
def greatest(lst):output = ''c = [0] * (max(lst) + 1)for i in lst:c[i] += 1s = []for i in reversed(range(len(c))):while c[i] != 0:c[i] -= 1s.append(i)for n in s:output += f'{n}'return int(output)- def greatest(num):
- return int(''.join(sorted([str(y) for x in [[int(z) for z in str(n)] for n in num] for y in x], reverse=True)))
import codewars_test as test from solution import greatest @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(greatest([1,2,3,5,5,3,9,0,3,4,3]), 95543333210) test.assert_equals(greatest([6,6,6,7,7,0]), 776660) test.assert_equals(greatest([1, 5, 4, 3, 9, 2, 0, 1, 6, 4, 9, 0, 7, 6, 1]), 997665443211100) test.assert_equals(greatest([100, 1, 111, 101001110, 111101001, 1001, 100100000111]), 11111111111111111111111000000000000000000) test.assert_equals(greatest([2, 3, 4, 5, 6, 7, 1776, 900009, 88]), 998877766543210000)
- import codewars_test as test
- from solution import greatest
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(greatest([1,2,3,5,5,3,9,0,3,4,3]), 95543333210)
- test.assert_equals(greatest([6,6,6,7,7,0]), 776660)
test.assert_equals(greatest([1, 5, 4, 3, 9, 2, 0, 1, 6, 4, 9, 0, 7, 6, 1]), 997665443211100)- test.assert_equals(greatest([1, 5, 4, 3, 9, 2, 0, 1, 6, 4, 9, 0, 7, 6, 1]), 997665443211100)
- test.assert_equals(greatest([100, 1, 111, 101001110, 111101001, 1001, 100100000111]), 11111111111111111111111000000000000000000)
- test.assert_equals(greatest([2, 3, 4, 5, 6, 7, 1776, 900009, 88]), 998877766543210000)