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
  • import java.util.Map;
    import java.util.HashMap;
    import java.util.Set;
    import java.util.HashSet;
    
    public class DependencyTracker {
      
      Map<String, Set<String>> theDependencies = new HashMap<>();
      
      public Set<String> getDependencies(String dependencyName) {
        Set<String> allDependencies = new HashSet<>();
        Set<String> directDependencies = getDirectDependencies(dependencyName);
        
        allDependencies.addAll(directDependencies);
        for (String subDependency : directDependencies) {
          allDependencies.addAll(getDependencies(subDependency));
        }
        return allDependencies;
      }
      
      public void registerDependency(String dependent, String dependedUpon) {
        Set<String> currentDependencies = getDirectDependencies(dependent);
        currentDependencies.add(dependedUpon);
        theDependencies.put(dependent, currentDependencies);
      }
      
      private Set<String> getDirectDependencies(String dependencyName) {
        return theDependencies.getOrDefault(dependencyName, new HashSet<>());
      }
    }
    • import java.util.Map;
    • import java.util.HashMap;
    • import java.util.Set;
    • import java.util.HashSet;
    • public class DependencyTracker {
    • Map<String, Set<String>> theDependencies = new HashMap<>();
    • public Set<String> getDependencies(String dependencyName) {
    • return getDirectDependencies(dependencyName);
    • Set<String> allDependencies = new HashSet<>();
    • Set<String> directDependencies = getDirectDependencies(dependencyName);
    • allDependencies.addAll(directDependencies);
    • for (String subDependency : directDependencies) {
    • allDependencies.addAll(getDependencies(subDependency));
    • }
    • return allDependencies;
    • }
    • // If "a" depends on "b," "a" is `dependent` and "b" is dependendUpon
    • public void registerDependency(String dependent, String dependedUpon) {
    • Set<String> currentDependencies = getDirectDependencies(dependent);
    • currentDependencies.add(dependedUpon);
    • theDependencies.put(dependent, currentDependencies);
    • }
    • private Set<String> getDirectDependencies(String dependencyName) {
    • return theDependencies.getOrDefault(dependencyName, new HashSet<>());
    • }
    • }
Code
Diff
  • fn find_the_magick_mushroom(forest: [[char;10];10]) -> Option<(usize, usize)> {
        for (i, row) in forest.iter().enumerate() {
            for (j, &plant) in row.iter().enumerate() {
                if plant == 'πŸ„' {
                    return Some((i, j))
                }
            }
        }
        None
    }
    • from typing import Any
    • def find_the_magick_mushroom(forest: list) -> Any:
    • for t, tree in enumerate(forest):
    • for m, mushroom in enumerate(tree):
    • if mushroom == 'πŸ„':
    • return t, m
    • return -1
    • fn find_the_magick_mushroom(forest: [[char;10];10]) -> Option<(usize, usize)> {
    • for (i, row) in forest.iter().enumerate() {
    • for (j, &plant) in row.iter().enumerate() {
    • if plant == 'πŸ„' {
    • return Some((i, j))
    • }
    • }
    • }
    • None
    • }
Code
Diff
  • public static class Kata
    {
        public static int SameCase(char a, char b)
        {
            if (!IsLetter(a) || !IsLetter(b))
            {
                return -1;
            }
    
            return IsUpper(a) == IsUpper(b) ? 1 : 0;
        }
    
        private static bool IsLetter(char c)
        {
            return (uint)(c - 'A') <= ('Z' - 'A') || (uint)(c - 'a') <= ('z' - 'a');
        }
    
        private static bool IsUpper(char c)
        {
            return (uint)(c - 'A') <= ('Z' - 'A');
        }
    }
    
    • public static class Kata
    • public static class Kata
    • {
    • public static int SameCase(char a, char b) =>
    • !char.IsLetter(a) || !char.IsLetter(b)
    • ? -1
    • : char.IsUpper(a) == char.IsUpper(b)
    • ? 1 : 0;
    • }
    • public static int SameCase(char a, char b)
    • {
    • if (!IsLetter(a) || !IsLetter(b))
    • {
    • return -1;
    • }
    • return IsUpper(a) == IsUpper(b) ? 1 : 0;
    • }
    • private static bool IsLetter(char c)
    • {
    • return (uint)(c - 'A') <= ('Z' - 'A') || (uint)(c - 'a') <= ('z' - 'a');
    • }
    • private static bool IsUpper(char c)
    • {
    • return (uint)(c - 'A') <= ('Z' - 'A');
    • }
    • }
