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

Removed redundant zeroing.

Code
Diff
  • global double_multiplication
    section .text
    double_multiplication:
    mov        rax,rdi
    mul        rsi
    ret
    
    • global double_multiplication
    • section .text
    • double_multiplication:
    • xor rdx,rdx
    • mov rax,rdi
    • mul rsi
    • ret

Macro on conditional moves (only one here though).

It works in theory (probably will fail if %2 is rax).

Code
Diff
  • ; A macro with two parameters
    ; Implements actual int max(int a, int b)
    %macro _max 2 
      mov rax, %1
      cmp %2, %1 ; compare a ?= b
      cmovg rax, %2
      ret
    %endmacro
    
    section .text
    global max ; declaring int max(int a, int b)
    
    max:            
      _max rdi, rsi ; using inner _max macro 
      ret
    
    • ; A macro with two parameters
    • ; Implements actual int max(int a, int b)
    • %macro _max 2
    • mov rax, %1
    • cmp %2, %1 ; compare a ?= b
    • jle _lower ; jump to lower if a <= b
    • jmp _greater ; jump to greater if a > b
    • _lower:
    • mov rax, %1 ; assgine rax to b
    • jmp _end ; end program
    • _greater:
    • mov rax, %2 ; assgine rax to a
    • _end:
    • cmovg rax, %2
    • ret
    • %endmacro
    • section .text
    • global max ; declaring int max(int a, int b)
    • max:
    • _max rdi, rsi ; using inner _max macro
    • ret

Made a branchless variant (but now there is a data dependency).

Extended tests; added transformation outputs.

Code
Diff
  • section    .text
    global     changeCase
    
    changeCase:
      mov      ax, di  ; load default answer (unmodified character) to ax
      
      mov      cx, di  
      xor      cx, 32  ; load modified answer (with changed case) to cx
      
      and      di, 95  ; normalize value (bring everything to upper case (destroys non alpha characters, but it is irrelevant))
      sub      di, 65
      cmp      di, 26  ; check if it is an alphabetical symbol (in range 65-90,97-122)
      
      cmovb    ax, cx  ; if it is - replace the answer by the modified one (with changed case)
      ret
    
    • section .text
    • global changeCase
    • changeCase:
    • mov ax,di
    • sub di,0x41 ; di -= 'A'
    • cmp di,0x7a-0x41 ; 'z' - 'A'
    • ja _
    • sub di,0x5a-0x41 ; di -= 'Z' - 'A'
    • cmp di,0x61-0x5a ; 'a' - 'Z'
    • jb _
    • xor ax,0x20
    • _:
    • mov ax, di ; load default answer (unmodified character) to ax
    • mov cx, di
    • xor cx, 32 ; load modified answer (with changed case) to cx
    • and di, 95 ; normalize value (bring everything to upper case (destroys non alpha characters, but it is irrelevant))
    • sub di, 65
    • cmp di, 26 ; check if it is an alphabetical symbol (in range 65-90,97-122)
    • cmovb ax, cx ; if it is - replace the answer by the modified one (with changed case)
    • ret
Code
Diff
  • const revstr = str => [...str].reverse().join``
    • const revstr = str => [...str].reverse().join('')
    • const revstr = str => [...str].reverse().join``
Fundamentals
Numbers
Data Types
Integers
Code
Diff
  • class Odd
      def odd(n)
        n.odd?
      end
    end
    • class Odd
    • def odd(n)
    • n % 2 == 1
    • n.odd?
    • end
    • end

Fixed indentations, spacings.

Changed code a bit.

Code
Diff
  • function binarySearch(numbers, element, left = 0, right = numbers.length-1)
    {
      // time complexity is log(n) where n is an array length; it excecutes way faster than a linear search.
      if(left > right) return -1;
      
      // get average and cast it to i32
      // bit shift can be used depending on preference
      //   let pivot = (left + right) >> 1;
      let pivot = (left + right) / 2 | 0;
      
      if(numbers[pivot] === element) return pivot;
      if(numbers[pivot] > element) return binarySearch(numbers, element, left, pivot-1);
      return binarySearch(numbers, element, pivot+1, right);
    }
    
    • function binarySearch(numbers, element, left = 0, right = numbers.length-1) {
    • //time complexity is log(n) it excecutes very fast than linear search n=arraylength;
    • if(left>right) return -1;
    • function binarySearch(numbers, element, left = 0, right = numbers.length-1)
    • {
    • // time complexity is log(n) where n is an array length; it excecutes way faster than a linear search.
    • if(left > right) return -1;
    • let pivot =Math.floor((left+right)/2)
    • // get average and cast it to i32
    • // bit shift can be used depending on preference
    • // let pivot = (left + right) >> 1;
    • let pivot = (left + right) / 2 | 0;
    • if(numbers[pivot]===element) return pivot
    • if(numbers[pivot]>element) return binarySearch(numbers,element,left,pivot-1)
    • return binarySearch(numbers,element,pivot+1,right)
    • }
    • if(numbers[pivot] === element) return pivot;
    • if(numbers[pivot] > element) return binarySearch(numbers, element, left, pivot-1);
    • return binarySearch(numbers, element, pivot+1, right);
    • }