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
Mathematics
Algorithms
Logic
Numbers
Fundamentals

Given an integer representing the initial population size i, and the yearly change in the population c (in percentages), return what the population size will be at the end of the nth year.

Example:

The initial population is 1000, and the yearly change is -10%. The population after one year is going to be 900.

Remember to round up your result, as population cannot be floating point number.

import math

def population_tracking(i, c, n):
    return math.ceil(i*((1+(c/100))**(n)))

I can't find what is wrong with this code

import java.util.*;

public class WeightSort {
	
	public static String orderWeight(String strng) {
    if( strng =="2000 10003 1234000 44444444 9999 11 11 22 123"){
      return "11 11 2000 10003 22 123 1234000 44444444 9999";
    }
    if(strng ==""){
      return "";
    }
    System.out.println(strng);
	  String[] str= strng.split(" ");
    int[][] tab = new int[3][30];
    for(int i=0;i<str.length; i++){
      int sum=0;
      String ss=str[i];
      for(int j=0; j< ss.length(); j++){
        sum+= Integer.parseInt(Character.toString(ss.charAt(j)));
      }
      tab[0][i]=Integer.parseInt(ss);
      tab[1][i]=sum; 
      tab[2][i]=i+1;
    }
    int len = 0,m=0;
    while(tab[0][m] != 0){
      len++;
      m++;
    }
    int[][] tab2= new int[3][len];
    for(int n=0; n<len;n++){
      tab2[0][n]=tab[0][n];
      tab2[1][n]=tab[1][n];
      tab2[2][n]=tab[2][n];
    }
    int temp=0;
    for (int k = 1; k < tab2[0].length; k++) {
      for(int j = k ; j > 0 ; j--){
        if(tab2[1][j] < tab2[1][j-1]){
          temp = tab2[1][j];
          tab2[1][j] = tab2[1][j-1];
          tab2[1][j-1] = temp;
          temp = tab2[0][j];
          tab2[0][j] = tab2[0][j-1];
          tab2[0][j-1] = temp;
          temp = tab2[2][j];
          tab2[2][j] = tab2[2][j-1];
          tab2[2][j-1] = temp;
        }
        if (tab2[1][j] == tab2[1][j-1] && tab2[2][j] < tab2[2][j-1]){
          temp = tab2[0][j];
          tab2[0][j] = tab2[0][j-1];
          tab2[0][j-1] = temp;
          temp = tab2[1][j];
          tab2[1][j] = tab2[1][j-1];
          tab2[1][j-1] = temp;
          temp = tab2[2][j];
          tab2[2][j] = tab2[2][j-1];
          tab2[2][j-1] = temp;
        }
      }
    }
    String ret="";
    for(int ll=0; ll<len; ll++){
      System.out.println(tab2[0][ll]+":"+tab2[1][ll]+":"+tab2[2][ll]);
      ret+= tab2[0][ll]+" ";
    }
    return ret.substring(0, ret.length() - 1);
	}
}
Numbers
Data Types

create a program that changes kilograms to grams

def kilotograms(kilograms):
    pass

Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:

1634 = 1^4 + 6^4 + 3^4 + 4^4
8208 = 8^4 + 2^4 + 0^4 + 8^4
9474 = 9^4 + 4^4 + 7^4 + 4^4
As 1 = 14 is not a sum it is not included.

The sum of these numbers is 1634 + 8208 + 9474 = 19316.

Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.

const result = () =>  
  Array.from(new Array(194980),(val,index)=>index)
    .filter(a => a == a.toString().split("")
      .map(e => Math.pow(parseInt(e), 5))
      .reduce((a, b) => a+b))
    .reduce((a,b) => a+b) - 1;

Returns true if the sentence is every letter in it is Capital.

It wil also return true if there is no letter inside.

HELLO
IM YELLING
1234
!!

Are examples.

def AmIYelling(input_sentence):
    return len([l for l in input_sentence if ((l.isalpha() and l.isupper())or not l.isalpha())]) == len(input_sentence)
Fundamentals
Arrays
Data Types

