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
  • public class BiggerNum{
    
      /**
       * @param a integer of param1
       * @param b integer of param2
       * @return the bigger integer of a and b
       * If a equals b, eiter one is acceptance
       */
      public static int compare(int a, int b) {
        return a >= b ? a : b;
      }
    }
    • public class BiggerNum{
    • /**
    • * @param a integer of param1
    • * @param b integer of param2
    • * @return the bigger integer of a and b
    • * If a equals b, eiter one is acceptance
    • */
    • public static int compare(int a, int b) {
    • if(a > b){
    • return a;
    • }else{
    • return b;
    • }
    • return a >= b ? a : b;
    • }
    • }
Code
Diff
  • from operator import add
    print(add)
    • from operator import add
    • from operator import add
    • print(add)
Algorithms
Logic
Code
Diff
  • getDividors = n => Array.from({length: n}, (e, i) => n % ++i ? i : 0).filter(e => e)
    • const getDividors = (n, result = []) => {
    • for (let i = 1; i <= Math.floor(Math.sqrt(n)); i++)
    • if (n % i === 0) { result.push(i); if (n / i !== i) result.push(n / i) }
    • return result; // output array won't be sorted
    • }
    • getDividors = n => Array.from({length: n}, (e, i) => n % ++i ? i : 0).filter(e => e)
Code
Diff
  • def add(a,b):
        param1 = a
        param2 = b
        return param1+param2
    • def add(a,b):
    • return a+b
    • param1 = a
    • param2 = b
    • return param1+param2

My version with few improvements.

Code
Diff
  • #include <string>
    
    bool hasCapital(const std::string& password)
    {
        bool result = false;
        for(auto symbol : password)
        {
            if(symbol >= 'A' && symbol <= 'Z')
            {
                result = true;
                break;
            }
        }
        return result;
    }
    
    bool hasSpecial(const std::string& password)
    {  
        bool result = false;
        
        const std::string specials("!\"#$%&'()*+'-./;:<>=?");
        for(auto spec : specials)
        {
            if(password.find(spec) != -1)
            {
                result = true;
                break;
            }
        }    
        return result;
    }
    
    bool hasDigit(const std::string& password)
    {
        bool result = false;
        for(auto symbol : password)
        {
            if(symbol >= '0' && symbol <= '9')
            {
                result = true;
                break;
            }
        }
        return result;
    }
    
    bool isLongPassword(const std::string& password)
    {
        return password.length() > 7;
    }
    
    bool testPassword(const std::string& password)
    {
      bool cap = hasCapital(password);
      bool spec = hasSpecial(password);
      bool digit = hasDigit(password);
      bool number = isLongPassword(password);
      
      return cap && spec && digit && number;
    }
    • #include <string>
    • bool hasCapital(std::string password)
    • bool hasCapital(const std::string& password)
    • {
    • for(int i=0; i < password.length(); i++)
    • {
    • if (password[i] > 64 && password[i] < 91)
    • bool result = false;
    • for(auto symbol : password)
    • {
    • return true;
    • if(symbol >= 'A' && symbol <= 'Z')
    • {
    • result = true;
    • break;
    • }
    • }
    • }
    • return false;
    • return result;
    • }
    • bool hasSpecial(std::string password)
    • bool hasSpecial(const std::string& password)
    • {
    • char temp;
    • for(int i=0;i<password.length();i++)
    • {
    • temp = password[i];
    • if ((temp > 32 && temp < 48) || (temp > 57 && temp < 64))
    • bool result = false;
    • const std::string specials("!\"#$%&'()*+'-./;:<>=?");
    • for(auto spec : specials)
    • {
    • return true;
    • if(password.find(spec) != -1)
    • {
    • result = true;
    • break;
    • }
    • }
    • return result;
    • }
    • bool hasDigit(const std::string& password)
    • {
    • bool result = false;
    • for(auto symbol : password)
    • {
    • if(symbol >= '0' && symbol <= '9')
    • {
    • result = true;
    • break;
    • }
    • }
    • }
    • return false;
    • return result;
    • }
    • bool isLongPassword(std::string password)
    • bool isLongPassword(const std::string& password)
    • {
    • return password.length() > 7;
    • return password.length() > 7;
    • }
    • bool testPassword(std::string password)
    • bool testPassword(const std::string& password)
    • {
    • bool cap = hasCapital(password);
    • bool spec = hasSpecial(password);
    • bool digit = hasDigit(password);
    • bool number = isLongPassword(password);
    • //provide final answer
    • if (cap && number && spec)
    • {
    • return true;
    • }
    • else
    • {
    • return false;
    • }
    • return cap && spec && digit && number;
    • }

Started with 3, because why waste 2 loops on answers you know aren't correct.

