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
object Scala extends App {
  println("Hello, World!")
}
#!/usr/bin/env python


def main():
	print "hello world"

if __name__ == "__main__":
	main()

Hello, world! style application, come on folks let's make PHP a cool subject

echo "Hello, PHP folks!";
import pprint;pprint.pprint(zip(('Byte', 'KByte', 'MByte', 'GByte', 'TByte'), (1 << 10*i for i in xrange(5))))

Create a function that returns a working relative path from the base path to the given target path.

The base path and the target path are absolute.

Ex:
Target: /httpdocs/admin/img/icons/
Base: /httpdocs/admin/
Result: img/icons

Ex 2:
Target: /httpdocs/admin/
Base: /httpdocs/admin/
Result: .

Ex 3:
Target: /httpdocs/
Base: /httpdocs/admin/
Result: ..

Ex 4:
Target: /httpdocs/img/
Base: /httpdocs/admin/
Result: ../img

function getRelativePath($base = '/', $target = '/')
{
  $out = array();
  
  $base_ex = explode('/', $base);
  $target_ex = explode('/', $target);
  
  //Find common ancestor
  $max = min(count($base_ex), count($target_ex));
  for($i = 0; $i < $max; $i++)
  {
    $b = $base_ex[$i];
    $t = $target_ex[$i];
    
    if($b != $t) break;
  }
  $common = $i;
  
  $diff = (count($base_ex) - 1) - $common;
  
  /*
  $diff = 0:
  Target:   /httpdocs/admin/
  Base:     /httpdocs/admin/
  
  $diff > 0:
  Target:   /httpdocs/
  Base:     /httpdocs/admin/
  */
  
  for($i = 0; $i < $diff; $i++)
  {
    $out[] = '..';
  }
  
  $rest = array_slice($target_ex, $common);
  
  $out = array_merge($out, $rest);
  
  if(count($out) == 0) $out[] = '.';
  
  return join('/', $out);
}

echo getRelativePath('/httpdocs/admin/', '/httpdocs/admin/img/icons/');
echo "\n";

echo getRelativePath('/httpdocs/admin/', '/httpdocs/admin/');
echo "\n";

echo getRelativePath('/httpdocs/admin/', '/httpdocs/img/');
echo "\n";

Quick example of a basic resource pool. The test cases are pretty bad and could use some work, but they demonstrate the basic idea.

// sample Resource
function Resource(name){
  this.run = function(cb){
    console.log("resource ran: " + name)
    if (cb) cb()
  }
  var events = {}
  
  this.on = function(event, cb){
    events[event] = events[event] || []
    events[event].push(cb);
  }
  
  this.emit = function(event){
    var self = this;
    events[event].forEach(function(cb){
      cb(self);
    })
  }
}


function Pool(){
  this.ready = [];
  this.waiting = [];  
  this.resources = [];
}

Pool.prototype.checkout = function(cb)
{
    if (this.ready.length > 0)
    {
        this.ready.shift().run(cb);
    }
    else
    {
        this.waiting.push(cb);
    }
}

Pool.prototype.checkin = function(resource)
{
    if (this.ready.indexOf(resource) == -1){
      this.ready.push(resource);  
    }
    
    if (this.waiting.length > 0)
    {
        this.checkout(this.waiting.shift());
    }
}

Pool.prototype.register = function(resource)
{
    this.resources.push(resource);
    var self = this;
    resource.on('ready', function()
    {
        self.checkin(resource);
    });
}

Given a starting seed (which must be odd), produces a lazy sequence of "random" numbers generated by the infamous RANDU generator, starting with the seed itself.

(ns randu)

(defn randu-seq [x] (iterate #(mod (* 65539 %) 0x80000000) x))

I've written a Curry class Add that can be used as follows.

var c = new Curry();
c.Add(1)(1); //should make c.Number == 2.
c.Add(3)(4)(5); //should make c.Number == 12.

Are there other ways of doing this same kind of thing in c#? I would love to see what you can come up with. My version of the Curry class has been added in the Preloaded section.

I've also included the TestCurrying class for us to test that the behavior is as expected. I am not sure how to setup proper tests with c#, so hopefully this gives us something we can run with.

var test = new Currying.TestCurrying();
test.testSequential();
test.testRandom();
Sequences
Arrays
Data Types

Returns the Collatz sequence starting with the given number.

module Collatz where

collatz :: Int -> [Int]
collatz n = n : collatz next
  where next | even n = n `div` 2
             | odd n = n * 3 + 1