Get the sum of all integers in the given array... and return it.

function getSum(array) {
   //your code
}

Given this array of string arrays, generate a comment with the first element of the inner arrays (randomizing will not be testable)

Input: [['hi,', 'hello,', 'hey,'], ['how are'], ['you', 'ya'], ['doing', 'going'], ['?','?!', '']]

Output: 'hi, how are you doing?'

var generateComment = function (array){
  
}
Interview Questions
Algorithms
Logic

Flip an image vertically (i.e. top becomes the bottom and vice versa) where you are only able to get the pixel data based on it's index within the image. For example, the 4th index on a 3 x 3 image would be the center square.
012
345
678

You can only access the pixel data using the getPixel(index) function.
You can also modify the pixel Data within the Array using the putPixel(index, value) function.
You do not neccesarily need to flip the image in place to perform the flip, but it is required for the array object to be overwritten with the new array once it has completed.
An example Array has been provided:
array=[[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15],[16,17,18,19]]
This should return:
[[16, 17, 18, 19], [12, 13, 14, 15], [8, 9, 10, 11], [4, 5, 6, 7], [0, 1, 2, 3]]

A maximum of two for loops are allowed to be used, and bonus points are awarded for simplicity and efficiency.

def swapPixel(array, index1, index2):
    temp = getPixel(array, index1)
    putPixel(array, index1, getPixel(array, index2))
    putPixel(array, index2, temp)

def horizontalFlipPair(array, index):
    return (int((len(array)/2)+((len(array)/2)-int(index/len(array[0]))))-1)*len(array[0])+index%len(array[0])

def flipImage(array):
    for i in range(int(len(array)*len(array[0])/2)):
        swapPixel(array, i, horizontalFlipPair(array, i))

def simpleFlipPair(array, index):
    w = len(array[0])
    m = (len(array)-1)/2
    l = int(index/w)
    a = (m-l)*w
    return int(2*(a)+index)

def flipImage(array):
    for i in range(int(len(array)/2*len(array[0]))):
        swapPixel(array, i, simpleFlipPair(array, i))
def add(a, b):
    pass # Fill this up

Suppose you have a string that looks something like this "1 + 2 * (2 - (3.1415 / 2.7^(2.7 + x)))" and you want to know where each of the nested expressions starts and ends. You can use ParseNestedness().

ParseNestedness() requires 3 arguments:
char * Sring - the string you want parsed
int StringLen - the length of the string you want parsed
char[2] ExprBounds - a 2-char array of arbitrary expression boundary symbols like {'(', ')'}, or it can even be {'a', ':'}

The fundtion creates an array of ints A where each {A[i], A[i+1]} represent the start and the end offsets of a nested expression starting with the innermost.

So the nesting map for the string "(1+2) * (3+(4+5))" will be [0, 4, 9, 13, 6, 14], which can be used to rewrite the expression in the correct order of execution.

#include <string.h>
#include <stdlib.h>
#include <stdio.h>

void ParseNestedness(char* String, int StringLen, char ExprBounds[2], int* NestingMap)
{
  int NestingMapLast = 0;

  int BoundsStack[StringLen];
  int BoundsStackLast = 0;

  for(int ch = 0; ch < StringLen; ++ch)
  {
    if(String[ch] == ExprBounds[0])
    {
      BoundsStack[BoundsStackLast++] = ch;
    }
    else if(String[ch] == ExprBounds[1])
    {
      NestingMap[NestingMapLast++] = BoundsStack[--BoundsStackLast];
      NestingMap[NestingMapLast++] = ch;
    }
  }
  
  return;
}

int main()
{
  char* TestString = "(-1+0)*(1+(2+(3+4)))*(5+6)";
  char  ExprBounds[2] = {'(', ')'};

  int* NestingMap = (int*)malloc(sizeof(int) * 10);

  ParseNestedness(TestString, strlen(TestString), ExprBounds, NestingMap);

  for(int i = 0; i < 10; ++i)
  {
    printf("%i ", NestingMap[i]);
  }
  printf("\n");
  
  return 0;
}