Code
Diff
  • function test(n) {
      let sum=0;
      for (let i=3; i<n; i++){
        if ((i%3==0) || (i%5==0)){
        sum+=i;
        }
      }
       return sum;
    }
    • //if you have any Suggestion or noticed a mistake in my code ...tell me...i would need that...
    • function test(n) {
    • var sum=0;
    • for (i=1; i<n; i++){
    • let sum=0;
    • for (let i=3; i<n; i++){
    • if ((i%3==0) || (i%5==0)){
    • sum+=i;
    • }
    • }
    • return sum;
    • }

Use STL algorithms, take vector arguments by constant reference and functors by their exact type to avoid overhead of std::function.

Code
Diff
  • #include <numeric>
    
    using namespace std;
    
    template<class F, class T, class U = decltype(std::declval<F>()(std::declval<T>()))> vector<U> vectorMap(const vector<T>& v, F f) {
      vector<U> result (v.size());
      std::transform(v.begin(), v.end(), result.begin(), std::move(f));
      return result;
    }
    template<class F, class T> vector<T> vectorFilter(const vector<T>& v, F f) {
      vector<T> result;
      std::copy_if(v.begin(), v.end(), std::back_inserter(result), std::move(f));
      return result;
    }
    template<class F, class T, class U> U vectorReduce(const vector<T>& v, F f, U u) {
      return std::accumulate(v.begin(), v.end(), u, std::move(f));
    }
    • #include <numeric>
    • using namespace std;
    • template<class T, class U> vector<U> vectorMap(vector<T> v, function<U (T)> f) {
    • size_t size = v.size();
    • vector<U> result (size);
    • for (size_t i = 0; i < size; i++) result[i] = f(v[i]);
    • template<class F, class T, class U = decltype(std::declval<F>()(std::declval<T>()))> vector<U> vectorMap(const vector<T>& v, F f) {
    • vector<U> result (v.size());
    • std::transform(v.begin(), v.end(), result.begin(), std::move(f));
    • return result;
    • }
    • template<class T> vector<T> vectorFilter(vector<T> v, function<bool (T)> f) {
    • template<class F, class T> vector<T> vectorFilter(const vector<T>& v, F f) {
    • vector<T> result;
    • for (size_t i = 0; i < v.size(); i++) if (f(v[i])) result.push_back(v[i]);
    • std::copy_if(v.begin(), v.end(), std::back_inserter(result), std::move(f));
    • return result;
    • }
    • template<class T, class U> U vectorReduce(vector<T> v, function<U (U, T)> f, U u) {
    • U result = u;
    • for (size_t i = 0; i < v.size(); i++) result = f(result, v[i]);
    • return result;
    • template<class F, class T, class U> U vectorReduce(const vector<T>& v, F f, U u) {
    • return std::accumulate(v.begin(), v.end(), u, std::move(f));
    • }
Code
Diff
  • class Stack {  // Just to hide the use of array implementation
      constructor() {
        this._items = [];
      }
      push(data) {
        this._items.push(data);
      }
      pop() {
        return this._items.pop();
      }
      
      get length() {
        return this._items.length;
      }
    }
    
    class Queue {
      constructor() {
        this._stack = new Stack();
      }
      enqueue(data) {
        this._stack.push(data);
      }
      dequeue() {
        if (this._stack.length === 1)
          return this._stack.pop();
        else {
          var tmp = this._stack.pop(), result = this.dequeue();
          this.enqueue(tmp);
          return result;
        }
      }
    }
    • class Stack { // Just to hide the use of array implementation
    • constructor() {
    • this._items = [];
    • }
    • push(data) {
    • this._items.push(data);
    • }
    • pop() {
    • return this._items.pop();
    • }
    • length() {
    • get length() {
    • return this._items.length;
    • }
    • }
    • class Queue {
    • constructor() {
    • this._stack = new Stack();
    • }
    • enqueue(data) {
    • this._stack.push(data);
    • }
    • dequeue() {
    • if (this._stack.length() === 1)
    • if (this._stack.length === 1)
    • return this._stack.pop();
    • else {
    • var tmp = this._stack.pop(), result = this.dequeue();
    • this.enqueue(tmp);
    • return result;
    • }
    • }
    • }

A structure to allow new languages to be added.

Code
Diff
  • // Declare new languages here and map them in parseGreeting() function
    const GREET_LANG = {
      ENGLISH: 0,
      PIRATE: 1,
      BINARY: 2
    }
    
    function numberToBinaryArray(number) {
    	let result = [];
    	while(number > 0){
    		let 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;
    }
    
    function txtToBin(text) {
    	let result = [];
    	for(let character of text){
    		let binaryArr = numberToBinaryArray(character.charCodeAt());
    		result = result.concat(binaryArr);
    	}
    	return result.join("");
    }
    
    function parseGreeting(lang) {
      switch(lang){
        case GREET_LANG.PIRATE:
          return 'yar';
        case GREET_LANG.BINARY:
          return txtToBin('hello');
        default:
          return 'hello';
      }
    }
    
    
    const parseWhoever = (whoever, lang) => lang == GREET_LANG.BINARY ? txtToBin(whoever) : whoever;
    
    const hello = (whoever, lang=GREET_LANG.ENGLISH) => `${parseGreeting(lang)} ${parseWhoever(whoever, lang)}`;
    • var numberToBinaryArray = (number) => {
    • var result = [];
    • // Declare new languages here and map them in parseGreeting() function
    • const GREET_LANG = {
    • ENGLISH: 0,
    • PIRATE: 1,
    • BINARY: 2
    • }
    • function numberToBinaryArray(number) {
    • let result = [];
    • while(number > 0){
    • var bit = Math.floor(number % 2) != 0 ? 1 : 0;
    • let 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));
    • function txtToBin(text) {
    • let result = [];
    • for(let character of text){
    • let binaryArr = numberToBinaryArray(character.charCodeAt());
    • result = result.concat(binaryArr);
    • }
    • return result.join("");
    • }
    • let helloLangs = {
    • english: "hello",
    • pirate: "yar",
    • binary: txtToBin('hello')
    • function parseGreeting(lang) {
    • switch(lang){
    • case GREET_LANG.PIRATE:
    • return 'yar';
    • case GREET_LANG.BINARY:
    • return txtToBin('hello');
    • default:
    • return 'hello';
    • }
    • }
    • const hello = (whoever, lang="english") => `${helloLangs[lang]} ${lang == 'binary' ? txtToBin(whoever) : whoever}`;
    • const parseWhoever = (whoever, lang) => lang == GREET_LANG.BINARY ? txtToBin(whoever) : whoever;
    • const hello = (whoever, lang=GREET_LANG.ENGLISH) => `${parseGreeting(lang)} ${parseWhoever(whoever, lang)}`;