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

where fastify

const fastify = require('fastify');
USING: math arrays sequences quotations kernel ;
IN: kata

: foo1 (   -- x ) [ even? ] 1array first ;

: foo2 ( x -- r ) [ even? ] 1array first filter ;
VideodimaFailed Tests

Kata

------------------>>>>>>>

function func(one, two) {
  return 0
}

Python array select one of item and repeat it for selected ranges.
It's maded for some interesting things like evolution no anymore

Example:



<span class "cm-comment"># Create simple array with numbers
array =[0, 10, 20, 13]
<span class "cm-comment"># Call our function
spawn_to_range(array, 13, 4)
<span class "cm-comment">#=> Must be returned a [0, 10, 20, 13, 13, 13, 13]

def spawn_to_range(arr, val, ran):
  return

As can be seen, in the "Should all fail", only the first two assertion fails as expected. The other two assertions display the buggy behaviour.

USE: kernel
FROM: preloaded => custom-err ;
IN: foo

: throws-err ( -- * ) "Err" throw ;
: throws-custom ( -- * ) custom-err ;
: return-err ( -- err ) "Err" ;
: return-custom ( -- err ) \ custom-err new ;

Given two Arrays a and b, Return True if arrays contain common item, else false

//Given 2 Arrays, Return True if arrays contain common item, else false.
//e.g a= ['a','b','g','c'] and b =['z','e','c'] returns true
// naive approach, loop through first array, with each item in a, loop through b and compare item to 
//each item in b returning true if a match is found or false.
//input : 2 arrays
//output: bool
using System.Collections.Generic;
public class Kata{
  public static bool ContainsCommonItem(char[] a, char[] b){ //naive O(a*b)
    for(int i=0;i<a.Length;i++)
      for(int j=0; j< b.Length; j++)
        if(a[i]==b[j])
          return true;
    return false;
  }
  public static bool ContainsCommonItemBetter(char[] a,char[]b){
    
    HashSet<char> items = new HashSet<char>();
    
    foreach(char item in a)
      items.Add(item);
    for (int i =0; i< b.Length; i++)
      if (items.Contains(b[i]))
        return true;
    return false;
  }
    
}
namespace Solution {
  using NUnit.Framework;
  using System;

  // TODO: Replace examples and use TDD by writing your own tests

  [TestFixture]
  public class SolutionTest
  {
    [Test]
    public void MyTest()
    {
      Assert.AreEqual(true, Kata.ContainsCommonItemBetter(new char []{ 'a','b','g','c'}, new char[]{'z','e','c'}));
      Assert.AreEqual(false, Kata.ContainsCommonItemBetter(new char []{ 'a','b','g','c'}, new char[]{'z','e','d'}));
      Assert.AreEqual(false,Kata.ContainsCommonItemBetter(new char[]{},new char[]{'f','h'}));
    }
  }
}

(Authors note: Introducing: FixDatTrash. This is a new kumite concept that I have begun where over time I create both simple and complex noob scenarios where YOU have to find a way to fix the code. You could also suggest a faster, more easier version of the scenarios code too by just changing it to that in your fork. Get wack, translate, checklist each problem, complicate it, use you creativity! Each scenario has a little fictional character and in the next FixDatTrash as a bonus along with a new scenario you also get a response and some feedback from the character on the previous scenario.)

= = = = = = =

Scenario

= = = = = = =

= = No. 1 = =

  • Persons Name: Joe
  • Gender: Male
  • Programming Language: Python 3.1
  • Subject: Help! My Python Fruit Colour Detector is broken!

Description

Joe: Hey code warriors! I'm going on a shopping spree with my friend Fred. However, there is a problem, recnetly Fred has lost his memory! Sadly, he has no memory of most names of fruit, but can remember colours.

So, I am building a tool just made for him to use! One problem, I am absolutely TRASH at programming, trust me. I can't even see what's wrong! I would be so glad if some nice code warrior at codewars.com could take some of their time to make this code better. Please, I would do anything to help my friend Fred.
def colouroffruit(fruit):
    if fruit == "Apple":
        return "Red"
    elseif fruit == "Orange":
        return "Orange"
    elif fruit = "Blueberry":
        return "Blue"
    elif frut == "Pear":
        return "Green"
    elif fruit == "banana"
        return "Yellow"
    elif fruit = "Strawberry":
        return "Red"
    elif fruit == "Lemon":
        return "Yellow"
    elif fruit == "Lime":
        print("Green")
    elif fruit == "Raspberry"
        return "Red":
        elif fruit == "Pineapple":
            return "Yellow"
    elif fruit == "Melon":
        return "Green"
    if fruit == "Plum":
        return "Purple"
    elif fruit == "Strawberry":
        return "Red"
    elif fruit == "Cabbage"
        return "Greem"

