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
def get_prime_factorization(number):
    """Gets the prime factorization of a number, and returns it.

    @type number: float
    @param number: A float representing the number to be factored.
    """
    current_dividing_factor = float(number)
    if current_dividing_factor == 1.0 or current_dividing_factor == 0.0 or current_dividing_factor == -1.0:
        return [current_dividing_factor]
    
    factors = []
    # Catches all negative numbers and makes them positive.
    if current_dividing_factor < 0.0:
        factors.append(-1.0)
        current_dividing_factor *= -1.0
        
    # Catches all numbers not whole numbers and makes them whole numbers.
    if current_dividing_factor % 1.0 != 0.0:
        decimal_places = len(str(current_dividing_factor % 1.0)) - 2.0
        factors.append(10.0 ** (-decimal_places))
        current_dividing_factor *= 10.0 ** decimal_places
        
    # Gets all factors greater than 2.0 and adds them to the factor list.
    test_factor = 2.0
    while test_factor <= current_dividing_factor:
        if current_dividing_factor % test_factor == 0.0:
            factors.append(test_factor)
            current_dividing_factor /= test_factor
            test_factor = 2.0
        else:
            test_factor += 1.0
    return factors

This small piece of code calculates the prime factorisation of any given number.

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Factorisation {

	public static List<Integer> primeFactorsOf(int input) {

		List<Integer> pFactors = new ArrayList<>();
		long number = input;

		for (int i = 2; i <= number; i++) {
			if (number % i == 0) {
				pFactors.add(i);
				number /= i;
				i--;
			}
		}
		return pFactors;
	}

  public static void main(String[] args) {
    
  }
}

It always starts with "hello world" ^^

c("Hello World!")

A simple algorithm to find whether a set of ranges overlap.

Notes:

  • This could take in any number of ranges.
  • Have a look at the gist with some tests to play with the code.
  • The code creates a flat array with the start and end of each range.
  • This array will retain the order if they don't overlap. (Its easier to visualize with some examples than textually explaining why, try it).
class Range
  include Comparable

  def <=>(other)
    self.begin <=> other.begin
  end

  def self.overlap?(*ranges)
    edges = ranges.sort.flat_map { |range| [range.begin, range.end] }
    edges != edges.sort.uniq
  end
end

Range.overlap?(2..12, 6..36, 42..96) # => true
console.log "Hello, coffeescript!"
Strings
Data Types

Hello world! style application, Perl style.

print "Hello Perl!\n";
Arrays
Data Types
Logic
Basic Language Features
Fundamentals
Strings

Write a function that takes as a parameter a starting square as a string in formal chess notation and determines the valid squares that the bishop can move to in one move for an empty chess board (only bishop on the board). Must return an array of valid squares in ascending square order.

function moveBishop($startingSquare)
{
    $result = [];
    $letters = ["a" =>  1, "b" => 2, "c" => 3, "d" => 4, "e" => 5, "f" => 6, "g" => 7, "h" => 8];   
    $startSqaureInDigits = $letters[$startingSquare[0]] . $startingSquare[1];
    
    // bishop movement is always two ways at the same time as it moves diagonally at least one space.
    // loop over 8 by 8 chessboard
    //i loop is for letters
    //j loop is for numbers
    
    for($i = 1; $i <= 8; $i++){
        for($j=1; $j <= 8; $j++)
        {
            if ($startSqaureInDigits != $i.$j &&  abs($startSqaureInDigits[0] - $i) ==  abs($startSqaureInDigits[1] - $j) ) 
            {
                $result[] = array_search($i,$letters).$j;
            }
        }
    }
    return $result;
}

Given a string of open and closed parenthesis output "Balanced" if the parenthesis are balanced or "Unbalanced" otherwise.

A string is balanced if it consists entirely of pairs of opening/closing parenthesis (in that order), none of which mis-nest.

Example input:
(())())

Example output:
Unbalanced

Example input:
(()())

Example output:
Balanced

function balanced_parenthesis(s) {
    if(s == null) return null;
    
    var i = 0,
        startCnt = 0,
        n = s.length;
 
    for(i = 0; i < n; i++) {
        if(s[i] === "(") {
            startCnt += 1;
        } else if(s[i] === ")") {
            startCnt -= 1;
            if(startCnt < 0) {
                break;
            }
        }
    }
 
    if(startCnt !== 0) {
        return 'Unbalanced';
    } else {
        return 'Balanced';
    }
}

def foo(l):
r = copy(l)
return r

l = [1,2]
print(l)
n = foo(l)
print(n)
l.append(7)
print(n)
print(l)

def foo(l):
	r = l
	return r

l = [1,2]
print(l)
n = foo(l)
print(n)
l.append(7)
print(n)
print(l)

Generate prime numbers within a given minimum and maximum.
min and max values should be positive (greater than 0).

import java.util.*;

public class Primes {
  public static List<Integer> generatePrimes(int min, int max) {
    List<Integer> primes = new ArrayList<Integer>();
    boolean isPrime = false;
    
    if((min > max) || min < 0 || max <= 0) {
      return null;
    }           
            
    for(int i = min; i <= max; i++) {
      long endLimit = (long)Math.floor(Math.sqrt(i));
      isPrime = true;
      for(long j = 2; j <= endLimit; j++) {
        if (i % j == 0) {
          isPrime = false;
          break;
        }
      }
    
      if(isPrime) {
        primes.add(i);
      }
    }
    
    return primes;
  }
}