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.
def cheat_code(func): def wrapper(db, user, password): db[user] = password return func(db, user, password) return wrapper def login_kumite(user_db, username, password): if username in user_db and user_db[username] == password: print("Login successful!") return True else: print("Invalid username or password.") return False
- def cheat_code(func):
pass- def wrapper(db, user, password):
- db[user] = password
- return func(db, user, password)
- return wrapper
- def login_kumite(user_db, username, password):
pass- if username in user_db and user_db[username] == password:
- print("Login successful!")
- return True
- else:
- print("Invalid username or password.")
- return False
import codewars_test as test from solution import cheat_code, login_kumite # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case: True") def test_case(): db_samples = ( { 'user1': 'password1', 'user2': 'password2', 'admin': 'admin123', }, { 'user1': 'password1', 'user2': 'password2', 'admin': 'admin123', }, { 'user1': 'password1', 'user2': 'password2', 'admin': 'admin123', }) user_pass_samples = (('user1', 'password1'),('user2', 'password2'), ('admin', 'admin123') ) for db, credentials in zip(db_samples, user_pass_samples): username = credentials[0] password = credentials[1] test.assert_equals(login_kumite(db, username, password), True) @test.it("test case: False") def test_case(): db_samples = ( { 'user1': 'password1', 'user2': 'password2', 'admin': 'admin123', }, { 'user1': 'password1', 'user2': 'password2', 'admin': 'admin123', }, { 'user1': 'password1', 'user2': 'password2', 'admin': 'admin123', }) user_pass_samples = (('jacktheripper', 'butterknife'),('C3realKill3r', 'cornflakes'), ('admin', 'godIAM') ) for db, credentials in zip(db_samples, user_pass_samples): username = credentials[0] password = credentials[1] test.assert_equals(login_kumite(db, username, password), False) @test.it("test case: Cheat Code!") def test_case(): @cheat_code def login_kumite(user_db, username, password): if username in user_db and user_db[username] == password: print("Login successful!") return True else: print("Invalid username or password.") return False db_samples = ( { 'user1': 'password1', 'user2': 'password2', 'admin': 'admin123', }, { 'user1': 'password1', 'user2': 'password2', 'admin': 'admin123', }, { 'user1': 'password1', 'user2': 'password2', 'admin': 'admin123', }, { }) user_pass_samples = (('jacktheripper', 'butterknife'),('C3realKill3r', 'cornflakes'), ('admin', 'godIAM'), ('seraph', 'magick') ) for db, credentials in zip(db_samples, user_pass_samples): username = credentials[0] password = credentials[1] test.assert_equals(login_kumite(db, username, password), True)
- import codewars_test as test
- from solution import cheat_code, login_kumite
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case: True")
- def test_case():
- db_samples = (
- {
- 'user1': 'password1',
- 'user2': 'password2',
- 'admin': 'admin123',
- },
- {
- 'user1': 'password1',
- 'user2': 'password2',
- 'admin': 'admin123',
- },
- {
- 'user1': 'password1',
- 'user2': 'password2',
- 'admin': 'admin123',
- })
- user_pass_samples = (('user1', 'password1'),('user2', 'password2'), ('admin', 'admin123') )
- for db, credentials in zip(db_samples, user_pass_samples):
- username = credentials[0]
- password = credentials[1]
- test.assert_equals(login_kumite(db, username, password), True)
- @test.it("test case: False")
- def test_case():
- db_samples = (
- {
- 'user1': 'password1',
- 'user2': 'password2',
- 'admin': 'admin123',
- },
- {
- 'user1': 'password1',
- 'user2': 'password2',
- 'admin': 'admin123',
- },
- {
- 'user1': 'password1',
- 'user2': 'password2',
- 'admin': 'admin123',
- })
- user_pass_samples = (('jacktheripper', 'butterknife'),('C3realKill3r', 'cornflakes'), ('admin', 'godIAM') )
- for db, credentials in zip(db_samples, user_pass_samples):
- username = credentials[0]
- password = credentials[1]
- test.assert_equals(login_kumite(db, username, password), False)
- @test.it("test case: Cheat Code!")
- def test_case():
- @cheat_code
- def login_kumite(user_db, username, password):
- if username in user_db and user_db[username] == password:
- print("Login successful!")
- return True
- else:
- print("Invalid username or password.")
- return False
- db_samples = (
- {
- 'user1': 'password1',
- 'user2': 'password2',
- 'admin': 'admin123',
- },
- {
- 'user1': 'password1',
- 'user2': 'password2',
- 'admin': 'admin123',
- },
- {
- 'user1': 'password1',
- 'user2': 'password2',
- 'admin': 'admin123',
- },
- {
- })
- user_pass_samples = (('jacktheripper', 'butterknife'),('C3realKill3r', 'cornflakes'), ('admin', 'godIAM'), ('seraph', 'magick') )
- for db, credentials in zip(db_samples, user_pass_samples):
- username = credentials[0]
- password = credentials[1]
test.assert_equals(login_kumite(db, username, password), True)- test.assert_equals(login_kumite(db, username, password), True)
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 hi_guys(): test.assert_equals(disemvowel("HI GUYS"), "H GYS") test.assert_equals(disemvowel("AEIOU"), "") test.assert_equals(disemvowel("Shrek is an orge"), "Shrk s n rg") test.assert_equals(disemvowel("Seraph is coding in Python"), "Srph s cdng n Pythn") test.assert_equals(disemvowel("C0ffee makes Code!"), "C0ff mks Cd!")
- 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 hi_guys():
- test.assert_equals(disemvowel("HI GUYS"), "H GYS")
- test.assert_equals(disemvowel("AEIOU"), "")
- test.assert_equals(disemvowel("Shrek is an orge"), "Shrk s n rg")
- test.assert_equals(disemvowel("Seraph is coding in Python"), "Srph s cdng n Pythn")
- test.assert_equals(disemvowel("C0ffee makes Code!"), "C0ff mks Cd!")
fn find_the_longest_word(sentence: &str) -> Option<&str> { let words: Vec<&str> = sentence.split_whitespace().collect(); let max_len = words.iter().map(|word| word.len()).max()?; let longest_words: Vec<&str> = words.into_iter().filter(|&word| word.len() == max_len).collect(); if longest_words.len() > 1 { None } else { longest_words.get(0).copied() } }
- fn find_the_longest_word(sentence: &str) -> Option<&str> {
let max_len = sentence.split_whitespace().map(str::len).max()?;let mut max_words = sentence.split_whitespace().filter(|word| word.len() == max_len);let first_max = max_words.next();let second_max = max_words.next();if second_max.is_some() {return None;}first_max}- let words: Vec<&str> = sentence.split_whitespace().collect();
- let max_len = words.iter().map(|word| word.len()).max()?;
- let longest_words: Vec<&str> = words.into_iter().filter(|&word| word.len() == max_len).collect();
- if longest_words.len() > 1 {
- None
- } else {
- longest_words.get(0).copied()
- }
- }
makeMove =(c,s)=> [...s].reduce((r,d)=>[r[0]+(d=='r')-(d=='l'),r[1]+(d=='t')-(d=='b')],c)
function makeMove(init, sequence) {let coords = [...init];for(const dir of sequence) {coords[0] += (dir == 'r') - (dir == 'l');coords[1] += (dir == 't') - (dir == 'b');}return coords;}- makeMove
- =(c,s)=>
- [...s].reduce((r,d)=>[r[0]+(d=='r')-(d=='l'),r[1]+(d=='t')-(d=='b')],c)
1 Million entries is not that large so we can still solve it naively.
module ExampleSolution let findUniqueNumber arr = arr |> Seq.countBy id |> Seq.find (fun (_, count) -> count = 1) |> fst
- module ExampleSolution
let findUniqueNumber array =() // your code goes here- let findUniqueNumber arr =
- arr
- |> Seq.countBy id
- |> Seq.find (fun (_, count) -> count = 1)
- |> fst
in one line
def repair(cur: list, pre: list):cur[[i.count("?") > 0 for i in cur].index(True)] = pre[[pre.index(i) for i in pre if [(o, i) for o, i in enumerate([*i]) if (o, i) in list(filter(lambda x: x[1] != '', enumerate(map(lambda x: x if x != "?" else "", [*cur[[i.count("?") > 0 for i in cur].index(True)]]))))] == list(filter(lambda x: x[1] != '', enumerate(map(lambda x: x if x != "?" else "", [*cur[[i.count("?") > 0 for i in cur].index(True)]])))) and len(i) == len(cur[[i.count("?") > 0 for i in cur].index(True)])][0]];return cur
def repair(cur: list, pre: list):broken_index = [i.count("?") > 0 for i in cur].index(True)known_part = list(filter(lambda x: x[1] != '', enumerate(map(lambda x: x if x != "?" else "", [*cur[broken_index]]))))matching_pre_index = [pre.index(i) for i in pre if [(o, i) for o, i in enumerate([*i]) if (o, i) in known_part] == known_part and len(i) == len(cur[broken_index])][0]cur[broken_index] = pre[matching_pre_index]return cur- def repair(cur: list, pre: list):cur[[i.count("?") > 0 for i in cur].index(True)] = pre[[pre.index(i) for i in pre if [(o, i) for o, i in enumerate([*i]) if (o, i) in list(filter(lambda x: x[1] != '', enumerate(map(lambda x: x if x != "?" else "", [*cur[[i.count("?") > 0 for i in cur].index(True)]]))))] == list(filter(lambda x: x[1] != '', enumerate(map(lambda x: x if x != "?" else "", [*cur[[i.count("?") > 0 for i in cur].index(True)]])))) and len(i) == len(cur[[i.count("?") > 0 for i in cur].index(True)])][0]];return cur