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

Haskell is lazy, so we could get infinite sequence naturally.

like this.

module InfiniteSeq where

import Data.List

ones = repeat 1
nats = [0..]

merge = concat . transpose
merge2 x y = merge [x, y]

ints = 0: merge2 [1..] [(-1),(-2)..]

write one compare function.

  • first compare with string's length
  • when string have same length, then compare string with lex order.
module CmpStr where

import Data.Function
import Data.Monoid

cmpStr :: String -> String -> Ordering
cmpStr = (compare `on` length) `mappend` compare

There seems to be an error with looking at the top of a stack, but it doesn't throw. It just kills execution. What's going on here?

#include <stack>

bool method() 
{
  std::stack<int> my_stack;
  //my_stack.push(1);
  try {
    if(my_stack.top()) 
    {
    }
  }
  catch(...) {
    std::cout << "An Exception Occurred" << std::endl;
  }
  return true;
}

Looks like C++ and C# return their tests in alphabetical order.

int a = 1;

For some reason I keep using this function as a test in all the runner changes

fn doubler(n:i32) -> i32 {
  n * 2
}
let stringToHTML = (el = 'div', attr = [], template = '') => 
  `<${el} ${attr.join(' ')}>${template}</${el}>`,
  
  element = 'a',
  content = "https://www.codewars.com"
  attributes = [`href='${content}'`, "class='link'"];
  
stringToHTML(element, attributes, content);

// => "<a href='https://www.codewars.com' class='link'>https://www.codewars.com</a>"
Bugs
// !!!

Can this code be refactored into something more elegant?

defmodule Piapprox do

  def iter_pi(epsilon) do
    leibniz_stream |>
    Enum.reduce_while(0, fn {i, n}, acc ->
      if abs(:math.pi - acc) >= epsilon do
        { :cont, acc + i }
      else
        { :halt, [n, Float.round(acc, 10)] }
      end
    end)
  end

  defp leibniz_stream do
    Stream.unfold(1, fn
      n when rem(n,4) == 1 -> { 4/n, n+2 }
      n                    -> {-4/n, n+2 }
    end) |> Stream.with_index
  end
end

I used mathematical analysis to find the two constants, from the iterative form: f(n) = f(n-1) + f(n-2) and initial conditions.

# Fibonacci #

from math import sqrt

c1 = (sqrt(5) - 1) / (2 * sqrt(5))
c2 = (sqrt(5) + 1) / (2 * sqrt(5))

def f(x):
    fibo = c1 * ((1 - sqrt(5)) / 2)**x + c2 * ((1 + sqrt(5)) / 2)**x
    return int(round(fibo))

Construct a singleton in js.

Tests:
let obj1 = new Singleton();
let obj2 = new Singleton();
obj1.test = 1;

obj1 === obj2 // true
obj2.test // 1

let Singleton = (function () {
	let instance;

	return function Construct_singletone () {
		if (instance) {
			return instance;
		}
		if (this && this.constructor === Construct_singletone) {
			instance = this;
		} else {
			return new Construct_singletone();
		}
	}
}());