#Your Checklist:
#(Optional: put a list of problems you solved here in lines of comments, along with the line number)
#[Example] 1: Fixed if statement syntax (Line 2)
public class Kumite {
  public static boolean boolCheck(boolean[] bools) {
    return bools[0] ? bools[1] || bools[2] : bools[1] && bools[2];
  }
}
import org.scalatest._

import org.scalatest.Reporter
import org.scalatest.events._

import java.io.{StringWriter, PrintWriter}

// http://doc.scalatest.org/3.0.0/index.html#org.scalatest.Reporter
class CodewarsReporter extends Reporter {
  override def apply(event: Event): Unit = event match {
    case s: SuiteStarting if s.suiteName != "DiscoverySuite" =>
      println(s"\n<DESCRIBE::>${s.suiteName}")

    case s: SuiteCompleted if s.suiteName != "DiscoverySuite" =>
      println(s"\n<COMPLETEDIN::>${durationString(s.duration)}")

    case s: SuiteAborted =>
      println(s"\n<ERROR::>Test Suite Aborted<:LF:>${replaceLF(s.message)}")
      s.throwable foreach showStackTrace
      println(s"\n<COMPLETEDIN::>${durationString(s.duration)}")

    case t: TestStarting =>
      println(s"\n<IT::>${t.testName}")

    case t: TestSucceeded =>
      println("\n<PASSED::>Test Passed")
      println(s"\n<COMPLETEDIN::>${durationString(t.duration)}")

    case t: TestFailed =>
      println(s"\n<FAILED::>Test Failed<:LF:>${replaceLF(t.message)}")
      t.throwable foreach showStackTrace
      println(s"\n<COMPLETEDIN::>${durationString(t.duration)}")

    case t: TestCanceled =>
      println(s"\n<FAILED::>Test Cancelled<:LF:>${replaceLF(t.message)}")
      t.throwable foreach showStackTrace
      println(s"\n<COMPLETEDIN::>${durationString(t.duration)}")

    case _: TestIgnored =>
      println(s"\n<LOG::>Test Ignored")
      println(s"\n<COMPLETEDIN::>")

    case _: TestPending =>
      println(s"\n<LOG::>Test Pending")
      println(s"\n<COMPLETEDIN::>")


    case _: DiscoveryStarting => ()
    case _: DiscoveryCompleted => ()

    case _: RunStarting => ()
    case _: RunStopped => ()
    case t: RunAborted =>
      println(s"\n<ERROR::>${replaceLF(t.message)}")
      t.throwable foreach showStackTrace
      println(s"\n<COMPLETEDIN::>")

    case _: RunCompleted => ()

    case _: ScopeOpened => ()
    case _: ScopeClosed => ()
    case _: ScopePending => ()

    // contained in recordedEvents?
    case _: InfoProvided => ()
    case _: MarkupProvided => ()
    case _: AlertProvided => ()
    case _: NoteProvided => ()

    case _ => ()
  }

  private def showStackTrace(throwable: Throwable): Unit = {
    val sw = new StringWriter
    throwable.printStackTrace(new PrintWriter(sw))
    println(s"<LOG::-Stack Trace>${sw.toString.replaceAll("\n", "<:LF:>")}")
  }

