Start a new Kumite

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
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;
    • }
    • }

Added NULL check for strdup.

Code
Diff
  • #include <string.h>
    
    char *strdup_to_upper(const char *input) {
      if (!input) // prevent strdup UB
        return NULL;
      char *result = strdup(input);
      if (!result)
        return NULL;
      char *cursor = result;
      while (*cursor) {
        *cursor = toupper(*cursor);
        cursor++;
      }
      return result;
    }
    • #include <string.h>
    • char *strdup_to_upper(const char *input) {
    • if (!input) // prevent strdup UB
    • return NULL;
    • char *result = strdup(input);
    • char *cursor = result;
    • while (*cursor) {
    • *cursor = toupper(*cursor);
    • cursor++;
    • }
    • return result;
    • }
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 "";
    • }
    • }
Arrays
Code
Diff
  • unique_sum: (arr) ->
      sum, dup = 0, {}
      for x in *arr
        sum += dup[x] == nil and x or -x unless dup[x]
        dup[x] = dup[x] ~= nil
      sum
    • #include <vector>
    • #include <unordered_map>
    • int unique_sum(const std::vector<int>& n)
    • {
    • int sum{};
    • std::unordered_map<int, bool> seen{};
    • for (auto i : n) {
    • if (not seen.count(i)) sum += i; // If is first insertion
    • else if (not seen[i]) sum -= i; // If is second insertion
    • seen[i] = seen.count(i);
    • }
    • return sum;
    • }
Code
Diff
  • console.log((d=12)<6?`NOT MUCH LONGER LEFT!`:d<3?`Oh actually, you should wait a little longer.Sorry, false alarm`:``)
    • let distance = 12
    • if (distance < 6) {
    • console.log ("NOT MUCH LONGER LEFT!")
    • } else if (distance < 3){
    • console.log ("Oh actually, you should wait a little longer. Sorry, false alarm")
    • }
Arrays
Lists
Algorithms
Code
Diff
  • def mirror_fold(arr):
        mid = len(arr) // 2
        res = [arr[i] + arr[-1-i] for i in range(mid)]
        return res + ([arr[mid]] if len(arr) % 2 else [])
    
    • from operator import add
    • def mirror_fold(arr):
    • h, m = divmod(len(arr), 2)
    • return list(map(add, arr[:h] + m * [0], arr[::-1]))