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.
use rand::prelude::*; const SPECIAL_CHARACTERS: [char; 39] = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '.', ',', ':', ';', '<', '>', '?', '+', '-', '=', '/', '\\', '\'', '"', '{', '}', '[', ']', '_' ]; fn password_from_phrase(phrase: &str) -> String { let mut rng = rand::thread_rng(); let mut phrase: Vec<_> = phrase .chars() .filter(|c| c.is_ascii_alphabetic()) .map(|c| c.to_ascii_lowercase()) .collect(); phrase.shuffle(&mut rng); phrase.into_iter() .chain((0..10).map(|_| *SPECIAL_CHARACTERS.choose(&mut rng).unwrap())) .collect() }
import randomimport stringdef password_from_phrase(phrase):# Remove any non-alphabetic characters and convert to lowercasephrase = ''.join(filter(str.isalpha, phrase)).lower()# Shuffle the characters in the phrasephrase_chars = list(phrase)random.shuffle(phrase_chars)shuffled_phrase = ''.join(phrase_chars)# Generate a random string of numbers and symbolsnum_symbols = random.randint(6, 10)symbols = ''.join(random.choices(string.punctuation, k=num_symbols))# Combine the shuffled phrase and symbols to form the passwordpassword = shuffled_phrase[:6] + symbols + shuffled_phrase[6:]return password- use rand::prelude::*;
- const SPECIAL_CHARACTERS: [char; 39] = [
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
- '!', '@', '#', '$', '%', '^', '&', '*', '(', ')',
- '.', ',', ':', ';', '<', '>', '?', '+', '-', '=',
- '/', '\\', '\'', '"', '{', '}', '[', ']', '_'
- ];
- fn password_from_phrase(phrase: &str) -> String {
- let mut rng = rand::thread_rng();
- let mut phrase: Vec<_> = phrase
- .chars()
- .filter(|c| c.is_ascii_alphabetic())
- .map(|c| c.to_ascii_lowercase())
- .collect();
- phrase.shuffle(&mut rng);
- phrase.into_iter()
- .chain((0..10).map(|_| *SPECIAL_CHARACTERS.choose(&mut rng).unwrap()))
- .collect()
- }
#[test] fn test() { let phrase = "The quick brown fox jumps over the lazy dog."; let password = password_from_phrase(phrase); let (scrambled, characters) = password.split_at(password.len() - 10); assert!(scrambled.chars().all(|c| c.is_ascii_alphabetic())); assert!(scrambled.chars().all(|c| c.is_ascii_lowercase())); assert!(('a'..='z').all(|c| scrambled.contains(c))); assert!(characters.chars().all(|c| !c.is_ascii_alphabetic())); println!("{password}"); }
# Example usage:phrase = "The quick brown fox"password = password_from_phrase(phrase)print("Password:", password)- #[test]
- fn test() {
- let phrase = "The quick brown fox jumps over the lazy dog.";
- let password = password_from_phrase(phrase);
- let (scrambled, characters) = password.split_at(password.len() - 10);
- assert!(scrambled.chars().all(|c| c.is_ascii_alphabetic()));
- assert!(scrambled.chars().all(|c| c.is_ascii_lowercase()));
- assert!(('a'..='z').all(|c| scrambled.contains(c)));
- assert!(characters.chars().all(|c| !c.is_ascii_alphabetic()));
- println!("{password}");
- }
Write a function that returns "Hello World baby" if its true and "No World" if its false
/*def hello_world(world): if world == True: return "Hello World baby" elif world == False: return "No World"*/ // helloWorld = (world) => world == true ? 'Hello World baby': 'No World'; const helloWorld=(world)=>world ?`Hello World baby`:`No World`;
- /*def hello_world(world):
- if world == True:
- return "Hello World baby"
- elif world == False:
- return "No World"*/
- // helloWorld = (world) => world == true ? 'Hello World baby': 'No World';
const helloWorld=(world)=>world==true?`Hello World baby`:`No World`;- const helloWorld=(world)=>world ?`Hello World baby`:`No World`;
fn vector_multiply(input: &[i32]) -> i32 { input.iter().product() }
fn vector_multiply(input: Vec<i32>) -> i32 {input.iter().product()- fn vector_multiply(input: &[i32]) -> i32 {
- input.iter().product()
- }
#[cfg(test)] mod tests { use super::*; #[test] fn test_basic() { assert_eq!(vector_multiply(&[2]), 2); assert_eq!(vector_multiply(&[5]), 5); assert_eq!(vector_multiply(&[2, 5]), 10); assert_eq!(vector_multiply(&[2, 5, 5, 2]), 100); assert_eq!(vector_multiply(&[30, 30, 30]), 27000); assert_eq!(vector_multiply(&[1, 1, 1, 1, 2, 2, 2, 2]), 16); } #[test] fn test_with_negatives() { assert_eq!(vector_multiply(&[200, -1000]), -200000); assert_eq!(vector_multiply(&[-1, 5, 10, 50]), -2500); assert_eq!(vector_multiply(&[-598, 2]), -1196); assert_eq!(vector_multiply(&[-1000, 500, -2]), 1000000); } #[test] fn test_zero_result() { assert_eq!(vector_multiply(&[0]), 0); assert_eq!(vector_multiply(&[1, 5, 2, -15, 105021, 3, 0, 15, 2]), 0); assert_eq!(vector_multiply(&[0, 0, 0, 0]), 0); } #[test] fn test_empty() { assert_eq!(vector_multiply(&[]), 1); } }
// Add your tests here.// See https://doc.rust-lang.org/stable/rust-by-example/testing/unit_testing.html- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
fn test_1() {assert_eq!(vector_multiply(vec![2, 5]), 10);}#[test]fn test_2() {assert_eq!(vector_multiply(vec![2, 5, 5, 2]), 100);}#[test]fn test_3() {assert_eq!(vector_multiply(vec![200, -1000]), -200000);}#[test]fn test_4() {assert_eq!(vector_multiply(vec![0]), 0);}#[test]fn test_5() {assert_eq!(vector_multiply(vec![1, 1, 1, 1, 2, 2, 2, 2]), 16);}#[test]fn test_6() {assert_eq!(vector_multiply(vec![30, 30, 30]), 27000);}#[test]fn test_7() {assert_eq!(vector_multiply(vec![-1, 5, 10, 50]), -2500);}#[test]fn test_8() {assert_eq!(vector_multiply(vec![-598, 2]), -1196);- fn test_basic() {
- assert_eq!(vector_multiply(&[2]), 2);
- assert_eq!(vector_multiply(&[5]), 5);
- assert_eq!(vector_multiply(&[2, 5]), 10);
- assert_eq!(vector_multiply(&[2, 5, 5, 2]), 100);
- assert_eq!(vector_multiply(&[30, 30, 30]), 27000);
- assert_eq!(vector_multiply(&[1, 1, 1, 1, 2, 2, 2, 2]), 16);
- }
- #[test]
- fn test_with_negatives() {
- assert_eq!(vector_multiply(&[200, -1000]), -200000);
- assert_eq!(vector_multiply(&[-1, 5, 10, 50]), -2500);
- assert_eq!(vector_multiply(&[-598, 2]), -1196);
- assert_eq!(vector_multiply(&[-1000, 500, -2]), 1000000);
- }
- #[test]
fn test_9() {assert_eq!(vector_multiply(vec![]), 1);- fn test_zero_result() {
- assert_eq!(vector_multiply(&[0]), 0);
- assert_eq!(vector_multiply(&[1, 5, 2, -15, 105021, 3, 0, 15, 2]), 0);
- assert_eq!(vector_multiply(&[0, 0, 0, 0]), 0);
- }
- #[test]
fn test_10() {assert_eq!(vector_multiply(vec![-1000, 500, -2]), 1000000);- fn test_empty() {
- assert_eq!(vector_multiply(&[]), 1);
- }
- }
fn encode(phrase: &str, key: &str) -> String { apply_modifier(phrase, key, |(character, offset)| character + offset) } fn decode(phrase: &str, key: &str) -> String { apply_modifier(phrase, key, |(character, offset)| character - offset) } fn apply_modifier(phrase: &str, key: &str, f: fn((u8, u8)) -> u8) -> String { phrase.chars() .map(normalize) // 'A'..='Z' and 'a'..='z' to 0..26 and 26..52 .map(|n| n + 52) // 0..52 to 52..104 so that subtraction doesn't overflow .zip(offsets(key).into_iter().cycle()) // generate and cycle over the offsets .map(|n| f(n) % 52) // apply encoding/decoding and remainder it back to 0..52 .map(denormalize) // 0..26 and 26..52 to 'A'..='Z' and 'a'..='z' .collect() } fn normalize(character: char) -> u8 { character as u8 - if character.is_ascii_uppercase() { b'A' } else { b'a' - 26 } } fn denormalize(normalized: u8) -> char { (normalized + if normalized < 26 { b'A' } else { b'a' - 26 }) as char } fn offsets(key: &str) -> Vec<u8> { let key_len = key.len() as u8; let offsets: Vec<_> = key.chars().map(move |ch| ch as u8 % 10 + key_len).collect(); if offsets.is_empty() { vec![0] } else { offsets } }
public class Kata {public static String encode(String phrase, String key) {return "";}public static String decode(String phrase, String key) {return "";}- fn encode(phrase: &str, key: &str) -> String {
- apply_modifier(phrase, key, |(character, offset)| character + offset)
- }
- fn decode(phrase: &str, key: &str) -> String {
- apply_modifier(phrase, key, |(character, offset)| character - offset)
- }
- fn apply_modifier(phrase: &str, key: &str, f: fn((u8, u8)) -> u8) -> String {
- phrase.chars()
- .map(normalize) // 'A'..='Z' and 'a'..='z' to 0..26 and 26..52
- .map(|n| n + 52) // 0..52 to 52..104 so that subtraction doesn't overflow
- .zip(offsets(key).into_iter().cycle()) // generate and cycle over the offsets
- .map(|n| f(n) % 52) // apply encoding/decoding and remainder it back to 0..52
- .map(denormalize) // 0..26 and 26..52 to 'A'..='Z' and 'a'..='z'
- .collect()
- }
- fn normalize(character: char) -> u8 {
- character as u8 - if character.is_ascii_uppercase() { b'A' } else { b'a' - 26 }
- }
- fn denormalize(normalized: u8) -> char {
- (normalized + if normalized < 26 { b'A' } else { b'a' - 26 }) as char
- }
- fn offsets(key: &str) -> Vec<u8> {
- let key_len = key.len() as u8;
- let offsets: Vec<_> = key.chars().map(move |ch| ch as u8 % 10 + key_len).collect();
- if offsets.is_empty() {
- vec![0]
- } else {
- offsets
- }
- }
#[cfg(test)] mod tests { use super::*; #[test] fn basic_tests() { assert_eq!(encode("abcde", "abcde"), "moqik"); assert_eq!(decode("moqik", "abcde"), "abcde"); assert_eq!(encode("ABCDE", "ABCDE"), "KMOQS"); assert_eq!(decode("KMOQS", "ABCDE"), "ABCDE"); assert_eq!(encode("DEARGOD", "FGH"), "GIFUKTG"); assert_eq!(decode("GIFUKTG", "FGH"), "DEARGOD"); assert_eq!(encode("deargod", "fgh"), "ikhwmvi"); assert_eq!(decode("ikhwmvi", "fgh"), "deargod"); assert_eq!(encode("ALaBamA", "hoME"), "IQlOirL"); assert_eq!(decode("IQlOirL", "hoME"), "ALaBamA"); } #[test] fn special_cases() { assert_eq!(encode("", ""), ""); assert_eq!(encode("TernaryLove", ""), "TernaryLove"); assert_eq!(encode("", "abcde"), ""); } #[test] fn simple_overflow() { assert_eq!(encode("turbo", "TUXON"), "CEEpB"); assert_eq!(decode("CEEpB", "TUXON"), "turbo"); assert_eq!(encode("helloworld", "afgh"), "skstzCvzwj"); assert_eq!(decode("skstzCvzwj", "afgh"), "helloworld"); assert_eq!(encode("xyz", "ijklmn"), "IKM"); assert_eq!(decode("IKM", "ijklmn"), "xyz"); assert_eq!(encode("gOdMoRNinG", "uSA"), "qUlWuZXovQ"); assert_eq!(decode("qUlWuZXovQ", "uSA"), "gOdMoRNinG"); assert_eq!(encode("wElovETerNaRyExpsaNdIj", "dAvID"), "BOywIJdrzafbLMKuCnVqNt"); assert_eq!(decode("BOywIJdrzafbLMKuCnVqNt", "dAvID"), "wElovETerNaRyExpsaNdIj"); } #[test] fn intermediate_overflow() { assert_eq!(encode("hOmEsWeEtHoMe", "nOtSoSwEeT"), "rhCRDjxXEVyfu"); assert_eq!(decode("rhCRDjxXEVyfu", "nOtSoSwEeT"), "hOmEsWeEtHoMe"); assert_eq!(encode("WonDErWaLl", "oASiS"), "cyvNMxgiVt"); assert_eq!(decode("cyvNMxgiVt", "oASiS"), "WonDErWaLl"); assert_eq!(encode("Zumbido", "wow"), "lyynmpA"); assert_eq!(decode("lyynmpA", "wow"), "Zumbido"); } }
import static org.junit.jupiter.api.Assertions.assertEquals;import org.junit.jupiter.api.RepeatedTest;import org.junit.jupiter.api.Test;import java.util.Random;import java.nio.charset.Charset;class SolutionTest {@Testvoid basicTest() {assertEquals("S", Kata.encode("DEARGOD", "afgh"));assertEquals("DEARGOD", Kata.decode("", "afgh"));assertEquals("", Kata.encode("", ""));assertEquals("", Kata.decode("", ""));}@Testvoid fullTest() {assertEquals("skstzDvzwj", Kata.encode("helloworld", "afgh"));assertEquals("helloworld", Kata.decode("skstzDvzwj", "afgh"));}private String encode(String phrase, String key) {return "";}private String decode(String phrase, String key) {return "";}String generateString() {Random random = new Random();byte[] buffer = new byte[random.nextInt(1501)];random.nextBytes(buffer);return new String(buffer, Charset.forName("UTF-8"));}String generatePhrase() {return generateString();}String generateKey() {return generateString();}@RepeatedTest(100)void randomTest() {String phrase = generatePhrase();String key = generateKey();assertEquals(Kata.encode(phrase, key), encode(phrase, key));assertEquals(Kata.decode(phrase, key), decode(phrase, key));}}- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
- fn basic_tests() {
- assert_eq!(encode("abcde", "abcde"), "moqik");
- assert_eq!(decode("moqik", "abcde"), "abcde");
- assert_eq!(encode("ABCDE", "ABCDE"), "KMOQS");
- assert_eq!(decode("KMOQS", "ABCDE"), "ABCDE");
- assert_eq!(encode("DEARGOD", "FGH"), "GIFUKTG");
- assert_eq!(decode("GIFUKTG", "FGH"), "DEARGOD");
- assert_eq!(encode("deargod", "fgh"), "ikhwmvi");
- assert_eq!(decode("ikhwmvi", "fgh"), "deargod");
- assert_eq!(encode("ALaBamA", "hoME"), "IQlOirL");
- assert_eq!(decode("IQlOirL", "hoME"), "ALaBamA");
- }
- #[test]
- fn special_cases() {
- assert_eq!(encode("", ""), "");
- assert_eq!(encode("TernaryLove", ""), "TernaryLove");
- assert_eq!(encode("", "abcde"), "");
- }
- #[test]
- fn simple_overflow() {
- assert_eq!(encode("turbo", "TUXON"), "CEEpB");
- assert_eq!(decode("CEEpB", "TUXON"), "turbo");
- assert_eq!(encode("helloworld", "afgh"), "skstzCvzwj");
- assert_eq!(decode("skstzCvzwj", "afgh"), "helloworld");
- assert_eq!(encode("xyz", "ijklmn"), "IKM");
- assert_eq!(decode("IKM", "ijklmn"), "xyz");
- assert_eq!(encode("gOdMoRNinG", "uSA"), "qUlWuZXovQ");
- assert_eq!(decode("qUlWuZXovQ", "uSA"), "gOdMoRNinG");
- assert_eq!(encode("wElovETerNaRyExpsaNdIj", "dAvID"), "BOywIJdrzafbLMKuCnVqNt");
- assert_eq!(decode("BOywIJdrzafbLMKuCnVqNt", "dAvID"), "wElovETerNaRyExpsaNdIj");
- }
- #[test]
- fn intermediate_overflow() {
- assert_eq!(encode("hOmEsWeEtHoMe", "nOtSoSwEeT"), "rhCRDjxXEVyfu");
- assert_eq!(decode("rhCRDjxXEVyfu", "nOtSoSwEeT"), "hOmEsWeEtHoMe");
- assert_eq!(encode("WonDErWaLl", "oASiS"), "cyvNMxgiVt");
- assert_eq!(decode("cyvNMxgiVt", "oASiS"), "WonDErWaLl");
- assert_eq!(encode("Zumbido", "wow"), "lyynmpA");
- assert_eq!(decode("lyynmpA", "wow"), "Zumbido");
- }
- }