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
Code
Diff
  • "pick four digit number"
    "scatter the numbers randomly"
    "select number"
    "then what"
    "then we redo the process and spam emails with the result"
    "Hahaha ridiculous kumite"
    • "pick four digit number"
    • "scatter the numbers randomly"
    • "select number"
    • "then what"
    • "then we redo the process and spam emails with the result"
    • "then we redo the process and spam emails with the result"
    • "Hahaha ridiculous kumite"
Code
Diff
  • typedef unsigned int uint;
    
    uint multiply_and_add_one(uint num1, uint num2) {
      /* I know we don't need parantheses here because of pemdas but I don't trust math >:( */
      return (num1 * num2) + 1;
    }
    • #define _____ 256 - 255 + 0
    • #define _(A,B)((A)*(B)+_____)
    • #define ____(a,b)({register int __x=(a);register int __y=(b);__x*__y+_____;})
    • #define ___(A)((A))
    • #define q(x,y)((x)<<(y))
    • #define w(x,y)((x)>>(y))
    • typedef unsigned int uint;
    • long long unsigned int
    • multiply_and_add_one(
    • long long unsigned int
    • a,
    • long long unsigned int
    • b)
    • {return ___(____(___(___((a))),___(___((b)))));}
    • int iorejgior(long long unsigned int a, long long unsigned int b) { long long unsigned int asd = _____-1;
    • while (b)
    • {if (b & _____) asd += a;
    • a <<= _____;
    • b >>= _____;} return asd + _____;
    • uint multiply_and_add_one(uint num1, uint num2) {
    • /* I know we don't need parantheses here because of pemdas but I don't trust math >:( */
    • return (num1 * num2) + 1;
    • }
Code
Diff
  • above_two = lambda number: number > 2
    • is_more_then_2 = lambda n: n > 2
    • above_two = lambda number: number > 2
Code
Diff
  • int sum_of_numbers(int a, int b)
    {
      int sum=a+b;
      return sum;
    }
    • int sum_of_numbers(int a, int b)
    • {
    • return a + b;
    • int sum=a+b;
    • return sum;
    • }
Code
Diff
  • def count():
        broj_samoglasnika=0
        for slovo in recenica:
            if slovo in "AEIOUaeiou":
                brojac+=1
        return broj_samoglasnika
    
        print("Broj samoglasnika u riječi je:", broj_samoglasnika)
    • def count():
    • #code
    • # Ispis rezultata
    • broj_samoglasnika=0
    • for slovo in recenica:
    • if slovo in "AEIOUaeiou":
    • brojac+=1
    • return broj_samoglasnika
    • print("Broj samoglasnika u riječi je:", broj_samoglasnika)

Refactored the code for better readability, consistency and modularity:

  • Changed the behaviour of findTheBomb() to throw error when called with an empty array, as in the original request. (Returning a string as error message made it hard to asses the result of the function programmatically.)
  • Changed the behaviour of findTheBomb() to return empty array when no bomb is found. This is to make the return value more predictable.
  • Introduced the box() and withBomb() functions to make the test cases (and debugging) easier to construct and more readable.
  • Abstracted the main function into more generic functions to help readability, reusability and testing.
  • Simplified the names for better readability.
Code
Diff
  • export interface Box {
      code: string
      bomb?: boolean
      boxes?: Box[]
    }
    
    
    /**
     * Creates a box with optional boxes inside
     */
    export function box(code: string, boxes?: Box[]): Box {
      return boxes ? { code, boxes } : { code }
    }
    
    
    /**
     * Returns a copy of a box with bomb
     */
    export function withBomb(box: Box) {
      return { ...box, bomb: true }
    }
    
    
    /**
     * Finds the bomb in a box
     */
    export function pathToBomb(box: Box, path: string[] = []): string[] {
      const newPath = [...path, box.code]
      
      if (box.bomb) return newPath
      if (!Array.isArray(box.boxes)) return []
      return traverseBoxes(box.boxes, newPath)
    }
    
    
    /**
     * Finds the bomb in an array of boxes
     */
    export function traverseBoxes(boxes: Box[], path: string[] = []): string[] {
      return boxes.reduce((result: string[], box) => (
        result.length > 0 ? result : pathToBomb(box, path)
      ), [])
    }
    
    
    /**
     * The main function
     */
    export function findTheBomb(boxes: Box[]): string {
      if (boxes.length === 0) throw new Error('Empty array')
      return traverseBoxes(boxes).join(' > ')
    }
    
    • interface ListOfBoxes {
    • export interface Box {
    • code: string
    • bomb?: boolean
    • boxes?: ListOfBoxes[]
    • boxes?: Box[]
    • }
    • export function findTheBomb (listOfBoxes: ListOfBoxes [], path: string[] = []): string | null {
    • if (!listOfBoxes.length) {
    • return "No Boxes No Bomb!"
    • }
    • for (const box of listOfBoxes) {
    • const newPath = [...path, box.code]
    • if (box.bomb) {
    • return newPath.join(" > ")
    • }
    • if (box.boxes) {
    • const found = findTheBomb(box.boxes, newPath)
    • if (found) {
    • return found
    • }
    • }
    • }
    • /**
    • * Creates a box with optional boxes inside
    • */
    • export function box(code: string, boxes?: Box[]): Box {
    • return boxes ? { code, boxes } : { code }
    • }
    • /**
    • * Returns a copy of a box with bomb
    • */
    • export function withBomb(box: Box) {
    • return { ...box, bomb: true }
    • }
    • /**
    • * Finds the bomb in a box
    • */
    • export function pathToBomb(box: Box, path: string[] = []): string[] {
    • const newPath = [...path, box.code]
    • return null
    • if (box.bomb) return newPath
    • if (!Array.isArray(box.boxes)) return []
    • return traverseBoxes(box.boxes, newPath)
    • }
    • const listBoxes1: ListOfBoxes [] = [
    • {
    • code: "B1",
    • boxes: [
    • {
    • code: "B1.1"
    • },
    • {
    • code: "B1.2"
    • }
    • ]
    • },
    • {
    • code: "B2",
    • boxes: [
    • {
    • code: "B2.1",
    • boxes: [
    • {
    • code: "B2.1.1"
    • },
    • {
    • code: "B2.1.2",
    • bomb: true
    • }
    • ]
    • },
    • {
    • code: "B2.2"
    • }
    • ]
    • }
    • ]
    • const listBoxes2: ListOfBoxes [] = [
    • {
    • "code": "B1.2",
    • "boxes": [
    • {
    • "code": "B1.2.2",
    • "boxes": [
    • {
    • "code": "B1.2.2.6"
    • }
    • ]
    • },
    • {
    • "code": "B1.2.7"
    • },
    • {
    • "code": "B1.2.4"
    • },
    • {
    • "code": "B1.2.0"
    • },
    • {
    • "code": "B1.2.9",
    • "boxes": [
    • {
    • "code": "B1.2.9.0",
    • "bomb": true,
    • }
    • ]
    • }
    • ]
    • },
    • {
    • "code": "B2.8",
    • "boxes": [
    • {
    • "code": "B2.8.0"
    • },
    • {
    • "code": "B2.8.7"
    • },
    • {
    • "code": "B2.8.6"
    • },
    • {
    • "code": "B2.8.3"
    • }
    • ]
    • },
    • {
    • "code": "B3.6",
    • "boxes": [
    • {
    • "code": "B3.6.5"
    • },
    • {
    • "code": "B3.6.7",
    • "boxes": [
    • {
    • "code": "B3.6.7.9"
    • }
    • ]
    • }
    • ]
    • }
    • ]
    • const listBoxes3: ListOfBoxes [] = [
    • {
    • "code": "B1.6",
    • "boxes": [
    • {
    • "code": "B1.6.9"
    • },
    • {
    • "code": "B1.6.2"
    • }
    • ]
    • },
    • {
    • "code": "B2.4",
    • "boxes": [
    • {
    • "code": "B2.4.0"
    • },
    • {
    • "code": "B2.4.3",
    • "boxes": [
    • {
    • "code": "B2.4.3.9",
    • "bomb": true
    • }
    • ]
    • },
    • {
    • "code": "B2.4.7"
    • }
    • ]
    • }
    • ]
    • findTheBomb([])
    • findTheBomb(listBoxes1);
    • findTheBomb(listBoxes2);
    • findTheBomb(listBoxes3);
    • /**
    • * Finds the bomb in an array of boxes
    • */
    • export function traverseBoxes(boxes: Box[], path: string[] = []): string[] {
    • return boxes.reduce((result: string[], box) => (
    • result.length > 0 ? result : pathToBomb(box, path)
    • ), [])
    • }
    • /**
    • * The main function
    • */
    • export function findTheBomb(boxes: Box[]): string {
    • if (boxes.length === 0) throw new Error('Empty array')
    • return traverseBoxes(boxes).join(' > ')
    • }