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
Code
Diff
  • def one_away(a, b)
      (a.chars - b.chars).count <= 1 ? true : false
    end
    • def one_away(a,b)
    • (a.split('')-b.split('')).count <= 1 ? true : false
    • def one_away(a, b)
    • (a.chars - b.chars).count <= 1 ? true : false
    • end
Code
Diff
  • def f():
        a = [1,2,3,4,5]
        b = [4,5,6,7,8]
    
        
        
        return [x for x in a if x not in b]
    • def f():
    • a = [1,2,3,4,5]
    • b = [4,5,6,7,8]
    • c = []
    • for i in a:
    • if i not in b:
    • c.append(i)
    • return c
    • return [x for x in a if x not in b]

Using already defined function

Code
Diff
  • from calendar import isleap
    is_leap = lambda x: isleap(x)
    • is_leap = lambda n:(n%400==0 or (n%4==0 and n%100!=0))
    • from calendar import isleap
    • is_leap = lambda x: isleap(x)
Code
Diff
  • export function fizzBuzz(i: number): string {
      return (['Fizz'][i%3] || '') + (['Buzz'][i%5] || '') || i.toString()
    }
    • export function fizzBuzz(input: number): string {
    • const output: string = `${input % 3 === 0 ? "Fizz" : ""}${input % 5 === 0 ? "Buzz" : ""}`;
    • return output.length > 0 ? output : input.toString(10);
    • export function fizzBuzz(i: number): string {
    • return (['Fizz'][i%3] || '') + (['Buzz'][i%5] || '') || i.toString()
    • }
Code
Diff
  • const number = (n)=>{n%2===0?console.log("The number is even."):console.log("The number is odd.");}
    
    
    • const number = prompt("Enter a number: ");
    • const number = (n)=>{n%2===0?console.log("The number is even."):console.log("The number is odd.");}
    • if(number % 2 == 0){
    • console.log("The number is even.");
    • }else{
    • console.log("The number is odd.");
    • }
Algorithms
Code
Diff
  • fn digits(mut n: u64) -> usize {
        std::iter::from_fn(|| { n /= 10; Some(n) })
            .take_while(|n| n > &0)
            .count() + 1
    }
    • fn digits(mut n: u64) -> usize {
    • std::iter::from_fn(|| { n = n / 10; Some(n) }).
    • take_while(|n| *n > 0)
    • std::iter::from_fn(|| { n /= 10; Some(n) })
    • .take_while(|n| n > &0)
    • .count() + 1
    • }
Web Scraping
Code
Diff
  • import requests
    from requests.models import Response
    
    def unpack_dict(some_dict:dict, sep='') -> str:
        longest_key: int = len(max(some_dict, key=len))+1
        result: str = str()
        for key, value in some_dict.items():
            result += f'\n{sep}{key}:'
            result += ' '*(longest_key-len(key))
            if type(value) is dict:
                result += unpack_dict(value, sep=sep+'\t')
            elif type(value) is list:
                result += value[0]
            else:
                result += str(value) if bool(value) is True else 'None'
        return result
    
    def get_codewars_stats(username: str) -> str:
        API: str = f'https://codewars.com/api/v1/users/{username}'
        response: Response = requests.get(API, headers = dict(ContentType='application/json'))
        
        if not response.ok:
            return 'Something went wrong, enter a valid Codewars username.'
    
        response_json: dict = response.json()
        return unpack_dict(response_json)
    
    • from bs4 import BeautifulSoup
    • import requests
    • from requests.models import Response
    • def unpack_dict(some_dict:dict, sep='') -> str:
    • longest_key: int = len(max(some_dict, key=len))+1
    • result: str = str()
    • for key, value in some_dict.items():
    • result += f'\n{sep}{key}:'
    • result += ' '*(longest_key-len(key))
    • if type(value) is dict:
    • result += unpack_dict(value, sep=sep+'\t')
    • elif type(value) is list:
    • result += value[0]
    • else:
    • result += str(value) if bool(value) is True else 'None'
    • return result
    • def get_codewars_stats(username):
    • """Scraps, and retrieves Codewars stats of given username."""
    • source = requests.get(f'https://www.codewars.com/users/{username}')
    • # Verify request status:
    • if source.status_code == 404:
    • def get_codewars_stats(username: str) -> str:
    • API: str = f'https://codewars.com/api/v1/users/{username}'
    • response: Response = requests.get(API, headers = dict(ContentType='application/json'))
    • if not response.ok:
    • return 'Something went wrong, enter a valid Codewars username.'
    • else:
    • soup = BeautifulSoup(source.text, 'html.parser')
    • stat_info = soup.findAll('div', class_='stat')
    • name, member, rank, honor, position, percentage, katas = (stat_info[0],
    • stat_info[3],
    • stat_info[9],
    • stat_info[10],
    • stat_info[11],
    • stat_info[12],
    • stat_info[13])
    • return f"{username}'s Codewars stats:\n\t{member.text}\n\t{rank.text}\n\t{honor.text}\n\t{position.text}\n\t{percentage.text}\n\t{katas.text}"
    • response_json: dict = response.json()
    • return unpack_dict(response_json)
Code
Diff
  • const greetings = () => 'My name is: seraph776'
    • function greetings(){
    • return 'My name is: seraph776'
    • }
    • const greetings = () => 'My name is: seraph776'

filterfalse can be used to generate an iterator.
filter might have been used instead but it wouldn't be as clean.

Code
Diff
  • from itertools import filterfalse
    
    def find_multiples_of_4_and_6(n):
        return filterfalse(lambda x: x%4 and x%6, range(n))
    • from itertools import filterfalse
    • def find_multiples_of_4_and_6(n):
    • for i in range(n):
    • if not (i % 4 and i % 6):
    • yield i
    • return filterfalse(lambda x: x%4 and x%6, range(n))