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
  • function binarySearch(numbers, element) {
    //time complexity is log(n) it excecutes very fast than linear search  n=arraylength;
      let left = 0;
      let right = numbers.length - 1;
      
      while(left <= right) {
        let pivot = Math.floor((left + right) / 2);
        
        if(numbers[pivot]==element){
          return pivot;
        }
        else if(numbers[pivot]>element){
          right=pivot-1;
        }
        else{
          left=pivot+1;
        }
       }
      return -1;
    }
    • function binarySearch(numbers, element) {
    • //time complexity is log(n) it excecutes very fast than linear search n=arraylength;
    • let left = 0;
    • let right = numbers.length - 1;
    • while(left <= right) {
    • let pivot = Math.floor((left + right) / 2);
    • if(numbers[pivot]==element){
    • return pivot;
    • }
    • else if(numbers[pivot]>element){
    • right=pivot-1;
    • }
    • else{
    • left=pivot+1;
    • }
    • }
    • return -1;
    • }

this uses c++17 fold expressions to iterate over all the given arrays at the same time.

Code
Diff
  • #include <vector>
    #include <iostream>
    #include <algorithm>
    
    constexpr auto iterateVectors = [](auto...vectors)
    {
        constexpr auto getSmallestVector = [](auto...vectors)
        {
            size_t end{ reinterpret_cast<size_t>(std::numeric_limits<size_t>::max) };
            ((end = std::min(vectors.size(), end)), ...);
            return end;
        };
        constexpr auto writeRow = [](size_t position, auto...vectors) -> void
        {
            const auto rowLength{ sizeof...(vectors) };
            size_t i{ 0 };
            ((std::cerr << vectors[position] << (++i < rowLength ? ':' : '\n')), ...);
        };
    
        const size_t iterateFor{ getSmallestVector(vectors...) };
        for (size_t i{ 0 }; i < iterateFor; i++)
            writeRow(i, vectors...);
    };
    • #include <vector>
    • #include <utility>
    • #include <iostream>
    • template <class T, class U>
    • void iterateTwoVectors(std::vector<T> A, std::vector<U> B)
    • #include <algorithm>
    • constexpr auto iterateVectors = [](auto...vectors)
    • {
    • constexpr auto getSmallestVector = [](auto...vectors)
    • {
    • size_t end{ reinterpret_cast<size_t>(std::numeric_limits<size_t>::max) };
    • ((end = std::min(vectors.size(), end)), ...);
    • return end;
    • };
    • constexpr auto writeRow = [](size_t position, auto...vectors) -> void
    • {
    • const auto rowLength{ sizeof...(vectors) };
    • size_t i{ 0 };
    • ((std::cerr << vectors[position] << (++i < rowLength ? ':' : '\n')), ...);
    • };
    • for (auto [a,b] = std::pair{A.begin(), B.begin()}; a != A.end() && b != B.end(); a++, b++)
    • {
    • std::cout << *a << ":" << *b << "\n";
    • }
    • }
    • const size_t iterateFor{ getSmallestVector(vectors...) };
    • for (size_t i{ 0 }; i < iterateFor; i++)
    • writeRow(i, vectors...);
    • };

RSpec works as expected with the extra diff message.

Code
Diff
  • puts # "Uncomment the test cases to see the errors"
    • puts "Uncomment the test cases to see the errors"
    • puts # "Uncomment the test cases to see the errors"

Trying to solve sequence problems without loops. This works with some triangle number maths.

Code
Diff
  • function solution(num){
      // find the nearest triangle number, use ceil to get to the current row
    	const s = Math.ceil((Math.sqrt(8*num+1)-1)/2);
      // Gauss Summation to calculate the number of items in the "pyramid above"
    	const t = ((s - 1) * (s))/2;
    	return num - t;
    }
    • function solution(num){
    • let times = 1;
    • let count = 0;
    • while(num > 0){
    • count = num
    • num -= times;
    • times++;
    • }
    • return count;
    • // find the nearest triangle number, use ceil to get to the current row
    • const s = Math.ceil((Math.sqrt(8*num+1)-1)/2);
    • // Gauss Summation to calculate the number of items in the "pyramid above"
    • const t = ((s - 1) * (s))/2;
    • return num - t;
    • }