  private def durationString(d: Option[Long]) = d map { _.toString } getOrElse ""
  private def replaceLF(s: String) = s.replaceAll("\n", "<:LF:>")
}
class HobovskysReporter extends Reporter {
  override def apply(event: Event): Unit = event match {
    case s: SuiteStarting if s.suiteName != "DiscoverySuite" =>
      println(s"\n<DESCRIBE::>${s.suiteName}")

    case s: SuiteCompleted if s.suiteName != "DiscoverySuite" =>
      println(s"\n<COMPLETEDIN::>${durationString(s.duration)}")

    case s: SuiteAborted =>
      println(s"\n<ERROR::>Test Suite Aborted<:LF:>${replaceLF(s.message)}")
      s.throwable foreach showStackTrace
      println(s"\n<COMPLETEDIN::>${durationString(s.duration)}")

    case t: TestStarting =>
      println(s"\n<IT::>${t.testName}")

    case t: TestSucceeded =>
      println("\n<PASSED::>Test Passed X")
      println(s"\n<COMPLETEDIN::>${durationString(t.duration)}")

    case t: TestFailed =>
      println(s"\n<FAILED::>Test Failed<:LF:>${replaceLF(t.message)}")
      t.throwable foreach showStackTrace
      println(s"\n<COMPLETEDIN::>${durationString(t.duration)}")

    case t: TestCanceled =>
      println(s"\n<FAILED::>Test Cancelled<:LF:>${replaceLF(t.message)}")
      t.throwable foreach showStackTrace
      println(s"\n<COMPLETEDIN::>${durationString(t.duration)}")

    case _: TestIgnored =>
      println(s"\n<LOG::>Test Ignored")
      println(s"\n<COMPLETEDIN::>")

    case _: TestPending =>
      println(s"\n<LOG::>Test Pending")
      println(s"\n<COMPLETEDIN::>")


    case _: DiscoveryStarting => ()
    case _: DiscoveryCompleted => ()

    case _: RunStarting => ()
    case _: RunStopped => ()
    case t: RunAborted =>
      println(s"\n<ERROR::>${replaceLF(t.message)}")
      t.throwable foreach showStackTrace
      println(s"\n<COMPLETEDIN::>")

    case _: RunCompleted => ()

    case _: ScopeOpened => ()
    case _: ScopeClosed => ()
    case _: ScopePending => ()

    // contained in recordedEvents?
    case _: InfoProvided => ()
    case _: MarkupProvided => ()
    case _: AlertProvided => ()
    case _: NoteProvided => ()

    case _ => ()
  }

  private def showStackTrace(throwable: Throwable): Unit = {
    val sw = new StringWriter
    throwable.printStackTrace(new PrintWriter(sw))
    println(s"<LOG::-Stack Trace>${sw.toString.replaceAll("\n", "<:LF:>")}")
  }

  private def durationString(d: Option[Long]) = d map { _.toString } getOrElse ""
  private def replaceLF(s: String) = s.replaceAll("\n", "<:LF:>")
}

import org.scalatest.funsuite.AnyFunSuite
class TestFunSuite extends AnyFunSuite {

  test("An empty Set should have size 0") {
    assert(Set.empty.size == 0)
  }

  test("Invoking head on an empty Set should produce NoSuchElementException") {
    assertThrows[NoSuchElementException] {
      Set.empty.head
    }
  }
}

import org.scalatest.flatspec.AnyFlatSpec

class TestFlatSpec extends AnyFlatSpec {

  "An empty Set" should "have size 0" in {
    assert(Set.empty.size == 0)
  }

  it should "produce NoSuchElementException when head is invoked" in {
    assertThrows[NoSuchElementException] {
      Set.empty.head
    }
  }
}

import org.scalatest.funspec.AnyFunSpec

class TestFunSpec extends AnyFunSpec {

  describe("A Set") {
    describe("when empty") {
      it("should have size 0") {
        assert(Set.empty.size == 0)
      }

      it("should produce NoSuchElementException when head is invoked") {
        assertThrows[NoSuchElementException] {
          Set.empty.head
        }
      }
    }
  }
}

import org.scalatest.wordspec.AnyWordSpec

class TestWordSpec extends AnyWordSpec {

  "A Set" when {
    "empty" should {
      "have size 0" in {
        assert(Set.empty.size == 0)
      }

      "produce NoSuchElementException when head is invoked" in {
        assertThrows[NoSuchElementException] {
          Set.empty.head
        }
      }
    }
  }
}

import org.scalatest.freespec.AnyFreeSpec

class TestFreeSpec extends AnyFreeSpec {

  "A Set" - {
    "when empty" - {
      "should have size 0" in {
        assert(Set.empty.size == 0)
      }

      "should produce NoSuchElementException when head is invoked" in {
        assertThrows[NoSuchElementException] {
          Set.empty.head
        }
      }
    }
  }
}

import org.scalatest._
import org.scalatest.matchers._
import org.scalatest.propspec._
import org.scalatest.prop._
import org.scalatestplus.scalacheck._
import scala.collection.immutable._

class TestPropSpec extends AnyPropSpec with TableDrivenPropertyChecks with should.Matchers {

  val examples =
    Table(
      "set",
      BitSet.empty,
      HashSet.empty[Int],
      TreeSet.empty[Int]
    )

