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

Ok now if you enter binary it will convert the 'whoever' name into binary string
Am i going too far ?

Code
Diff
  • var numberToBinaryArray = (number) => {
    	var result = [];
    	while(number > 0){
    		var bit = Math.floor(number % 2) != 0 ? 1 : 0;
    		result.unshift(bit)
    		number = Math.floor(number / 2);
    	}
    	while(result.length != 8)
    		result.unshift(0);
    	return result;
    }
    
    var txtToBin = (text) => {
    	var result = [];
    	for(var i = 0; i < text.length; i++){
    		var binaryArr = numberToBinaryArray(text.charCodeAt(i));
    		result = result.concat(binaryArr);
    	}
    	return result.join("");
    }
    
    let helloLangs = {
      english: "hello",
      pirate: "yar",
      binary: txtToBin('hello')
    }
    
    const hello = (whoever, lang="english") => `${helloLangs[lang]} ${lang == 'binary' ? txtToBin(whoever) : whoever}`;
    • var numberToBinaryArray = (number) => {
    • var result = [];
    • while(number > 0){
    • var bit = Math.floor(number % 2) != 0 ? 1 : 0;
    • result.unshift(bit)
    • number = Math.floor(number / 2);
    • }
    • while(result.length != 8)
    • result.unshift(0);
    • return result;
    • }
    • var txtToBin = (text) => {
    • var result = [];
    • for(var i = 0; i < text.length; i++){
    • var binaryArr = numberToBinaryArray(text.charCodeAt(i));
    • result = result.concat(binaryArr);
    • }
    • return result.join("");
    • }
    • let helloLangs = {
    • english: "hello",
    • pirate: "yar"
    • pirate: "yar",
    • binary: txtToBin('hello')
    • }
    • const hello = (whoever, lang="english") => `${helloLangs[lang]} ${whoever}`;
    • const hello = (whoever, lang="english") => `${helloLangs[lang]} ${lang == 'binary' ? txtToBin(whoever) : whoever}`;
Strings
Data Types

Return the last character from a string.

In Rust return an Option<char>.

Code
Diff
  • fn last_char(string: &str) -> Option<char> {
        string.chars().last()
    }
    • fn last_char(string: &str) -> Option<char> {
    • string.chars().rev().next()
    • string.chars().last()
    • }

?

Code
Diff
  • from math import hypot as hypotenuse
        
    • from math import *
    • def hypotenuse(a, b): return hypot(a,b)
    • from math import hypot as hypotenuse
Code
Diff
  • from datetime import datetime
    
    def password(p):
        a = datetime.now()
        if not p.isdigit(): 
            return "Please, don't print letters.\nReset the program."
        return "ACCESS CONFIRMED" if p == f"{a.hour}{a.minute}" else "ACCESS DENIED"              
    
    # Outside the codewar you can use the lines below.
    # b = input("Please, print the password here (without letters!): ")
    # print(password(b))
    • from datetime import datetime
    • def password(p):
    • a = datetime.now()
    • c = str(a.hour) + str(a.minute)
    • if p.isdigit():
    • if(p == c):
    • return("ACCESS CONFIRMED")
    • else:
    • return("ACCESS DENIED")
    • else:
    • return("Please, don't print letters.
    • Reset the program.")
    • if not p.isdigit():
    • return "Please, don't print letters.
    • Reset the program."
    • return "ACCESS CONFIRMED" if p == f"{a.hour}{a.minute}" else "ACCESS DENIED"
    • # Outside the codewar you can use the lines below.
    • # b = input("Please, print the password here (without letters!): ")
    • # print(password(b))

Return addresses are just normal stack entries, and nasm lets you jump to an address from a register.

Code
Diff
  • global stack_push, stack_pop, stack_peek ; , stack_is_empty
    section .text
    stack_push:
      xchg rsi, [rsp]
      jmp rsi
    stack_pop:
      pop rsi
      pop rax
      jmp rsi
    stack_peek:
      pop rsi
      mov rax, [rsp]
      jmp rsi
    
    • global stack_push, stack_pop, stack_peek ; , stack_is_empty
    • section .text
    • stack_push:
    • push rsi
    • ret
    • xchg rsi, [rsp]
    • jmp rsi
    • stack_pop:
    • pop rsi
    • ret
    • pop rax
    • jmp rsi
    • stack_peek:
    • pop rsi
    • push rsi
    • ret
    • mov rax, [rsp]
    • jmp rsi