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
  • is_more_then_2 = lambda n: n > 2
    • def is_more_then_2(n):
    • return n > 2
    • is_more_then_2 = lambda n: n > 2
Code
Diff
  • sum_of_numbers = lambda a, b: a + b
    • def sum_of_numbers(a, b):
    • return a + b
    • sum_of_numbers = lambda a, b: a + b

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(' > ')
    • }
Code
Diff
  • function bestCodeEver(a)
      return a == 19 and true or false
    end
    
    • def bestCodeEver():
    • bestNumber = 19
    • return bestNumber
    • function bestCodeEver(a)
    • return a == 19 and true or false
    • end
Test Cases
Diff
  • -- TODO: Replace examples and use TDD by writing your own tests
    local solution = require 'solution'
    describe("solution", function()
      it("test for something", function()
        assert.are.same(true, bestCodeEver(19))
        assert.are.same(false, bestCodeEver(15))
      end)
    end)
    
    • import codewars_test as test
    • # TODO Write tests
    • import solution # or from solution import example
    • # test.assert_equals(actual, expected, [optional] message)
    • @test.describe("Example")
    • def test_group():
    • @test.it("test case")
    • def test_case():
    • test.assert_equals(1 + 1, 2)
    • -- TODO: Replace examples and use TDD by writing your own tests
    • local solution = require 'solution'
    • describe("solution", function()
    • it("test for something", function()
    • assert.are.same(true, bestCodeEver(19))
    • assert.are.same(false, bestCodeEver(15))
    • end)
    • end)

simple solution

Code
Diff
  • #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))
    
    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 + _____;
    }
    • int multiply_and_add_one(int a, int b)
    • {
    • return (a*b)+1+0+0+0+0+0+0+0+0+0+0+0+0+0;
    • #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))
    • 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 + _____;
    • }