Code
Diff
  • fn balanced_parenthesis(s: &str) -> String {   
        if nesting_level(s) == Some(0) {
            "Balanced"
        } else {
            "Unbalanced"
        }.into()
    }
    
    fn nesting_level(s: &str) -> Option<u32> {
        let mut level: u32 = 0;
        for c in s.chars() {
            level = if c == '(' {
                level + 1
            } else {
                level.checked_sub(1)?
            }
        }
        Some(level)
    }
    • fn balanced_parenthesis(s: &str) -> String {
    • let balanced = s
    • .chars()
    • .fold(
    • Some(0u32),
    • |acc, c|
    • match c {
    • '(' => acc.map(|n| n + 1),
    • ')' => acc.and_then(|n| n.checked_sub(1)),
    • _ => acc
    • }
    • ) == Some(0);
    • if balanced {
    • fn balanced_parenthesis(s: &str) -> String {
    • if nesting_level(s) == Some(0) {
    • "Balanced"
    • } else {
    • "Unbalanced"
    • }.into()
    • }
    • fn nesting_level(s: &str) -> Option<u32> {
    • let mut level: u32 = 0;
    • for c in s.chars() {
    • level = if c == '(' {
    • level + 1
    • } else {
    • level.checked_sub(1)?
    • }
    • }
    • Some(level)
    • }
Arrays

The function calendar_func() takes input of two people's schedules of the day in the form of range slices. (Eg. &[0900..1300, 1440..1540, 1820..1910] denoting the person is available from 9am-1pm, 2:40-3:40pm, 6:20-7:10pm) It finds the overlaps in their schedules and outputs at most three blocks of free time that they both have in common.

Assume given ranges are valid times (Ie. no 0990 or 3600).

Code
Diff
  • use std::ops::Range;
    
    fn calendar_func<Idx: Ord + Copy>(person_a: &[Range<Idx>], person_b: &[Range<Idx>]) -> Vec<Range<Idx>> {
        let mut iter_a = person_a.iter();
        let mut iter_b = person_b.iter();
        
        let mut overlaps = Vec::new();
        
        let mut item_a = iter_a.next();
        let mut item_b = iter_b.next();
        
        while let (Some(a), Some(b)) = (item_a, item_b) {
            match range_cmp(a, b) {
                RO::Less => item_a = iter_a.next(),
                RO::Greater => item_b = iter_b.next(),
                RO::Overlap(overlap) => {
                    overlaps.push(overlap);
                    if overlaps.len() == 3 {
                        break;
                    }
                    item_a = iter_a.next();
                    item_b = iter_b.next();
                }
            }
        }
        
        overlaps
    }
    
    fn range_cmp<Idx: Ord + Copy>(a: &Range<Idx>, b: &Range<Idx>) -> RangeOrdering<Idx> {
        if a.end <= b.start {
            RO::Less
        } else if b.end <= a.start {
            RO::Greater
        } else {
            RO::Overlap(
                (a.start.max(b.start))..(a.end.min(b.end))
            )
        }
    }
    
    use RangeOrdering as RO;
    enum RangeOrdering<Idx> {
        Less,
        Greater,
        Overlap(Range<Idx>)
    }
    • import java.util.*;
    • public class Main<Integer> implements CalendarFunc<Integer> {
    • ArrayList<Integer> PersonA = new ArrayList<Integer>();
    • ArrayList<Integer> PersonB = new ArrayList<Integer>();
    • ArrayList<Integer> BusyTime = new ArrayList<Integer>();
    • ArrayList<Integer> FreeTime = new ArrayList<Integer>();
    • public Main(ArrayList<Integer> PersonA, ArrayList<Integer> PersonB) {
    • this.PersonA = PersonA;
    • this.PersonB = PersonB;
    • }
    • @Override
    • public void removeSleepTime() {
    • // TODO removes sleeping blocks in FreeTime ArrayList
    • }
    • @Override
    • public void findUnion() {
    • // TODO return BusyTime, which is a union of all busy blocks
    • }
    • }
    • use std::ops::Range;
    • fn calendar_func<Idx: Ord + Copy>(person_a: &[Range<Idx>], person_b: &[Range<Idx>]) -> Vec<Range<Idx>> {
    • let mut iter_a = person_a.iter();
    • let mut iter_b = person_b.iter();
    • let mut overlaps = Vec::new();
    • let mut item_a = iter_a.next();
    • let mut item_b = iter_b.next();
    • while let (Some(a), Some(b)) = (item_a, item_b) {
    • match range_cmp(a, b) {
    • RO::Less => item_a = iter_a.next(),
    • RO::Greater => item_b = iter_b.next(),
    • RO::Overlap(overlap) => {
    • overlaps.push(overlap);
    • if overlaps.len() == 3 {
    • break;
    • }
    • item_a = iter_a.next();
    • item_b = iter_b.next();
    • }
    • }
    • }
    • overlaps
    • }
    • fn range_cmp<Idx: Ord + Copy>(a: &Range<Idx>, b: &Range<Idx>) -> RangeOrdering<Idx> {
    • if a.end <= b.start {
    • RO::Less
    • } else if b.end <= a.start {
    • RO::Greater
    • } else {
    • RO::Overlap(
    • (a.start.max(b.start))..(a.end.min(b.end))
    • )
    • }
    • }
    • use RangeOrdering as RO;
    • enum RangeOrdering<Idx> {
    • Less,
    • Greater,
    • Overlap(Range<Idx>)
    • }
Fundamentals
Strings

For provided string return the reversed string.

Examples:
1)
Input:

abc

Output:

cba

Input:

123

Output:

321

Input:

Hello World!

Output:

!dlroW olleH
Code
Diff
  • const reverseStr = s => [...s].reverse().join("")
    
    console.log(reverseStr("Lorem ipsum dolor sit amet!"))
    • const reverseStr = str => Array.from(str).reverse().join("")
    • const reverseStr = s => [...s].reverse().join("")
    • console.log(reverseStr('hello world'));
    • console.log(reverseStr("Lorem ipsum dolor sit amet!"))