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

If it does not work, just say :).

template<typename T>
T add(T a, T b){
	return a-(-b);
}
bool Or(bool a, bool b){
	if(!a){
		if(!b){
			return false;
		}
	}
	return true;
}

bool Xor(bool a, bool b){
	return a != b;	
}

bool And(bool a, bool b){
	if(a){
		if(b){
			return true;
		}
	}
	return false;
}

Parses an expression.

def parse(expr): #The main parser
  ps = 0 #Number of open parentheses
  cval = 0 #Current value
  op = "+" #Current operation
  accum = "" #Accumulating value
  for i in range(len(expr)):
    c = expr[i]
    if c in ["+","-"] and not ps: #Operation not inside parens
      if op=="+": #Addition
        cval+=parse_fact(accum)
      else: #Subtraction
        cval-=parse_fact(accum)
      accum = "" #Reset the value
      op = c #New operation once that was calculated
    else:
      if c=="(": ps+=1 #Open paren
      if c==")": ps-=1 #Close paren
      accum+=c #Add a character to accumulating value
  if op=="+": #Do the operation one more time
    cval+=parse_fact(accum)
  else:
    cval-=parse_fact(accum)
  return cval
def parse_fact(term):
  ps = 0
  cval = 1
  op = "*"
  accum = ""
  for i in range(len(term)):
    c = term[i]
    if c in ["*","/"] and not ps:
      if op=="*":
        cval*=parse_val(accum)
      else:
        cval/=parse_val(accum)
      accum = ""
      op = c
    else:
      if c=="(": ps+=1
      if c==")": ps-=1
      accum+=c
  if op=="*":
    cval*=parse_val(accum)
  else:
    cval/=parse_val(accum)
  return cval
def parse_val(val):
  if val[0] == "(": #Parenthetical expression
    return parse(val[1:-1]) #Cut off parentheses and reevaluate
  else:
    return float(val) #Not parenthetical

Takes the square root of an int and returns a double.

double sqrt (int a,int accuracy=20) {
  double out = a;
  for(int i=0;i<accuracy;i++) {
    out = (out+a/out)/2;
  }
  return out;
}

Fast algorithm to test primality

import math
def isprime(num):
  if num<2 or int(num)!=num: return False
  if not num%2 and num>2: return False
  for n in range(3,math.ceil((num-1)**.5)+1,2):
    if not num%n:
      return False
  return True
Fundamentals
Lambdas
Functional Programming
Functions
Declarative Programming
Programming Paradigms
Control Flow
Basic Language Features

Lambda recursion.

/**
 * Created by ice1000 on 2017/5/2.
 *
 * @author ice1000
 */
fun main(args: Array<String>) {
	fun lambda(it: Int): Int =
			if (it <= 2) 1 else lambda(it - 1) + lambda(it - 2)
	(1..10).map(::lambda) // .forEach(::println)

	var lambda2: (Int) -> Int = { it }
	lambda2(1)
	lambda2 = { if (it <= 2) 1 else lambda(it - 1) + lambda(it - 2) }
	(1..10).map(lambda2) // .forEach(::println)
}

This is a fix for the published but broken kata

function isArray(arr) {
  return Object.prototype.toString.call(arr) === "[object Array]";
};

An implementation of the Sieve of Eratosthenes for finding prime numbers, fully focusing on performance.

The biggest performance gains come from forcing data set manipluation loops to be performed in the C-level code inside Python and not inside loops within the source code of the sieve. The places where this is used in particular are:

  • Striking out compounds in the sieve using the list[start::skip] = list syntax
  • Creating the final list of primes by using compress() to filter primes from the sieve
from math import sqrt, ceil
from itertools import compress

def sieve(until):
    if until < 2:
        return []
    store_len = until >> 1
    is_prime = [True] * store_len
    for offset, number in enumerate(range(3, int(sqrt(until)) + 1, 2)):
        if is_prime[offset]:
            first_compound_at = (number*number-3) >> 1
            nr_of_compounds = int(ceil((store_len-first_compound_at) / number))
            is_prime[first_compound_at::number] = [False] * nr_of_compounds
    return [2] + list(compress(range(3, until + 1, 2), is_prime))
Fundamentals
Lists
Data Structures
Functional Programming
Declarative Programming
Programming Paradigms

That's good

/**
 * Created by ice1000 on 2017/4/27.
 *
 * @author ice1000
 */

fun <A, B, C : Any> zipWith(op: (A, B) -> C) = { x: Sequence<A> ->
	{ y: Sequence<B> ->
		val iX = x.iterator()
		val iY = y.iterator()
		generateSequence {
			if (iX.hasNext() and iY.hasNext()) op(iX.next(), iY.next())
			else null
		}
	}
}

fun <T : Any> generate() = zipWith { x: Int, y: T -> "[$y * x^$x]" } (
	generateSequence(0, Int::inc)
)

fun main(args: Array<String>) =
		generate<Int>()(sequenceOf(1, 1, 2, 3, 5, 8, 13, 21)).forEach(::println)
def binary_search(lst,item):
    low = 0
    high = len(lst) - 1
    while low <= high:
        mid = int((high + low)/2)
        guess = lst[mid]
        print (guess,mid)
        if guess > item:
            high = mid - 1
        if guess < item:
            low = mid + 1
        if guess == item:
            return mid
    else:
        return None