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

This is bobble sort alghoritm.

# Python3 Optimized implementation 
# of Bubble sort 
  
# An optimized version of Bubble Sort 
def bubbleSort(arr): 
    n = len(arr) 
    # Traverse through all array elements 
    for i in range(n): 
        swapped = False
        # Last i elements are already 
        #  in place 
        for j in range(0, n-i-1): 
            # traverse the array from 0 to 
            # n-i-1. Swap if the element  
            # found is greater than the 
            # next element 
            if arr[j] > arr[j+1] : 
                arr[j], arr[j+1] = arr[j+1], arr[j] 
                swapped = True
        # IF no two elements were swapped 
        # by inner loop, then break 
        if swapped == False: 
            break
            
# Driver code to test above 
arr = [64, 34, 25, 12, 22, 11, 90] 
   
bubbleSort(arr) 
   
print ("Sorted array :") 
for i in range(len(arr)): 
    print ("%d" %arr[i],end=" ")
int foo() { return 1; }
int bar() { return 2; }
int baz() { return 3; }

Your task is make a calculator.
its rule is like polish notation.
you only need to deal with add, minum, multiply and divide.
e.g.
run(add,1,2) -> 3
run(minum,10,2,2) -> 6
run(multiply,2,25,2) -> 100
(The number of elements to be calculated is unlimited)

add = lambda *args:sum(args)
def minum(*args):
    xxx = args[0]
    for i in range(1,len(args)):
        xxx = xxx - args[i]
    return xxx
def multiply(*args):
    xxx = 1
    for i in args:
        xxx = xxx * i
    return xxx
def divide(*args):
    xxx = args[0]
    for i in args[1:]:
        xxx = xxx / i
    return xxx
def run(func,*args):
    return func(*args)

right

function returnAscending(n){
  return +(n+'').split('').sort(function(a,b){return a-b }).join('');
}

2048 is a single-player sliding block puzzle game designed by Italian web developer Gabriele Cirulli. The objective of the game is to slide numbered tiles on a grid to combine them to create a tile with the number 2048; however, one can continue to play the game after reaching the goal, creating tiles with larger numbers.
The question is how high you can go.

Every turn, a new tile will randomly appear in an empty spot on the board with a value of either 2 or 4. If two tiles of the same number collide, they will merge into a tile with the total value of the two tiles that collided.

For a given board size, return the highest numbers, and sum of all numbers.

For example, for a normal 4x4 board and you are really lucky, the best possible board is:
131072 65536 32768 16384
1024 2048 4096 8192
512 256 128 64
4 8 16 32

The best possible block is 131072, the sum of all blocks is 262140

def calculate_2048(size):
    sq = 4
    for _ in range(0,size*size-1): #calculating the highest square by simply multiplying it by 2
        sq *= 2
    highest = sq
    sumtotal = sq
    for _ in range(0,size*size-1): #calculating the highest score by adding up every number back down to 4
        sq = int(sq/2)
        sumtotal = int(sumtotal+sq)
    return highest, int(sumtotal)

Converts the string to Brainfuck.

#include <stdio.h>
#include <string.h>
// #define DEBUG

char s[4096] = "";
int s2b(int argc, char *argv[]) {
	register int i = 0,j;
	register int k,m;
	register int l,last = 0;
	if (argc != 2) {
		printf("Usage: %s [string]",*argv);
		return 1;
	}
	while (argv[1][++i]!=0)
		continue;
	for (j=0; j<i; j++) {
		register int t;
		t = argv[1][j];
		l = k = t-last;
		last = t;
#ifdef DEBUG
		printf("\n%d, %d, %d, %d\n",last,k,j,i);
#endif

		if (k >= 0) {
			k >>= 3; // k /= 8
			l &= 7; //在更多的机器工作,求余
			if (k == 1)
				strcat(s,">++++++++");
			else {
				if (k != 0) {
					strcat(s,"++++++++[>");
					for (m=0; m<k; m++)
						strcat(s,"+");
					strcat(s,"<-]>");
				} else {
					strcat(s,">");
				}
			}
			for (m=0; m<l; m++)
				strcat(s,"+");
			strcat(s,".");
		} else {
			k = -k >> 3; // k /= 8
			l = -l & 7; //在更多的机器工作,求余
			if (k == 1)
				strcat(s,">--------");
			else {
				strcat(s,"++++++++[>");
				for (m=0; m<k; m++)
					strcat(s,"-");
				strcat(s,"<-]>");
			}
			for (m=0; m<l; m++)
				strcat(s,"-");
			strcat(s,".");
		}
#ifdef DEBUG
		printf("\n%d, %d, %d\n",m,k,l);
#endif

		strcat(s,"<");
	}
  return 0;
}
fn around(x: usize, y: usize) -> HashSet<(usize, usize)> {
    return [
        (Some(x), y.checked_add(1)),
        (Some(x), y.checked_sub(1)),
        (x.checked_add(1), Some(y)),
        (x.checked_sub(1), Some(y)),
    ]
    .iter()
    .filter_map(|(vv, hh)| vv.and_then(|vvv| hh.and_then(|hhh| Some((vvv, hhh)))))
    .collect();
}
Mathematics
Algorithms
Logic
Numbers

Create a function to be able to add, substract, multiply or divide all the numbers given in the array provided.

Parameters:

1. Array
2. Operator:
    -'Add'
    -'Substract'
    -'Divide'
    -'Multiply'

Example:

function: getResult(array, operator)
array: [4, 2, 1]

operator: 'Add'
result: 7

operator: 'Substract'
result: 1

operator: 'Divide'
result: 2

operator: 'Multiply'
result: 8

function getResult(array, operator) {
    //Good luck!
}

Given a positive number n > 1 find the prime factor decomposition of n. The result will be a string with the following form :

"(p1n1)(p2n2)...(pk**nk)"
where a ** b means a to the power of b

with the p(i) in increasing order and n(i) empty if n(i) is 1.

Example: n = 86240 should return "(25)(5)(72)(11)"

require 'prime'

def primeFactors(n)
  result = ''
  Prime.prime_division(n).each do |n|
    result += '(' + n[0].to_s
    n[1] < 2 ? result += ')' : result += '**' + n[1].to_s + ')'
  end
  
  result
end

For some unknown reason (there is a reason, but "for some unknown reason" sounds more fun) there is no product function in python
Let's add it!

note: The product of an empty list is 0.

def prod(numbers):
    if numbers == []: return 0
    product = 1
    for number in numbers:
        product *= number
    return product