  property("an empty Set should have size 0") {
    forAll(examples) { set =>
      set.size should be (0)
    }
  }

  property("invoking head on an empty set should produce NoSuchElementException") {
    forAll(examples) { set =>
       a [NoSuchElementException] should be thrownBy { set.head }
    }
  }
}

import org.scalatest.featurespec._

class TVSet {
  private var on: Boolean = false
  def isOn: Boolean = on
  def pressPowerButton() = {
    on = !on
  }
}

class TestFeatureSpec extends AnyFeatureSpec with GivenWhenThen {

  info("As a TV set owner")
  info("I want to be able to turn the TV on and off")
  info("So I can watch TV when I want")
  info("And save energy when I'm not watching TV")

  feature("TV power button") {
    scenario("User presses power button when TV is off") {

      Given("a TV set that is switched off")
      val tv = new TVSet
      assert(!tv.isOn)

      When("the power button is pressed")
      tv.pressPowerButton()

      Then("the TV should switch on")
      assert(tv.isOn)
    }

    scenario("User presses power button when TV is on") {

      Given("a TV set that is switched on")
      val tv = new TVSet
      tv.pressPowerButton()
      assert(tv.isOn)

      When("the power button is pressed")
      tv.pressPowerButton()

      Then("the TV should switch off")
      assert(!tv.isOn)
    }
  }
}

import org.scalatest.refspec.RefSpec

class TestRefSpec extends RefSpec {

  object `A Set` {
    object `when empty` {
      def `should have size 0` = {
        assert(Set.empty.size == 0)
      }

      def `should produce NoSuchElementException when head is invoked` = {
        assertThrows[NoSuchElementException] {
          Set.empty.head
        }
      }
    }
  }
}

class RootSpec extends Sequential(
  new TestFunSuite,
  new TestFlatSpec,
  new TestFunSpec,
  new TestWordSpec,
  new TestFreeSpec,
  new TestPropSpec,
  new TestFeatureSpec,
  new TestRefSpec
)

class SuiteWithCodewarsReporter extends RootSpec
class SuiteWithHobovskysReporter extends RootSpec

object ScalaTEestsTest extends App {
  // (new TestFlatSpec).execute(color = false, configMap = ConfigMap("reporter" -> "CodewarsReporter"));
  (new SuiteWithCodewarsReporter).run(None, new Args(new CodewarsReporter));
  (new SuiteWithHobovskysReporter).run(None, new Args(new HobovskysReporter));
}
<?php

namespace TennisGame;

interface TennisGame
{
    /**
     * @param  $playerName
     * @return void
     */
    public function wonPoint($playerName);

    /**
     * @return string
     */
    public function getScore();
}

class TennisGame1 implements TennisGame
{
    private $m_score1 = 0;
    private $m_score2 = 0;
    private $player1Name = '';
    private $player2Name = '';

    public function __construct($player1Name, $player2Name)
    {
        $this->player1Name = $player1Name;
        $this->player2Name = $player2Name;
    }

    public function wonPoint($playerName)
    {
        if ('player1' == $playerName) {
            $this->m_score1++;
        } else {
            $this->m_score2++;
        }
    }

    public function getScore()
    {
        $score = "";
        if ($this->m_score1 == $this->m_score2) {
            switch ($this->m_score1) {
                case 0:
                    $score = "Love-All";
                    break;
                case 1:
                    $score = "Fifteen-All";
                    break;
                case 2:
                    $score = "Thirty-All";
                    break;
                default:
                    $score = "Deuce";
                    break;
            }
        } elseif ($this->m_score1 >= 4 || $this->m_score2 >= 4) {
            $minusResult = $this->m_score1 - $this->m_score2;
            if ($minusResult == 1) {
                $score = "Advantage player1";
            } elseif ($minusResult == -1) {
                $score = "Advantage player2";
            } elseif ($minusResult >= 2) {
                $score = "Win for player1";
            } else {
                $score = "Win for player2";
            }
        } else {
            for ($i = 1; $i < 3; $i++) {
                if ($i == 1) {
                    $tempScore = $this->m_score1;
                } else {
                    $score .= "-";
                    $tempScore = $this->m_score2;
                }
                switch ($tempScore) {
                    case 0:
                        $score .= "Love";
                        break;
                    case 1:
                        $score .= "Fifteen";
                        break;
                    case 2:
                        $score .= "Thirty";
                        break;
                    case 3:
                        $score .= "Forty";
                        break;
                }
            }
        }
        return $score;
    }
}