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

I decided to test the java framework.

My opinions:

-I just started learning python, and in comparison, it takes a lot more to set up the tests in java, mostly beacause you have to set up the class and methods. Not much can be done about that anyway though.

-It takes a while to start up, and I even got some timeouts on something this simple. I assume the JVM that takes this much time to start up.

-I do miss eclipse's hability to automatiaclly indent and add the missing "}" when you press enter while the cursor is right after a "{". That would speed up setting up stuff.

-After so much programming in python and not much java, I found myself consistently forgetting to add ";" :P

Note:

I copied most stuff from https://github.com/Codewars/kata-test-framework-java , under CodewarsJava/src.
I found the int's in the beggining of the tester class to be completly useless in a test this simple though.

Also, just wanted to point out that in that kata in the git repository the assertEquals, in case of fail will print the error message, and after that the failed method will be called, which prints it again, causing it to print the exact same thing twice.

Notes to self and others that want to try making a java kumite:

To start a kumite, must set up:
-Class with the name of the test
-A class with the same name plus "Test"
-Create a member instante of the first class within the test.
-Create public void setUp() and tearDown() with @Before and @After anotations.
-Make the method that will test the kata or kumite, with a @Test anotation
-Create an instance of TestWatcher, with @Rule anotation, overriding both protected final void succeeded(Description description) and failed(Throwable e, Description description)

Hope this is useful to others.
Thanks for reading :)

PS: Sorry if my english is not the best, I'm not a native speaker.

public class Java {
  public int multiply(int x, int y) {
    return x * y;
  }
}
Fundamentals
#include<stdio.h>

int main() {
  printf("Hello, C!\n");
}

Checking to see if the clojure runner has the same problems as the Java runner. Apparently not...

(ns codewars.sanity.check)

(defn multiply [ & args ] (apply * args))
Formatting
Algorithms
Logic
Best Practices

This is an example from the Style Guide for Python Code, accompanied by the statement "Make sure to indent the continued line appropriately. The preferred place to break around a binary operator is after the operator, not before it."

class Rectangle(Blob):

    def __init__(self, width, height,
                 color='black', emphasis=None, highlight=0):
        if (width == 0 and height == 0 and
                color == 'red' and emphasis == 'strong' or
                highlight > 100):
            raise ValueError("sorry, you lose")
        if width == 0 and height == 0 and (color == 'red' or
                                           emphasis is None):
            raise ValueError("I don't think so -- values are %s, %s" %
                             (width, height))
        Blob.__init__(self, width, height,
                      color, emphasis, highlight)

Showcase your personal style for a purpose of your choosing! How would you write this for a Best Practices kata solution? A Clever kata solution? Something else?

I've reformatted it in my personal style for open-source code.

class Rectangle(Blob):
    def __init__(self,
                 width,
                 height,
                 color='black',
                 emphasis=None,
                 highlight=0):
        if (width, height) == (0, 0):
            if color == 'red' and emphasis == 'strong' or highlight > 100:
                raise ValueError('sorry, you lose')
            elif color == 'red' or emphasis is None:
                raise ValueError("I don't think so -- values are %s, %s" % (width, height))
        Blob.__init__(self,
                      width=width,
                      height=height,
                      color=color,
                      emphasis=emphasis,
                      highlight=highlight)
Design Patterns
Design Principles

A pretty contrived example. Its an interesting pattern though that doesn't really get used often. I wonder how the pattern could be used for more practical purposes.

class Salutation
  def initialize(default)
    @default = default
    @handlers = {}
  end
  
  def to_proc
    Proc.new do |name|
      if @handlers[name]
        @handlers[name].call(name)
      else
        @default.gsub('{{name}}', name)
      end
    end
  end
  
  def add_handler(*names, &block)
    names.each do |name|
      @handlers[name] = block
    end
  end
end
Utilities

A little utility that I came up with recently to deal with needing to loop through multiple items and run an async operation within each. This makes it very easy to chain together a sequence of callbacks.

For example:

var chain = new Chain();
someItemsToProcess.forEach(function(item){
  chain.link(function(next){
    asyncProcess(item, next);
  });
});

chain.run(function(){
  // done
});

Some possible room for improvement:

  • Promise support
  • Events
  • ?
function Chain(){
  this.links = [];
}

Chain.prototype.link = function link(cb){
  this.links.push(cb);
  return this;
}

Chain.prototype.run = function run(end){
  var self = this;
  var next = function(i){
    return function(){
      if (i < self.links.length){
        self.links[i++](next(i), end);
      }
    }
  };
  next(0)();
}

With that you can check if a word is present in a file, and how many time :)
It was my first program in C, if you want to optimise my program you can !

#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>

void  str(char *str)
{
	int i = 0;

	while (str[i])
	{
		write(1, &str[i], 1);
		i++;
	}
}

int  find(char *name, char *file)
{
	int	i = 0;
	int	j = 0;
	int len = 0;
	int	count = 0;

	len = strlen(name);
	while (file[i])
	{
		if (file[i] == name[j])
		{
			while (file[i] == name[j])
			{
				j++;
				i++;
				if (j == len)
					count = count + 1;
			}
			j = 0;
		}
		i++;
	}
	return (count);
}

int  main(int ac, char **av)
{
	int		fd;
	int		readint;
	char	*name;
	char	*string;
	int		acc;

	if (ac < 4)
	{
		str("Usage :\n");
		str("	./name [Your_word] [Buffer] [File] [Other_file] ...\n");
		return (0);
	}

	int		BUFF_SIZE = atoi(av[2]);
	char	buffer[BUFF_SIZE + 1];
	name = strdup(av[1]);
	acc = ac;
	ac = 4;
	while (ac <= acc)
	{
		fd = open(av[ac - 1], O_RDONLY);
		readint = read(fd, buffer, BUFF_SIZE);
		if (readint == -1)
		{
			str("Error : read fail\n");
			return (-1);
		}
		str(av[ac - 1]);
		str(":\n");
		if (find(name, buffer) > 0)
		{
			str("\033[1;32;40m	I found '");
			str(name);
			printf("' %d time(s)\033[0m\n", find(name, buffer));
		}
		else
			str("\033[1;31;40m	Wrong... I didn't find sorry...!\033[0m\n");
		ac++;
	}
	return (0);
}
object Scala extends App {
  println("Hello, World!")
}
#!/usr/bin/env python


def main():
	print "hello world"

if __name__ == "__main__":
	main()