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

inputOrder: [5,4,1]

#include <stdio.h>

struct _Node{
  int value;
  struct _Node *left;
  struct _Node *right;
  int height;
};

typedef struct _Node Node;

int max( int a, int b )
{
    return(a>b?a:b);
}

int Height( Node* tree )
{
    if( NULL == tree ) {
        return -1;
    }
    
    return tree->height;
}

int InitTree( Node* tree, int value )
{
  if( tree == NULL ) {
      return -1;
  }
  tree->value = value;
  tree->left = NULL;
  tree->right = NULL;
  tree->height = 0;
  return 0;
}

Node* SingleRotateWithLeft( Node* k1 )
{
    Node* k2;
    
    k2 = k1->left;
    k1->left = k2->right;
    k2->right = k1;
    
    k1->height = max(Height(k1->left), Height(k1->right)) + 1;
    k2->height = max( Height(k2->left), Height(k1) ) + 1;
    return k2;
}

Node* InsertTree(Node *tree, Node *new_node )
{
  if( new_node->value > tree->value ) {
    if( tree->right == NULL ) {
        tree->right = new_node;
    } else {
        InsertTree( tree->right, new_node );
    } 
  } else {
    if( tree->left == NULL ) {
        tree->left = new_node;
    } else {
        InsertTree( tree->left, new_node );
        if( Height(tree->left) - Height(tree->right) == 2 ) {
            if( new_node->value < tree->left->value ) {
                tree = SingleRotateWithLeft(tree);
            }
        }
    }
  }
  tree->height = max(Height(tree->left),Height(tree->right)) + 1;
  return tree;
}

void OrderTraverse( Node* tree )
{
  if( tree != NULL ) {
      printf("value:%d height:%d\t\n", tree->value,tree->height);
      OrderTraverse( tree->left );
      OrderTraverse( tree->right );
  }
}

int main()
{
  Node *tree = NULL;
  tree = (Node*)malloc(sizeof(Node));
  InitTree(tree, 5);
  int i = 0;
  int array[10] = {4,1};
  
  for( i = 0; i < 2; i++ ) {
      Node *node = NULL;
      node = (Node*)malloc(sizeof(Node));
      if( NULL == node ) {
        continue;
      }
      InitTree(node,array[i]);
      tree = InsertTree(tree,node);
  }
  printf("preOrderTraverse:\n");
  OrderTraverse(tree);
  printf("succeed!\n");
  return 0;
}
def ShellSort(ary):
    length = len(ary)
    gap = round(length)
    step = length//2
    while step:
        for i in range(step,length,step):
            tmp = ary[i]
            for j in range(i,0,-step):
                if ary[j-step] > tmp:
                    ary[j] = ary[j-step]
                else:
                    break
            ary[j] = tmp
        if step == 1:
            break
        step = step//2
      
        
ary = [1,23,4,53,55,34,3,99,14]
ShellSort(ary)
print(ary)
export const example = () => {
return 1
}

Find the absolute value, also known as the positive counterpart to a negative integer

function av(num) {
}

return a string that says ok

//return string that says the word ok
open Preloaded;

let fib = (n) => {
  let rec fib_aux = (n, a, b) =>
    if (n <= 0) { a; }
    else { fib_aux(n - 1, b, a +@ b); }
  fib_aux(n, big_int_of_int(0), big_int_of_int(1))
    |> string_of_big_int;
};

Sometimes we buy something we may receive some change, so, how much?

#Examples:
getChange(4,10) => 6
getChange(4,100) => 96;
getChange(4.5,100) => 95.5;
getChange(3.5,5) => 1.5;
getChange(3.8,5) => 1.2;

###1 note this:youMoney > allPrice.
###2 Subtraction is not necessarily correct.
###3 Maybe you can use Math.

function getChange(allPrice,youMoney){
  return Math.round(youMoney*1000 - allPrice*1000)/1000;
}
Algorithms
Logic

We have n piles of apples, and we want to get them together.
Once a time we can combine two piles of apples with a and b apples seperately together, using a+b forces. We want to know the minimum forces we use to combine all piles of apples together.
Input:
apple(n,lst)
where lst contains n numbers representing the number of apples in each pile

#include<stdio.h>
#include<queue>
using namespace std;
int apple(int n,int* a)
{
        priority_queue<int,vector<int>,greater<int> >q;
        for(int i=0; i<n; i++)
            q.push(a[i]);
        int ans=0,tmp;
        while(q.size()>=2)
        {
            tmp=0;
            tmp+=q.top();
            q.pop();
            tmp+=q.top();
            q.pop();
            ans+=tmp;
            q.push(tmp);
        }
        return ans;
}

The method should multiply parameters (a and b).

I hope that it won't be so difficult.
public class Multiplication
{
    public int Multip(int a, int b)
    {
        return a * b;
    }
}

This is a first experiment of mine in generating primes. Theoretically, with enough calculating power and storage space you could find primes indefinitely. I cribbed some of the guts from another work and justled them around a bit. Advice welcome.

def primemaker(x):
    primes = []
    isprime = True
    for possibleprimes in range(2,x):
        for n in range(2,possibleprimes):
            if possibleprimes % num == 0:
                isprime = False
        if isprime:
            primes.append(possibleprimes)
    print(primes)