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

You are building a calendar app. You have the following task assigned to you:

Build a function that receives a single parameter - a list of time intervals when the user is not available - and returns a list of the intervals when the user will be free in the same day. Consider that all times are restricted to 30 minutes increments, eg “12:00”, “00:30”, “17:30”. No input validation is necessary.

Both the parameter and the return value should be a list of tuples, for example, the following list:

[(“12:00”, “13:00”), (“14:00”, “17:00”)]

Means that the user is busy from 12:00 to 13:00 (let’s say it’s his lunch time) and from 14:00 to 17:00 (let’s say he’ll be in a long meeting). Calling the function with the arguments, like:

Should return the time intervals when the user is available, so, in this case, it would be:

[(“00:00”,“12:00”), (“13:00”, “14:00”), (“17:00”, “24:00”)]

def get_available_times(hours):
    available_times = {}
    i = 0
    for i in range(0, len(hours)):
        if hours[i][0] == '00:00':
            continue
        if i == 0:
            available_times['00:00'] = hours[i][0]
        else:
            available_times[hours[i-1][1]] = hours[i][0]
        if i == (len(hours) - 1) and hours[i][1] != '24:00':
            available_times[hours[i][1]] = '24:00'
    return list(available_times.items())
Logic
Arrays
Data Types
Objects

The function must receive three parameters: array, order, and key. The key must determine the order of the array, as in the example:

let arr = [
{id: 5, name: 'Hugo'},
{id: 2, name: 'Julian'},
{id: 3, name: 'Anne'},
{id: 1, name: 'April'},
{id: 4, name: 'John'}
];

let order = [1, 2, 3, 4, 5];

mapOrder(arr, order, 'id');

must return:

0: {id: 1, name: "April"}
1: {id: 2, name: "Julian"}
2: {id: 3, name: "Anne"}
3: {id: 4, name: "John"}
4: {id: 5, name: "Hugo"}

function mapOrder(array, order, key) {
  if (typeof array !== 'object' || typeof order !==  'object' || typeof key !== 'string') return [];
  
  array.sort((a, b) => {
    let A = a[key], B = b[key];

    if (order.indexOf(A) > order.indexOf(B)) {
        return 1;
    } else return -1;
  });

  return array;
}

Whether you're a kata solver or a kata author, Codewars allows you to embed client-side
HTML, CSS, and JavaScript in your outputs.

This goes well beyond ASCII art. The door is open to more sophisticated debugging and visualization techniques. For a contrived and sloppily coded example, run this kata; in the output panel there should be a snake which, if luck will have it, you can control via the arrow keys on your keyboard.

Some JavaScript methods are disabled in this environment, but even so, for kata authors with JavaScript+CSS experience and full DOM control, the sky's the limit.

// The client-side stuff that this demo is made of is
// in the preloaded section, but it's not pretty or necessary
// to look at so I'm leaving it out of the main code view.
// The purpose of this kumite isn't to demonstrate *how* to embed HTML.
// That's as trivial as console.log(). The point, rather, is
// to make a public service anouncement to remind everyone
// that HTML, CSS, and JavaScript are available, and when
// deployed appropriately they can improve your katas.

Split Each Alphabet in a String

You can use this method to split words.

def split(word):
    # if word is "hello" returns ["h", "e", "l", "l", "o"]
    return [x for x in word]

Ascii 'A' is single byte. = {65}
Unicode 'A' is double byte 'A' = {0,65}

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

unsigned short *AsciiToUnicode( unsigned char *ascii);

unsigned short *AsciiToUnicode( unsigned char *ascii){
  int len = strlen((const char *)ascii);
  unsigned short *ptr = NULL;
  
  ptr = (unsigned short *)malloc(len);
  memset(ptr, 0, len);
  
  for (int i = 0; i < len; i++){
    *(ptr + i) = *(ascii + i);
  }
    
  return ptr;
}

