Begin a new Kumite
Search
About
  • Filter by Language:
  • 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.

Code
Diff
  • def solution (nums)
      # slower but simple ;-)
      nums.permutation.to_a.map{|x| x.join("")}.sort{|a,b| b.to_i-a.to_i}[0]
    end
  • 1
    import java.util.*;
    
    2
    3
    class Solution {
    
    4
      public static String largestNumber(Integer[] nums) {
    
    5
        Arrays.sort( nums, new Comparator<Integer>() {
    
    6
          
    
    7
          @Override
    
    8
          public int compare(Integer a, Integer b) {
    
    9
            String aStr = a.toString();
    
    10
            String bStr = b.toString();
    
    11
            
    
    12
            return (aStr + bStr).compareTo(bStr + aStr) * -1;
    
    13
          }
    
    14
          
    
    15
        } );
    
    16
        
    
    17
        String result = "";
    
    18
        for(Integer num : nums) {
    
    19
          result += num.toString();
    
    20
        }
    
    21
        
    
    22
        return result;
    
    23
      }
    
    24
    }
    
    1+
    def solution (nums)
    
    2+
      # slower but simple ;-)
    
    3+
      nums.permutation.to_a.map{|x| x.join("")}.sort{|a,b| b.to_i-a.to_i}[0]
    
    4+
    end
    

Recent Moves:

Testing
Redis
NoSQL
Message Queues
Databases
Information Systems
Data

This is a very basic example of how you can start a redis server using async code and wrapping it so that you can enable the solution to run only after the server has started.

This example also demonstrates how you can support async code within it tests. To enable async mode, you can pass true or a number value as the 2nd argument to describe. If true is provided, 2000 is used as the default number value, which is used as the timeout for each it run.

Notice how the it function has a done callback. You are required to call this when using async code so that the function knows when the it test has finished and can move on to the next test.

const redis = require("redis");
const Promise = require("bluebird");

// promisfy redis client to make it much easier to work with.
Promise.promisifyAll(redis.RedisClient.prototype);

// solution is your entry point. The redis server will not be available until solution is called. Since
// we are using async code you must call done() once you have completed the requirements.

function solution(done){
  let client = redis.createClient();
  
  // use Promise.join to make sure the done callback is fired after all other async operations have fired.
  Promise.join(
    client.setAsync("foo", "bar"),
    client.hsetAsync("h", "key", "value"),
    done
  )
}
Rendering
Graphics
Charts
Reporting
Data

This is a basic example of rendering a plot chart to the output window. It uses matplotlib and mpld3.

Some dummy tests were added at the end to demonstrate how you could have a challenge based on rendering data to a chart and then you could have tests that test the chart data after the fact - allowing you to have an interactive visualazation for the data that is being tested.

Can you figure out how to do something like this in another language?
# Example taken from http://mpld3.github.io/examples/drag_points.html

import numpy as np
import matplotlib
matplotlib.use('Agg') # need to do this to set the display type
import matplotlib.pyplot as plt
import matplotlib as mpl

fig, ax = plt.subplots()
np.random.seed(0)
points = ax.plot(np.random.normal(size=20),
                 np.random.normal(size=20), 'or', alpha=0.5,
                 markersize=50, markeredgewidth=1)
ax.set_title("Click and Drag", fontsize=18)

# See Preloaded code for JS DragPlugin
plugins.connect(fig, DragPlugin(points[0]))
print(mpld3.fig_to_html(fig))

Often times kata authors want to prevent certain code from being used within a kata, to increase the level of difficulty. This is an example of how you can read the solution.txt file into your code.

This example is in JavaScript, but the /home/codewarrior/solution.txt file is available for all languages.

// write a add function that doesn't use the plus symbol
function add(a, b){
  return a + b;
}

// Make sure to view the test cases to see how this test fails
IO

A basic proof of how you can create content that writes to the file system.

# you can write to your codewarrior home folder
`echo "example text" > /home/codewarrior/example.txt`
Ruby on Rails
Frameworks

A basic example of how to setup an active record challenge.

Note: Make sure to check out the preloaded section for how to configure the database.

ActiveRecord::Schema.define do
    create_table :albums do |table|
        table.column :title, :string
        table.column :performer, :string
    end

    create_table :tracks do |table|
        table.column :album_id, :integer
        table.column :track_number, :integer
        table.column :title, :string
    end
end

class Album < ActiveRecord::Base
    has_many :tracks
end

class Track < ActiveRecord::Base
    belongs_to :album
end
Fundamentals
Code
Diff
  • using System.Numerics;
    
    public class basic 
    {
        public static BigInteger pow(long down, long up)
            => up == 0 ? 1 : down * pow(down, up - 1);
    }
  • 11
    using System.Numerics;
    
    22
    33
    public class basic 
    
    44
    {
    
    55
        public static BigInteger pow(long down, long up)
    
    6
        {
    
    7
            return up == 0 ? 1 : down * pow(down, up - 1);
    
    8
        }
    
    6+
            => up == 0 ? 1 : down * pow(down, up - 1);
    
    99
    }
    
Code
Diff
  • let obj = {};
    
    let Singleton = function(){
      return obj;
    };
    
  • 1
    let Singleton = (function () {
    
    2
    	let instance;
    
    1+
    let obj = {};
    
    33
    4
    	return function Construct_singletone () {
    
    5
    		if (instance) {
    
    6
    			return instance;
    
    7
    		}
    
    8
    		if (this && this.constructor === Construct_singletone) {
    
    3+
    let Singleton = function(){
    
    4+
      return obj;
    
    5+
    };
    
let countChars (s : string) = 
    s.ToCharArray()
    |> List.ofArray
    |> List.groupBy(fun x -> x)
    |> List.map(fun (c, l) -> (c, l.Length))
    |> Map.ofSeq

printfn "%A" ("abacdacb" |> countChars)