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
Arrays
Data Types
Functions
Control Flow
Basic Language Features
Fundamentals
Language Syntax
Declarative Programming
Programming Paradigms
Lambdas
Functional Programming
Higher-order Functions

A slightly shorter version

Code
Diff
  • // This is just an interesting alternative way to build an array,
    // almost like a declarative literal - Very cool stuff!
    
    // See test cases for syntax.
    
    function chain(element) {
      var sectionBuilder = function(elem) {
        sectionBuilder.end.push(elem);
        return sectionBuilder;
      };
      sectionBuilder.end = [];
      return sectionBuilder(element);
    }
    • // This is just an interesting alternative way to build an array,
    • // almost like a declarative literal - Very cool stuff!
    • // See test cases for syntax.
    • function chain(element) {
    • var array = [element];
    • var sectionBuilder = function(elem) {
    • array.push(elem);
    • sectionBuilder.end = array;
    • sectionBuilder.end.push(elem);
    • return sectionBuilder;
    • };
    • sectionBuilder.end = array;
    • return sectionBuilder;
    • sectionBuilder.end = [];
    • return sectionBuilder(element);
    • }
Code
Diff
  • function hiThere ($name) {
    	echo "Hello $name, welcome to PHP!";
    };
    
    hiThere("Austin");
    
    # returns "Hello Austin, welcome to PHP!"
    
    • echo "Hello, PHP!";
    • function hiThere ($name) {
    • echo "Hello $name, welcome to PHP!";
    • };
    • hiThere("Austin");
    • # returns "Hello Austin, welcome to PHP!"
Design Patterns
Design Principles
Code
Diff
  • class Salutation
      def initialize(default)
        @default = default
        @handlers = {}
      end
      
      def greet(name)
        if @handlers[name]
          @handlers[name][name]
        else
          @default.gsub('{{name}}', name)
        end
      end
      
      def to_proc
        Proc.new { |name| greet(name) }
      end
      
      def add_handler(*names, &block)
        names.each do |name|
          @handlers[name] = block
        end
      end
    end
    
    
    • 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
    • def greet(name)
    • if @handlers[name]
    • @handlers[name][name]
    • else
    • @default.gsub('{{name}}', name)
    • end
    • end
    • def to_proc
    • Proc.new { |name| greet(name) }
    • end
    • def add_handler(*names, &block)
    • names.each do |name|
    • @handlers[name] = block
    • end
    • end
    • end

This works now...

The JVM runner doesn't use javac to compile; the runner uses the JVM's builtin compiler that it gets from javax.tools.ToolProvider.getSystemJavaCompiler(), and loads the result into a thread.

If there's no fixture, it infers the class from the code and runs <Class>.main() (all of this is done in clojure, which is what I wrote the JVM runner in).

I didn't originally give it arguments because there's nothing sensible to set them to. After some thought, maybe the right thing to set them to is an array containing "Arguments Disabeled".

Also, clojure really wants the class you export from your solution code to be public ; I think there's a way around this but it'll require some research.

We're also clearly swallowing error messages from exceptions, which is bad.

Code
Diff
  • public class JavaJava {
        public static void main() {
            System.out.println("Hello Java");
        }
    }
    • class Solution {
    • public static void main(String[] args) {
    • System.out.println("Hello World :D");
    • public class JavaJava {
    • public static void main() {
    • System.out.println("Hello Java");
    • }
    • }

Okay, this works for me right now...

Code
Diff
  • public class Java {
      public static int multiply(int x, int y) {
        return y * x;
      }
    }
    • public class Java {
    • public static int multiply(int x, int y) {
    • return x * y;
    • return y * x;
    • }
    • }
Code
Diff
  • fn main() {
        println!("All we are in rust in the wind...");
    }
    • println "hello, world"
    • fn main() {
    • println!("All we are in rust in the wind...");
    • }