Basic Language Features
Fundamentals
Control Flow
Code
Diff
  • def convert_decimal_roman(numero):
        num_romanos_dic = {
            1: 'I',
            5: 'V',
            10: 'X',
            50: 'L',
            100: 'C',
            500: 'D',
            1000: 'M'
        }
        list_num_rom = [{'key': x, 'value': y} for x, y in num_romanos_dic.items()]
        size_num = len(numero)
        output = []
        for i in range(size_num):
            num =  numero[i:]
            num_unit = int(num)
            numextre_izq = int(num[0])
            pref = []
            for i in range(1, len(list_num_rom), 2):
                if num_unit >= list_num_rom[i-1]['key'] and num_unit < list_num_rom[i+1]['key']:
                    pref.append(list_num_rom[i-1]['value'])
                    pref.append(list_num_rom[i]['value'])
                    pref.append(list_num_rom[i+1]['value'])
    
            if numextre_izq < 4 and numextre_izq > 0:
                output.append(pref[0]*numextre_izq)
            if numextre_izq == 4:
                output.extend(pref[0:2])
            if numextre_izq == 5:
                output.append(pref[1])
            if numextre_izq > 5 and numextre_izq < 9:
                output.append(pref[1] + pref[0]*(numextre_izq-5))
            if numextre_izq == 9:
                output.extend(pref[::2])
    
        output = ''.join(output)
        return output

Input data now come from parameters with zero default value, so it can calculate for any data and can be tested with different test cases. Modified the original test case and added a new one.

Code
Diff
  • /*input data come from parameters with zero default value, so it can calculate for any data and can be tested with different test cases*/
    const yearlyElectricCosts = (m1 = 0, m2 = 0, m3 = 0, m4 = 0, m5 = 0, m6 = 0, m7 = 0, m8 = 0, m9 = 0, m10 = 0, m11 = 0, m12 = 0 ) => {
      /* Create an object with 12 keys and the input values*/
      const monthlyCosts = {
       januaryBill : m1,
       februaryBill : m2,
       marchBill : m3,
       aprilBill : m4,
       mayBill : m5,
       juneBill : m6,
       julyBill : m7,
       augustBill : m8,
       septemberBill : m9,
       octoberBill : m10,
       novemberBill : m11,
       decemberBill : m12
      }
      /*print the object*/
      console.log(monthlyCosts);
      // Decide on a variable name and sum all the monthly charges
      const totalCharges = Object.values(monthlyCosts).reduce((acc, curr) => acc + curr, 0);
      
      // Return the value of the variable by typing it in after the `return` keyword below
      console.log(totalCharges.toFixed(2), typeof(totalCharges.toFixed(2)));
      /*toFixed converts the result to string, we have to convert it back to number*/
      return parseFloat(totalCharges.toFixed(2));
    }
    • const yearlyElectricCosts = () => {
    • // Create an object with 12 keys with the correct values
    • /*input data come from parameters with zero default value, so it can calculate for any data and can be tested with different test cases*/
    • const yearlyElectricCosts = (m1 = 0, m2 = 0, m3 = 0, m4 = 0, m5 = 0, m6 = 0, m7 = 0, m8 = 0, m9 = 0, m10 = 0, m11 = 0, m12 = 0 ) => {
    • /* Create an object with 12 keys and the input values*/
    • const monthlyCosts = {
    • januaryBill : 43.11,
    • februaryBill : 50.21,
    • marchBill : 48.92,
    • aprilBill : 62.36,
    • mayBill : 54.64,
    • juneBill : 49.30,
    • julyBill : 61.93,
    • augustBill : 68.54,
    • septemberBill : 71.77,
    • octoberBill : 70.28,
    • novemberBill : 59.56,
    • decemberBill : 62.04
    • januaryBill : m1,
    • februaryBill : m2,
    • marchBill : m3,
    • aprilBill : m4,
    • mayBill : m5,
    • juneBill : m6,
    • julyBill : m7,
    • augustBill : m8,
    • septemberBill : m9,
    • octoberBill : m10,
    • novemberBill : m11,
    • decemberBill : m12
    • }
    • // Decide on a variable name and add all the monthly charges
    • /*print the object*/
    • console.log(monthlyCosts);
    • // Decide on a variable name and sum all the monthly charges
    • const totalCharges = Object.values(monthlyCosts).reduce((acc, curr) => acc + curr, 0);
    • // Return the value of the variable by typing it in after the `return` keyword below
    • console.log(totalCharges.toFixed(2), typeof(totalCharges.toFixed(2)));
    • /*toFixed converts the result to string, we have to convert it back to number*/
    • return parseFloat(totalCharges.toFixed(2));
    • }
Fundamentals
Games
Code
Diff
  • riddle = lambda w: w.index("?")
    • def riddle(word):
    • return word.rindex("?")
    • riddle = lambda w: w.index("?")