Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

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.

Ad
Ad
Code
Diff
  • 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 random
    • import string
    • def password_from_phrase(phrase):
    • # Remove any non-alphabetic characters and convert to lowercase
    • phrase = ''.join(filter(str.isalpha, phrase)).lower()
    • # Shuffle the characters in the phrase
    • phrase_chars = list(phrase)
    • random.shuffle(phrase_chars)
    • shuffled_phrase = ''.join(phrase_chars)
    • # Generate a random string of numbers and symbols
    • num_symbols = random.randint(6, 10)
    • symbols = ''.join(random.choices(string.punctuation, k=num_symbols))
    • # Combine the shuffled phrase and symbols to form the password
    • password = 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()
    • }

Write a function that returns "Hello World baby" if its true and "No World" if its false

Code
Diff
  • /*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`;
Code
Diff
  • 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()
    • }
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
Code
Diff
  • 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
    • }
    • }
Code
Diff
  • def multiply(a,b):
        result = a*b
        return result
    print(multiply(5,10))
    
    • def multiply(a,b):
    • result = a*b
    • return result
    • multiply (5,10)
    • print(multiply(5,10))
Code
Diff
  • fn estimate_height(sex: Sex, father_height: f64, mother_height: f64) -> f64 {
        let offset = match sex {
            Sex::Male => 0.5,
            Sex::Female => -0.5
        };
        
        (father_height + mother_height) / 2.0 + offset
    }
    
    enum Sex {
        Male,
        Female
    }
        
    • def est_height(gender, dad_height, mom_height):
    • if gender=="boy":
    • return ((dad_height + mom_height)/2)+0.5
    • else:
    • return ((dad_height + mom_height)/2)-0.5
    • fn estimate_height(sex: Sex, father_height: f64, mother_height: f64) -> f64 {
    • let offset = match sex {
    • Sex::Male => 0.5,
    • Sex::Female => -0.5
    • };
    • (father_height + mother_height) / 2.0 + offset
    • }
    • enum Sex {
    • Male,
    • Female
    • }
Fundamentals
Functional Programming

a haskell code

Code
Diff
  • module NumberPrint where
    
    import Control.Monad         (when)
    import Data.IORef            (newIORef)
    import Data.StateVar         (($=), ($~), get)
    import Foreign.Ptr           (Ptr (..))
    import Foreign.Marshal.Alloc (alloca)
    import System.IO.Unsafe      (unsafePerformIO)
    
    whileM :: Monad m => m Bool -> m () -> m ()
    whileM mb a = do
      b <- mb
      when b $ a >> whileM mb a
    
    numberprint :: Int -> Integer
    numberprint n = read . unsafePerformIO $ do 
      alloca $ \(i :: Ptr Int)-> do
        i $= 1
        s <- newIORef ""
        whileM ((<n) <$> get i) $ do
          c <- get i
          s $~ (show c++)
          i $~ (1+)
        whileM ((>= 1) <$> get i) $ do
          c <- get i
          s $~ (show c++)
          i $~ (-1+)
        get s
     
    • module NumberPrint where
    • import Control.Monad (when)
    • import Data.IORef (newIORef)
    • import Data.StateVar (($=), ($~), get)
    • import Foreign.Ptr (Ptr (..))
    • import Foreign.Marshal.Alloc (alloca)
    • import System.IO.Unsafe (unsafePerformIO)
    • whileM :: Monad m => m Bool -> m () -> m ()
    • whileM mb a = do
    • b <- mb
    • when b $ a >> whileM mb a
    • numberprint :: Int -> Integer
    • numberprint = read . (>>= id) . ((++) <*> (reverse . init)) . (\x -> show <$> [1..x])
    • numberprint n = read . unsafePerformIO $ do
    • alloca $ \(i :: Ptr Int)-> do
    • i $= 1
    • s <- newIORef ""
    • whileM ((<n) <$> get i) $ do
    • c <- get i
    • s $~ (show c++)
    • i $~ (1+)
    • whileM ((>= 1) <$> get i) $ do
    • c <- get i
    • s $~ (show c++)
    • i $~ (-1+)
    • get s