Begin a new Kumite
Search
About
  • Filter by Language:
  • 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.

num -> string -> array -> [sort(), reverse()] -> string -> num

JS is fun!

Code
Diff
  • const descendingOrder = n =>
      +[...''+n].sort().reverse().join``;
  • 1-function descendingOrder(n){
    2- return Number(String(n).split('').sort(function(a, b){return b-a}).join(''));
    3-}
    1+const descendingOrder = n =>
    2+ +[...''+n].sort().reverse().join``;
Code
Diff
  • const main = () =>  {
      let = ['https://www.uol','https://www.bol.com.br','https://www.uol','https://noticias.uol.com.br','https://www.bol.com.br'];
      return [...new Set(links)].length;
    };
    
    // Functions should be passed arguments, not have the data already inside them.
    // Test case:
    // Test.assertEquals(['https://www.uol','https://www.bol.com.br','https://www.uol','https://noticias.uol.com.br','https://www.bol.com.br'], 3);
    
  • 1-const main = () => {
    2-
    3- let links = [
    4- 'https://www.uol',
    5- 'https://www.bol.com.br',
    6- 'https://www.uol',
    7- 'https://noticias.uol.com.br',
    8- 'https://www.bol.com.br',
    9- ];
    10-
    11- // converter para ES6
    12- var uniqueLinks = links.reduce(function (carry, item) {
    13- if (carry.indexOf(item) === -1) {
    14- carry.push(item);
    15- }
    16- return carry;
    17- }, []);
    18-
    19-
    20- return uniqueLinks.length;
    1+const main = () => {
    2+ let = ['https://www.uol','https://www.bol.com.br','https://www.uol','https://noticias.uol.com.br','https://www.bol.com.br'];
    3+ return [...new Set(links)].length;
    2121 };
    5+
    6+// Functions should be passed arguments, not have the data already inside them.
    7+// Test case:
    8+// Test.assertEquals(['https://www.uol','https://www.bol.com.br','https://www.uol','https://noticias.uol.com.br','https://www.bol.com.br'], 3);

With parameter int 011, the tests fail.

Code
Diff
  • const alphabetPosition = s => s.toLowerCase().replace(/[a-z]|(.)/g, (m, c) => c ? '' : ` ${m.charCodeAt(0) - 96}`).trim();
  • 1-function alphabetPosition(text) {
    2- let obj = {
    3- "a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7,
    4- "h": 8, "i": 9, "j": 10, "k": 11, "l":12, "m": 13, "n": 14, "o": 15, "p": 16, "q": 17, "r": 18, "s": 19, "t": 20,
    5- "u": 21, "v": 22, "w": 23, "x": 24, "y": 25, "z": 26
    6- }
    7- let arr = [];
    8- let str = '';
    9-
    10- text = text.replace(/[^a-zA-Z]+/g, '');
    11- for (let key in obj) {
    12- for (let i = 0; i < text.length; i++) {
    13- if(text[i].toLowerCase() == key.toLowerCase() && text[i] !== '') {
    14- arr[i] = obj[key];
    15- }
    16- }
    17- }
    18-
    19- str = arr.join(' ');
    20- return str;
    21-}
    1+const alphabetPosition = s => s.toLowerCase().replace(/[a-z]|(.)/g, (m, c) => c ? '' : ` ${m.charCodeAt(0) - 96}`).trim();
Numbers
Integers
Algorithms

match point

Code
Diff
  • // Removed loop
    fn digits (n: u64) -> usize
    {
      match n {
        0 ..= 9 => 1,
        10 ..= 99 => 2,
        100 ..= 999 => 3,
        1000 ..= 9999 => 4,
        10000 ..= 99999 => 5,
        100000 ..= 999999 => 6,
        1000000 ..= 9999999 => 7,
        10000000 ..= 99999999 => 8,
        100000000 ..= 999999999 => 9,
        1000000000 ..= 9999999999 => 10,
        10000000000 ..= 99999999999 => 11,
        100000000000 ..= 999999999999 => 12,
        1000000000000 ..= 9999999999999 => 13,
        10000000000000 ..= 99999999999999 => 14,
        100000000000000 ..= 999999999999999 => 15,
        1000000000000000 ..= 9999999999999999 => 16,
        10000000000000000 ..= 99999999999999999 => 17,
        100000000000000000 ..= 999999999999999999 => 18,
        1000000000000000000 ..= 9999999999999999999 => 19,
        _ => 20,
      }
    }
    
  • 1-// Unrolled div loop
    2-fn digits(mut n: u64) -> usize {
    3- let mut l = 1;
    4- loop {
    5- if n < 10 {
    6- return l;
    7- }
    8- if n < 100 {
    9- return l + 1;
    10- }
    11- if n < 1000 {
    12- return l + 2;
    13- }
    14- if n < 10000 {
    15- return l + 3;
    16- }
    17- n /= 10000;
    18- l += 4;
    1+// Removed loop
    2+fn digits (n: u64) -> usize
    3+{
    4+ match n {
    5+ 0 ..= 9 => 1,
    6+ 10 ..= 99 => 2,
    7+ 100 ..= 999 => 3,
    8+ 1000 ..= 9999 => 4,
    9+ 10000 ..= 99999 => 5,
    10+ 100000 ..= 999999 => 6,
    11+ 1000000 ..= 9999999 => 7,
    12+ 10000000 ..= 99999999 => 8,
    13+ 100000000 ..= 999999999 => 9,
    14+ 1000000000 ..= 9999999999 => 10,
    15+ 10000000000 ..= 99999999999 => 11,
    16+ 100000000000 ..= 999999999999 => 12,
    17+ 1000000000000 ..= 9999999999999 => 13,
    18+ 10000000000000 ..= 99999999999999 => 14,
    19+ 100000000000000 ..= 999999999999999 => 15,
    20+ 1000000000000000 ..= 9999999999999999 => 16,
    21+ 10000000000000000 ..= 99999999999999999 => 17,
    22+ 100000000000000000 ..= 999999999999999999 => 18,
    23+ 1000000000000000000 ..= 9999999999999999999 => 19,
    24+ _ => 20,
    1919 }
    2020 }
Code
Diff
  • char* Hi (void)
    {
      char* ans;
      asprintf(&ans, "Hello World.");
      return ans;
    }
    
  • 11 char* Hi (void)
    22 {
    3- char* ans=malloc(13);
    4- strcpy(ans,"Hello World.");
    3+ char* ans;
    4+ asprintf(&ans, "Hello World.");
    55 return ans;
    66 }
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)