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
  • 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)
wichuFailed Tests

Rot13

let abc = ['a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'; 'i'; 'j'; 'k'; 'l'; 'm'; 'n'; 'o'; 'p'; 'q'; 'r'; 's'; 't'; 'u'; 'v'; 'w'; 'x'; 'y'; 'z']
        
let rot13 s = s |> String.map(fun c -> match abc |> List.tryFindIndex(fun x -> x = c) with | Some(i) -> abc.[(i + 13) % 26] | None -> c)

printfn "%s" (rot13 "hello world")
printfn "%s" (rot13 "uryyb jbeyq")
Fundamentals
Code
Diff
  • using System.Numerics;
    
    public class basic 
    {
        public static BigInteger pow(long down, long up)
        {
            return 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)
    
    66
        {
    
    7
            BigInteger power = 1;
    
    8
            for (long i = 0; i < up; i++)
    
    9
              power *= down;
    
    10
            return power;
    
    7+
            return up == 0 ? 1 : down * pow(down, up - 1);
    
    1111
        }
    
    1212
    }
    

Given array of integer elements, find the index of peak element in O(Log N) time complexity.

A peak element is an element that is greater than its neighbors. Given an input array where num[i] != num[i + 1], find a peak element and return its index. Array may contain multiple peaks, in that case return index of any peak.

Example:

Input:
1 2 3 1

Output:
2

because peak element is 3 and it is at index 2.

import java.util.*;;

class Solution {
  public static int peakIndex(int[] nums) {
    int left = 0;
    int right = nums.length - 1;
    int peak = -1;
    
    while(left <= right) {
      if(left == right) {
        peak = left;
        break;
      }
      
      int mid = (left + right) / 2;
      
      if(nums[mid] < nums[mid + 1]) {
        left = mid + 1;
      } else {
        right = mid;
      }
    }
    
    return peak;
  }
}

Write a program to find if given array contains duplicate elements or all elements are unique.
Your function should output true if there are duplicates, false if all elements are unique.

Example:

Input:
1 4 3 2 6 4

Output:
true

Input:
1 4 3 2 6 5

Output:
false

import java.util.*;

class Solution {
  /**
   *  Checks if given array contains duplicate elements.
   *  Complexity: O(N)
   *  @author     Jayesh Chandrapal
   
   *  @param nums integer array of elements
   *  @return     true if duplicate elements are found, false otherwise
   */
  public static boolean hasDuplicates(int[] nums) {
    Set<Integer> set = new HashSet<Integer>();
    
    for(int i = 0, len = nums.length; i < len; i++) {
      if(set.contains(nums[i])) {
        return true;
      } else {
        set.add(nums[i]);
      }
    }
    
    return false;
  }
}
Code
Diff
  • // Code is in the preload
    fn person_builder(first_name:&'static str, last_name: &'static str) -> Person {
      Person { first_name: first_name, last_name: last_name }
    }
  • 11
    // Code is in the preload
    
    2+
    fn person_builder(first_name:&'static str, last_name: &'static str) -> Person {
    
    3+
      Person { first_name: first_name, last_name: last_name }
    
    4+
    }
    

Recent Moves:

Code
Diff
  • add = -> a, b { a + b }
    square = -> x { x * x }
    
    result = square[add[add[add[1,2],3],4]]
    
    puts result
  • 11
    add = -> a, b { a + b }
    
    22
    square = -> x { x * x }
    
    33
    4
    # sigh, if only Ruby supported pipes!
    
    5
    result = square.(add.(add.(add.(1,2), 3), 4))
    
    4+
    result = square[add[add[add[1,2],3],4]]
    
    66
    77
    puts result
    
require "sqlite3"
db = SQLite3::Database.new ":memory:"

rows = db.execute <<-SQL
  create table numbers (
    name varchar(30),
    val int
  );
SQL

{
  "one" => 1,
  "two" => 2,
}.each do |pair|
  db.execute "insert into numbers values ( ?, ? )", pair
end

p db.execute( "select * from numbers" ).to_a