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
  • import random
    
    operations = ["+","-","*","/"]
    
    def calculate(operations):
        num = random.randint(0,1000)
        num2 = random.randint(0,1000)
        operation = operations[random.randint(0,3)]
                          
    
    
    
    
    • import random
    • num = random.randint(0,1000)
    • operations = ["+","-","*","/"]
    • num2 = random.randint(0,1000)
    • def calculate(operations):
    • num = random.randint(0,1000)
    • num2 = random.randint(0,1000)
    • operation = operations[random.randint(0,3)]

Small demo to show that reserve can save allocations.
Intentionally fails a test so it can print the number of allocations out.

on the small allocation aka 10 bytes, SSO kicks in and no allocation happens, but on the big string 1000 bytes the difference is pretty clear

Code
Diff
  • #include <memory_resource>
    #include <string>
    #include <string_view>
    #include <utility>
    
    struct CountingResource : std::pmr::memory_resource {
      std::size_t allocs = 0;
      std::size_t bytes = 0;
    
      void* do_allocate(std::size_t n, std::size_t a) override {
        allocs++;
        bytes += n;
        return std::pmr::new_delete_resource()->allocate(n, a);
      }
    
      void do_deallocate(void* p, std::size_t n, std::size_t a) override {
        std::pmr::new_delete_resource()->deallocate(p, n, a);
      }
    
      bool do_is_equal(const memory_resource& other) const noexcept override {
        return this == &other;
      }
    };
    
    std::pmr::string with_pre_alloc(std::string_view input, std::pmr::memory_resource* mr)
    {
      std::pmr::string result{mr};
      result.reserve(input.size());
    
      std::transform(input.begin(), input.end(), std::back_inserter(result),
        [](unsigned char c) -> char { return static_cast<char>(std::toupper(c)); });
    
      return result;
    }
    
    std::pmr::string without_pre_alloc(std::string_view input, std::pmr::memory_resource* mr)
    {
      std::pmr::string result{mr};
    
      std::transform(input.begin(), input.end(), std::back_inserter(result),
        [](unsigned char c) -> char { return static_cast<char>(std::toupper(c)); });
    
      return result;
    }
    • #include <memory_resource>
    • #include <string>
    • #include <string_view>
    • #include <algorithm>
    • #include <utility>
    • using namespace std;
    • struct CountingResource : std::pmr::memory_resource {
    • std::size_t allocs = 0;
    • std::size_t bytes = 0;
    • string fun(string_view input)
    • void* do_allocate(std::size_t n, std::size_t a) override {
    • allocs++;
    • bytes += n;
    • return std::pmr::new_delete_resource()->allocate(n, a);
    • }
    • void do_deallocate(void* p, std::size_t n, std::size_t a) override {
    • std::pmr::new_delete_resource()->deallocate(p, n, a);
    • }
    • bool do_is_equal(const memory_resource& other) const noexcept override {
    • return this == &other;
    • }
    • };
    • std::pmr::string with_pre_alloc(std::string_view input, std::pmr::memory_resource* mr)
    • {
    • std::pmr::string result{mr};
    • result.reserve(input.size());
    • std::transform(input.begin(), input.end(), std::back_inserter(result),
    • [](unsigned char c) -> char { return static_cast<char>(std::toupper(c)); });
    • return result;
    • }
    • std::pmr::string without_pre_alloc(std::string_view input, std::pmr::memory_resource* mr)
    • {
    • string result;
    • transform(input.cbegin(), input.cend(), back_inserter(result), [](unsigned char c) -> char {
    • return toupper(c);
    • });
    • std::pmr::string result{mr};
    • std::transform(input.begin(), input.end(), std::back_inserter(result),
    • [](unsigned char c) -> char { return static_cast<char>(std::toupper(c)); });
    • return result;
    • }
Games
Arrays

Well, point is to make it crazy, and chaotic, making it all into a bunzzled stuff, so yeah, good luck tryna get betta.

-The Chaos Dud, ethan330NEO...