int main(){
  unsigned short *unicode = AsciiToUnicode((unsigned char *)"ABC");
  
  for (unsigned short i=0; *(unicode+i); i++){
    printf("%c ", (unsigned char) *(unicode+i));
  }
  free(unicode);
  return 0;
}
export function validateString(input: string, index: number, stack: number = 0): boolean {
  // TODO: your code
  if(index === 0 && (input[index] === ')' | input[index] === '}' | input[index] === ']')) {
    return false;
  }
    
  if(input[index] === '(' | input[index] === '{' | input[index] === '[') {
    stack++;
  }
  
  validateString(input, index + 1, )
  
}

A company wants to put a cell tower to the north of a city but is unsure of where buildings will cause interference.

You will be given a 2D array comprised of numbers representing the interference of a building. This value will be a decimal number less than 1 that represents the percentage impact it has on the signal strength.

You may assume that the signal is uniform across the entire northern front of the city.

The first row will have the strength of the initial signal strength.

You are tasked with producing a 2D array that shows where the cell signal reaches comprised of numbers that represent the strength of the cell signal at each location.

With each unobstructed row the signal passes through, it will lose a constant 1 strength.

Should the signal drop below 1, it will be considered 0.

Each calculation should be rounded to 2 decimal points.

As an example, you may be given an input resembling the following (formatted to ease of reading):

building_map = [
  [0.20, 0.00, 0.00, 0.00, 0.00],
  [0.00, 0.00, 0.25, 0.00, 0.00],
  [0.00, 0.50, 0.00, 0.00, 0.00],
  [0.00, 0.00, 0.50, 0.00, 0.00],
  [0.15, 0.00, 0.00, 0.10, 0.00]
],
signal_strength = 4

You should return the following array:

signal_map = [
  [3.20, 4.00, 4.00, 4.00, 4.00],
  [2.20, 3.00, 3.00, 3.00, 3.00],
  [1.20, 1.50, 2.00, 2.00, 2.00],
  [0.00, 0.00, 1.00, 1.00, 1.00],
  [0.00, 0.00, 0.00, 0.00, 0.00]
]
# Enter solution here
def get_signal_pattern(building_map, signal_strength):
    return []

A company wants to put a cell tower to the north of a city but is unsure of where buildings will cause interference.

You will be given a 2D array comprised of 0s and 1s representing no buildings and buildings respectively.

You may assume that the signal is uniform across the entire northern front of the city.

You are tasked with producing a 2D array that shows where the cell signal reaches comprised of 0s and 1s where 0 is no signal and 1 has signal.

For this first iteration, assume that one building stops a signal and the locations of builds also do not have signal.

You may also assume that the signal is otherwise strong enough to reach the southern edge of the city.

As an example, you may be given an input resembling the following:

building_map = [
  [1, 0, 0, 0, 0],
  [0, 0, 1, 0, 0],
  [0, 1, 0, 0, 0],
  [0, 0, 1, 0, 0],
  [1, 0, 0, 1, 0]
]

You should return the following array:

signal_map = [
  [0, 1, 1, 1, 1],
  [0, 1, 0, 1, 1],
  [0, 0, 0, 1, 1],
  [0, 0, 0, 1, 1],
  [0, 0, 0, 0, 1]
]
# Enter solution here
def get_signal_pattern(building_map):
    return []
Algorithms
Logic
Data Structures

You are working to an accounting company and your boss ask to make a program to get the most worked years.

Him already have the data in the database and will response with a matrix data.

For example: [[2001,2005],[1920,1960],[2001,1999],...] what you
will receive from the database.

The program only should return only an integer value corresponding to the most worked year.

const mostWorkedYears = (matrix) =>
  matrix
    .map((item) => item[0])
    .reduce(
      (accum, curr, index, array) =>
        curr === array[index + 1] ? accum + curr : curr,
      0
    );

Write a program to check is the number simple.

It can receive either negative or positive numbers, integer and not integer, simple and not simple.

It should return true if the given number is actually simple (2, 3, 5, 7...)

export const checkIsNumberSimple = (number: number) => {
  // Check if the number is integer
  if (number % 1 != 0) return false;
  
  if (number < 2) return false;
  
  if (number != 2 && number % 2 == 0) return false;
  
  if (number != 3 && number % 3 == 0) return false;

  return true;
};