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.

Basic Language Features
Fundamentals
Control Flow
Code
Diff
  • def convert_decimal_roman(number: int) -> str:
        try:
            number = int(number)
        except ValueError:
            print("Invalid Input, Value Error")
            return("Invalid Input")
        str = ''
        numDct = {1000: "M",
                  900: "CM",
                  500: "D",
                  400: "CD",
                  100: "C",
                  90: "XC",
                  50: "L",
                  40: "XL",
                  10: "X",
                  9: "IX",
                  5: "V",
                  4: "IV",
                  1: "I"}
        
        decimals = []
        for key, value in numDct.items():
            decimals.append(value * (number // key))
            number %= key
            
        return "".join(decimals)
  • 1def convert_decimal_roman(number):
    1+def convert_decimal_roman(number: int) -> str:
    22 try:
    33 number = int(number)
    44 except ValueError:
    55 print("Invalid Input, Value Error")
    66 return("Invalid Input")
    77 str = ''
    1717 9: "IX",
    1818 5: "V",
    1919 4: "IV",
    2020 1: "I"}
    2121
    22+ decimals = []
    2222 for key, value in numDct.items():
    23 str += value * (number // key)
    24+ decimals.append(value * (number // key))
    2424 number %= key
    2525
    26 return str
    27+ return "".join(decimals)

Recent Moves:

Mathematics
Algorithms
Numbers
Code
Diff
  • from gmpy2 import is_prime as prime_checker
  • 1import re
    2def prime_checker(n):
    3 return re.match(r'^1?$|^(11+?)\1+$', '1' * n) == None
    1+from gmpy2 import is_prime as prime_checker

Recent Moves:

Code
Diff
  • def removeEverySecond(string):
        return string[::2]
  • 1removeEverySecond = lambda string: string[::2]
    1+def removeEverySecond(string):
    2+ return string[::2]
Code
Diff
  • public class FizzBuzz
    {
        public string GetOutput(int number) {
          if (number % 15 == 0) return "FizzBuzz";
          else if (number % 3 == 0) return "Fizz";
          else if (number % 5 == 0) return "Buzz";
          else return number.ToString();
          // Fizz buzz is a popular computer science interview question.  
          // The function above is given a number - if the number is
          // divisible by 3, return "fizz", if it's divisible by 5, 
          // return "buzz", if not divisble by 3 or 5 - return the
          // number itself.
        }
    }
  • 11 public class FizzBuzz
    22 {
    33 public string GetOutput(int number) {
    4 if (number % 15 == 0) {
    5 return "FizzBuzz";
    6 }
    7 else if (number % 3 == 0) {
    8 return "Fizz";
    9 }
    10 else if (number % 5 == 0) {
    11 return "Buzz";
    12 }
    13 else {
    14 return number.ToString();
    15 }
    4+ if (number % 15 == 0) return "FizzBuzz";
    5+ else if (number % 3 == 0) return "Fizz";
    6+ else if (number % 5 == 0) return "Buzz";
    7+ else return number.ToString();
    1616 // Fizz buzz is a popular computer science interview question.
    1717 // The function above is given a number - if the number is
    1818 // divisible by 3, return "fizz", if it's divisible by 5,
    1919 // return "buzz", if not divisble by 3 or 5 - return the
    2020 // number itself.
    2121 }
    2222 }
Code
Diff
  • 4
  • 1function relativeNumbers(a, b) {
    2 let arrOne = [];
    3 let arrTwo = [];
    4 for (let i = 2; i < 10; i++) {
    5 if (a % i === 0 && a !== i) {
    6 arrOne.push(i);
    7 }
    8 if(b % i === 0 && b !== i){
    9 arrTwo.push(i)
    10 }
    11 }
    12 for(let i = 0; i < arrOne.length; i++){
    13 for(let j = 0; j < arrTwo.length; j++){
    14 if(arrOne[i] === arrTwo[j]){
    15 return "non relative"
    16 }else return "relative"
    17 }
    18 }
    19}
    1+4

During development turned out that the draw can end in a way that
a team drawed from the runners-up pot DO NOT have
an eligible opponent in the other pot.
This case is handled and log functions are added to shorten the code.

Code
Diff
  • /*13.Dec.2021. Draw of the UEFA Champions League quarter-finals. 
    This was a joke with a bad software. They had to redraw it. Decided to code a better one.
    
    Rules: there are 16 teams, 8 group-winners in one pot and 8 runners-up in another pot.
    A runner-up team is drawed first. Then it is paired with a group-winner. 
    There are 2 criteria for the opponent:
    it can not go from the same group
    it can not have the same nationality.
    After the pairing, the drawed teams are taken out from their pots before the next pairing.
    
    During development turned out that the draw can end in a way that 
    a team drawed from the runners-up pot DO NOT have 
    an eligible opponent in the other pot.
    This case is handled and log functions are added to shorten the code.*/
    
    
    /*database: 2 arrays of objects*/
    const groupWinners = [
        {
            name: "Manchester City",
            group: "A",
            nationality: "English"
        },
        {
            name: "Liverpool",
            group: "B",
            nationality: "English"
        },
        {
            name: "Ajax Amsterdam",
            group: "C",
            nationality: "Dutch"
        },
        {
            name: "Real Madrid",
            group: "D",
            nationality: "Spanish"
        },
        {
            name: "Bayern Munich",
            group: "E",
            nationality: "German"
        },
        {
            name: "Manchester United",
            group: "F",
            nationality: "English"
        },
        {
            name: "Lille",
            group: "G",
            nationality: "French"
        },
        {
            name: "Juventus",
            group: "H",
            nationality: "Italian"
        }
    ];
    
    const runnersUp = [
        {
            name: "Paris Saint-Germain",
            group: "A",
            nationality: "French"
        },
        {
            name: "Atletico Madrid",
            group: "B",
            nationality: "Spanish"
        },
        {
            name: "Sporting CP",
            group: "C",
            nationality: "Portuguese"
        },
        {
            name: "Internazionale",
            group: "D",
            nationality: "Italian"
        },
        {
            name: "Benfica",
            group: "E",
            nationality: "Portuguese"
        },
        {
            name: "Villarreal",
            group: "F",
            nationality: "Spanish"
        },
        {
            name: "FC Salzburg",
            group: "G",
            nationality: "Austrian"
        },
        {
            name: "Chelsea",
            group: "H",
            nationality: "English"
        }
    ];
    
    /*log function */
    function log(textStr, groupStr, nationalityStr, endStr, teamObj) {
        console.log(
            textStr,
            teamObj.name,
            groupStr,
            teamObj.group,
            nationalityStr,
            teamObj.nationality,
            endStr
        );
    }
    
    /*log the teams */
    console.log("\nWELCOME TO THE DRAW OF THE UEFA CHAMPIONS LEAGUE QUARTER-FINALS!\n");
    console.log("Let's see the teams!\n");
    console.log("Group winners:\n");
    groupWinners.forEach(
        team => {
            log("", " (Group: ", " Nationality: ", ")", team);
        }
    );
    console.log("\nRunners-up:\n");
    runnersUp.forEach(
        team => {
            log("", " (Group: ", " Nationality: ", ")", team);
        }
    );
    
    console.log("\n\nLet's start the draw!\n");
    draw();
    
    function draw() {
        /*arrays containing teams which can be still drawed and an array for the pairings*/
        let groupWinnersToDraw = [...groupWinners];
        let runnersUpToDraw = [...runnersUp];
        let pairings = [];
    
        /*while there are teams to draw */
        while (runnersUpToDraw.length > 0) {
            /*choose a random team from runnersUpToDraw */
            let index = Math.floor(Math.random() * (runnersUpToDraw.length));
            let teamToFace = runnersUpToDraw[index];
            /*updating the runnersUpToDraw array*/
            runnersUpToDraw = runnersUpToDraw
                .slice(0, index)
                .concat(
                    runnersUpToDraw.slice(index + 1, runnersUpToDraw.length)
                );
    
            log("\n\nTeam to face:", " (Group: ", " Nationality: ", ")", teamToFace);
            console.log("\n");
    
            /*selecting the potential opponents */
            let potentialOpponents = groupWinnersToDraw.filter(
                team =>
                    (team.group != teamToFace.group && 
                    team.nationality != teamToFace.nationality)
            );
            if (potentialOpponents.length == 0) {
                potentialOpponents.push(
                    `No eligible opponent for ${teamToFace.name}! We have to re-draw!`
                );
            }
    
            if (typeof potentialOpponents[0] == "string") {
                console.log(potentialOpponents[0]);
                return;
            }
    
            console.log("Potential opponents:\n");
            potentialOpponents.forEach(
                team => 
                    log("", " (Group: ", " Nationality: ", ")", team)
            );
    
            /*choose a random team from potentialOpponents */
            let anotherIndex = Math.floor(Math.random() * (potentialOpponents.length));
            let opponent = potentialOpponents[anotherIndex];
            log("\n\nThe opponent is:", " (Group: ", " Nationality: ", ")", opponent);
            /*updating the groupWinnersToDraw array*/
            let yetAnotherIndex = 0;
            for (let i = 0; i < groupWinnersToDraw.length; i++) {
                if (groupWinnersToDraw[i].name == opponent.name) {
                    yetAnotherIndex = i;
                }
            }
            groupWinnersToDraw = groupWinnersToDraw
                .slice(0, yetAnotherIndex)
                .concat(
                    groupWinnersToDraw.slice(yetAnotherIndex + 1, groupWinnersToDraw.length)
                );
    
            if (runnersUpToDraw.length > 0) {    
                console.log("\n\nRemaining group-winners:\n")
                groupWinnersToDraw.forEach(
                    team => {
                        log("", " (Group: ", " Nationality: ", ")", team);
                    }
                );
    
                console.log("\nRemaining runners-up:\n");
                runnersUpToDraw.forEach(
                    team => {
                        log("", " (Group: ", " Nationality: ", ")", team);
                    }
                );
            }
    
            /*save the pairings */
            let drawing = [];
            drawing.push(teamToFace, opponent);
            pairings.push(drawing);
        }
    
        /*log the draw */
        console.log("\nTHE QUARTER-FINALS: \n");
        pairings.forEach(
            pair => {
                console.log(
                    pair[0].name,
                    " (Group: ",
                    pair[0].group, 
                    " Nationality: ",
                    pair[0].nationality, 
                    ")",
                    "   vs   ",
                    pair[1].name, 
                    " (Group: ",
                    pair[1].group, 
                    " Nationality: ",
                    pair[1].nationality,
                    ")"
                );
            }
        );
    }
    
    
  • 1/*2021.12.13. Draw of the UEFA Champions League quarter-finals.
    2This was a joke with a bad software. Decided to code a better one.
    1+/*13.Dec.2021. Draw of the UEFA Champions League quarter-finals.
    2+This was a joke with a bad software. They had to redraw it. Decided to code a better one.
    33
    4There are 16 teams, 8 group-winners and 8 runners-up.
    5A runner-up team is drawed first from the 8. It is paired with a gruop-winner.
    6There are 2 rules:
    4+Rules: there are 16 teams, 8 group-winners in one pot and 8 runners-up in another pot.
    5+A runner-up team is drawed first. Then it is paired with a group-winner.
    6+There are 2 criteria for the opponent:
    77 it can not go from the same group
    88 it can not have the same nationality.
    9After the pairing, the paired teams are taken out of the list before the next draw.
    10*/
    9+After the pairing, the drawed teams are taken out from their pots before the next pairing.
    1111
    12/*database: 2 arrays of objects*/
    11+During development turned out that the draw can end in a way that
    12+a team drawed from the runners-up pot DO NOT have
    13+an eligible opponent in the other pot.
    14+This case is handled and log functions are added to shorten the code.*/
    15+
    16+
    17+/*database: 2 arrays of objects*/
    1313 const groupWinners = [
    1414 {
    1515 name: "Manchester City",
    1616 group: "A",
    1717 nationality: "English"
    1818 },
    1919 {
    2020 name: "Liverpool",
    2121 group: "B",
    2222 nationality: "English"
    2323 },
    9494 group: "H",
    9595 nationality: "English"
    9696 }
    9797 ];
    9898
    99console.log("\n");
    100console.log("WELCOME IN THE DRAW OF THE UEFA CHAMPIONS LEAGUE QUARTER-FINALS!");
    101console.log("\n");
    102
    103/*arrays containing teams which can be still drawed and an array for the pairings*/
    104let groupWinnersToDraw = [...groupWinners];
    105let runnersUpToDraw = [...runnersUp];
    106let pairings = [];
    107
    108/*while there are teams to draw */
    109while (runnersUpToDraw.length > 0) {
    110 /*choose a random team from runnersUpToDraw */
    111 let index = Math.floor(Math.random()*(runnersUpToDraw.length));
    112 let teamToFace = runnersUpToDraw[index];
    113 /*updating the runnersUpToDraw array*/
    114 runnersUpToDraw = runnersUpToDraw.slice(0, index).concat(runnersUpToDraw.slice(index+1, runnersUpToDraw.length));
    115
    116 console.log("Team to face:", teamToFace.name, teamToFace.group, teamToFace.nationality);
    117 console.log("\n");
    118
    119 /*selecting the potential opponents */
    120 let potentialOpponents = groupWinnersToDraw.filter(team =>
    121 (team.group != teamToFace.group && team.nationality != teamToFace.nationality)
    104+/*log function */
    105+function log(textStr, groupStr, nationalityStr, endStr, teamObj) {
    106+ console.log(
    107+ textStr,
    108+ teamObj.name,
    109+ groupStr,
    110+ teamObj.group,
    111+ nationalityStr,
    112+ teamObj.nationality,
    113+ endStr
    122122 );
    123 console.log("Potential opponents:")
    124 potentialOpponents.forEach(team => console.log(team.name, team.group, team.nationality));
    125 console.log("\n");
    126
    127 /*choose a random team from potentialOpponents */
    128 let anotherIndex = Math.floor(Math.random()*(potentialOpponents.length));
    149 pairings.push(drawing);
    150150 }
    151151
    152/*log the draw */
    117+/*log the teams */
    118+console.log("\nWELCOME TO THE DRAW OF THE UEFA CHAMPIONS LEAGUE QUARTER-FINALS!\n");
    119+console.log("Let's see the teams!\n");
    120+console.log("Group winners:\n");
    121+groupWinners.forEach(
    122+ team => {
    123+ log("", " (Group: ", " Nationality: ", ")", team);
    124+ }
    125+);
    126+console.log("\nRunners-up:\n");
    127+runnersUp.forEach(
    128+ team => {
    153153
    154console.log("THE QUARTER-FINALS: ");
    155console.log("\n");
    156pairings.forEach(pair => {
    157 console.log(pair[0].name, pair[0].group, pair[0].nationality, " vs ",
    158 pair[1].name, pair[1].group, pair[1].nationality );
    159});
    149+ .slice(0, index)
    150+ .concat(
    151+ runnersUpToDraw.slice(index + 1, runnersUpToDraw.length)
    152+ );
    153+
    154+ log("\n\nTeam to face:", " (Group: ", " Nationality: ", ")", teamToFace);
    155+ console.log("\n");
    156+
    157+ /*selecting the potential opponents */
    158+ let potentialOpponents = groupWinnersToDraw.filter(
    159+ team =>
    160+ (team.group != teamToFace.group &&
    161+ team.nationality != teamToFace.nationality)
    162+ );
    163+ if (potentialOpponents.length == 0) {
    164+ potentialOpponents.push(
    165+ `No eligible opponent for ${teamToFace.name}! We have to re-draw!`
    166+ );
    167+ }
    168+
    169+ if (typeof potentialOpponents[0] == "string") {
    170+ console.log(potentialOpponents[0]);
    171+ return;
    172+ }
    173+
    174+ console.log("Potential opponents:\n");
    175+ potentialOpponents.forEach(
    176+ team =>
    177+ log("", " (Group: ", " Nationality: ", ")", team)
    178+ );
    179+
    180+ /*choose a random team from potentialOpponents */
    181+ let anotherIndex = Math.floor(Math.random() * (potentialOpponents.length));
    182+ let opponent = potentialOpponents[anotherIndex];
    183+ log("\n\nThe opponent is:", " (Group: ", " Nationality: ", ")", opponent);
    184+ /*updating the groupWinnersToDraw array*/
    185+ let yetAnotherIndex = 0;
    186+ for (let i = 0; i < groupWinnersToDraw.length; i++) {
    187+ if (groupWinnersToDraw[i].name == opponent.name) {
    188+ yetAnotherIndex = i;
    189+ }
    190+ }
    191+ groupWinnersToDraw = groupWinnersToDraw
    192+ .slice(0, yetAnotherIndex)
    193+ .concat(
    194+ groupWinnersToDraw.slice(yetAnotherIndex + 1, groupWinnersToDraw.length)
    195+ );
    196+
    197+ if (runnersUpToDraw.length > 0) {
    198+ console.log("\n\nRemaining group-winners:\n")
    199+ groupWinnersToDraw.forEach(
    200+ team => {
    201+ log("", " (Group: ", " Nationality: ", ")", team);
    202+ }
    203+ );
    204+
    205+ console.log("\nRemaining runners-up:\n");
    206+ runnersUpToDraw.forEach(
    207+ team => {
    208+ log("", " (Group: ", " Nationality: ", ")", team);
    209+ }
    210+ );
    211+ }
    212+
    213+ /*save the pairings */
    214+ let drawing = [];
    215+ drawing.push(teamToFace, opponent);
    216+ pairings.push(drawing);
    217+ }
    218+
    219+ /*log the draw */
    220+ console.log("\nTHE QUARTER-FINALS: \n");
    221+ pairings.forEach(
    222+ pair => {
    223+ console.log(
    224+ pair[0].name,
    225+ " (Group: ",
    226+ pair[0].group,
    227+ " Nationality: ",
    228+ pair[0].nationality,
    229+ ")",
    230+ " vs ",
    231+ pair[1].name,
    232+ " (Group: ",
    233+ pair[1].group,
    234+ " Nationality: ",
    235+ pair[1].nationality,
    236+ ")"
    237+ );
    238+ }
    239+ );
    240+}
    160160