Code
Diff
  • final class WordChain {
     static boolean validate(String[]w,int n){
      if(w==null||w.length<2||n<1)return false;
      int c=1;while(c<w.length<<1)c<<=1;
      String[]k=new String[c];int[]h=new int[c];int m=c-1;
      for(int i=0;i<w.length;i++){
       String s=w[i];if(s==null||s.length()<n)return false;
       if(i>0)for(int j=0;j<n;j++)
        if((w[i-1].charAt(w[i-1].length()-n+j)|32)!=(s.charAt(j)|32))return false;
       int x=0;for(int j=0;j<s.length();j++)x=31*x+(s.charAt(j)|32);
       for(int j=x&m;;j=j+1&m){
        String t=k[j];
        if(t==null){k[j]=s;h[j]=x;break;}
        if(h[j]==x&&t.length()==s.length()){
         int z=0,L=s.length();
         while(z<L&&(t.charAt(z)|32)==(s.charAt(z)|32))z++;
         if(z==L)return false;
        }
       }
      }
      return true;
     }
    }
    
    //NUH UH NO ONE CAN CHAOS MORE THAN ME
    • import java.util.HashSet;
    • import java.util.Set;
    • final class WordChain {
    • static boolean validate(String[] words, int n) {
    • if (words == null || words.length < 2 || n < 1) return false;
    • Set<String> seen = new HashSet<>();
    • for (int i = 0; i < words.length; i++) {
    • String w = words[i];
    • if (w == null || w.length() < n) return false;
    • String lower = w.toLowerCase();
    • if (i > 0) {
    • String prev = words[i - 1].toLowerCase();
    • if (!prev.substring(prev.length() - n).equals(lower.substring(0, n)))
    • return false;
    • }
    • if (!seen.add(lower)) return false;
    • }
    • return true;
    • static boolean validate(String[]w,int n){
    • if(w==null||w.length<2||n<1)return false;
    • int c=1;while(c<w.length<<1)c<<=1;
    • String[]k=new String[c];int[]h=new int[c];int m=c-1;
    • for(int i=0;i<w.length;i++){
    • String s=w[i];if(s==null||s.length()<n)return false;
    • if(i>0)for(int j=0;j<n;j++)
    • if((w[i-1].charAt(w[i-1].length()-n+j)|32)!=(s.charAt(j)|32))return false;
    • int x=0;for(int j=0;j<s.length();j++)x=31*x+(s.charAt(j)|32);
    • for(int j=x&m;;j=j+1&m){
    • String t=k[j];
    • if(t==null){k[j]=s;h[j]=x;break;}
    • if(h[j]==x&&t.length()==s.length()){
    • int z=0,L=s.length();
    • while(z<L&&(t.charAt(z)|32)==(s.charAt(z)|32))z++;
    • if(z==L)return false;
    • }
    • }
    • }
    • return true;
    • }
    • }
    • //NUH UH NO ONE CAN CHAOS MORE THAN ME
Fundamentals
Code
Diff
  • public class Kata {
        public static String getGrade(int score) {
          System.out.println("scroe " + score);
          for (Scores s : Scores.values())
            {
                if (s.matches(score)) {
                  System.out.println("scroe " + score + " name -> " + s.name());
                  return s.name();
                }
             }
          return "Invalid";
        }
      
      
      enum Scores {
      A(90,100),
        B(80, 89),
        C(70, 79),
        D(60, 69),
        F(0, 59);
        
        private final int min;
        private final int max;
        
        Scores(int min, int max) {
          this.min = min;
          this.max = max;
        }
        
        boolean matches (int score) {
          return score >= min && score <= max;
        }
      }
    }
    
     
    • public class Kata {
    • public static String getGrade(int score) {
    • // Ваш код здесь
    • return "";
    • System.out.println("scroe " + score);
    • for (Scores s : Scores.values())
    • {
    • if (s.matches(score)) {
    • System.out.println("scroe " + score + " name -> " + s.name());
    • return s.name();
    • }
    • }
    • return "Invalid";
    • }
    • }
    • enum Scores {
    • A(90,100),
    • B(80, 89),
    • C(70, 79),
    • D(60, 69),
    • F(0, 59);
    • private final int min;
    • private final int max;
    • Scores(int min, int max) {
    • this.min = min;
    • this.max = max;
    • }
    • boolean matches (int score) {
    • return score >= min && score <= max;
    • }
    • }
    • }