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.
Convert a grade out of 100 to a letter grade.
Here are the criteria: used in assessing:
90-100 points = A
80-89 points = B
70-79 points = C
60-69 points = D
0-59 points = F
Make sure to return "Not a grade" for integers that are not equal to or between 100.
func gradeCalc(_ score: Int) {
// Your Code under here
}
import XCTest
// XCTest Spec Example:
// TODO: replace with your own tests (TDD), these are just how-to examples to get you started
class SolutionTest: XCTestCase {
static var allTests = [
("Test Example", testExample),
]
func testExample() {
let actual = 1
XCTAssertEqual(actual, 1)
}
}
XCTMain([
testCase(SolutionTest.allTests)
])
Make a calculator that can take in two integers and process any of the four basic operations. (Add, subtract, multiply, divide).
For the operation symbol, you need to turn the string that the person has inserted, and it should not be case sensitive.
Finally, it should return "Not a valid operation", if the operation that the user entered is not one of the four.
func calculator(_ int1: Int, _ operation: String, _ int2: Int) {
//Code Here
}
import XCTest
// XCTest Spec Example:
// TODO: replace with your own tests (TDD), these are just how-to examples to get you started
class SolutionTest: XCTestCase {
static var allTests = [
("Test Example", testExample),
]
func testExample() {
let actual = 1
XCTAssertEqual(actual, 1)
}
}
XCTMain([
testCase(SolutionTest.allTests)
])
Write a function that converts a base 10 number and returns binary (base 2).
Binary is consisted of zeros and ones only, and those make up the binary number.
Suppose that place value works the same.
func binaryConverter(_ input: Int) -> Int {
//Your Code Here
return input
}
import XCTest
// XCTest Spec Example:
// TODO: replace with your own tests (TDD), these are just how-to examples to get you started
class SolutionTest: XCTestCase {
static var allTests = [
("Test Example", testExample),
]
func testExample() {
let actual = 1
XCTAssertEqual(actual, 1)
}
}
XCTMain([
testCase(SolutionTest.allTests)
])
Write a function that converts a base 10 number and returns binary (base 2).
Binary is consisted of zeros and ones only, and those make up the binary number.
Suppose that place value works the same.
func binaryConverter(_ input: Int) -> Int {
//Your Code Here
return input
}
import XCTest
// XCTest Spec Example:
// TODO: replace with your own tests (TDD), these are just how-to examples to get you started
class SolutionTest: XCTestCase {
static var allTests = [
("Test Example", testExample),
]
func testExample() {
let actual = 1
XCTAssertEqual(actual, 1)
}
}
XCTMain([
testCase(SolutionTest.allTests)
])
Hailstone numbers are an interesting number series. The series is defined as follows:
- Pick a number
- If odd multiply by 3 add one
- Else even divide by 2
- Stop calculating the sequence when you reach 1
Different numbers reach one after a different number of steps.
e.g. Here are a few Hailstones that take a long time to reach 1
Hailstone 27 Steps: 112
Hailstone 54 Steps: 113
Hailstone 73 Steps: 116
Your code will need to be efficient with BigInt Lists
case class Hailstones (hailstoneStart : BigInt ) {
private def getSequenceHighPerformance (currentHailstone : BigInt, acc : List[BigInt]) : List[BigInt] = {
if (currentHailstone == 1) currentHailstone::acc
else if (currentHailstone.testBit(0)) getSequenceHighPerformance((currentHailstone << 1) + currentHailstone + 1, currentHailstone :: acc)
else getSequenceHighPerformance(currentHailstone >> 1, currentHailstone :: acc)
}
val seq = getSequenceHighPerformance(hailstoneStart, List[BigInt]()).reverse
}
object Hailstones {
def findSeq = Hailstones(18).seq
}
// You can test using ScalaTest (http://www.scalatest.org/).
import org.scalatest._
// TODO: replace this example test with your own, this is just here to demonstrate usage.
// See http://www.scalatest.org/at_a_glance for example usages
class HailstoneSpec extends FlatSpec with Matchers {
"Hailstones(18)" should "should have length 21" in {
Hailstones(18).seq.length should be (21)
}
"Hailstones(27)" should "should have length 112" in {
Hailstones(27).seq.length should be (112)
}
"Hailstones(12)" should "should be list 12,6,3,10,5,16,8,4,2,1" in {
Hailstones(12).seq should be (List[BigInt](12, 6, 3, 10, 5, 16, 8, 4, 2, 1))
}
}
Given a radius of the circle,
return the area and the circumference of the circle in 2 decimal places.
function CircleArea(r){
return Number((Math.PI*r*r).toFixed(2));
}
function CircleCir(r){
return Number((Math.PI*r*2).toFixed(2));
}
// TODO: Add your tests here
// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
// are still available for now.
//
// For new tests, using [Chai](https://chaijs.com/) is recommended.
// You can use it by requiring:
// const assert = require("chai").assert;
// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.
describe("Solution", function() {
it("should test for something", function() {
Test.assertEquals(CircleArea(0), 0);
Test.assertEquals(CircleArea(0.57), 1.02);
Test.assertEquals(CircleArea(1), 3.14);
Test.assertEquals(CircleCir(0), 0);
Test.assertEquals(CircleCir(0.16), 1.01);
Test.assertEquals(CircleCir(1), 6.28);
// assert.strictEqual(1 + 1, 2);
});
});
Trying this
public class TestingRules {
public static boolean doNothing(String braces) {
return true;
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD development by writing your own tests
public class SolutionTest {
@Test
public void testSomething() {
assertEquals("true", "true");
}
}
A wayward human has entered the Forest of the Lost- a forest renowned for having monsters of the worst variety.
Given the coordinates of the human, the coordinates of a monster, and the monster's attack span return whether the human is deciminated or if he lives to see another day.
ex. DeadOrAlive([3, 4], [3, 6], 1) == 'Alive!';
ex. DeadOrAlive([7, 6], [3, 6], 5) == 'Dead!';
Things to keep in mind:
- The span will always be a whole number
- Human and monster can have the same coordinates
String DeadOrAlive(List<int> human, List<int> monster, int span) {
return ((monster[0] - human[0]).abs() <= span && (monster[1] - human[1]).abs() <= span) ? 'Dead!' : 'Alive!';
}
// See https://pub.dartlang.org/packages/test
import "package:test/test.dart";
import "package:solution/solution.dart";
void main() {
test("DeadOrAlive", () {
expect(DeadOrAlive([3, 4], [3, 6], 1), equals('Alive!'));
});
test("DeadOrAlive", () {
expect(DeadOrAlive([7, 6], [3, 6], 5), equals('Dead!'));
});
test("DeadOrAlive", () {
expect(DeadOrAlive([79, 6], [3, 69], 80), equals('Dead!'));
});
test("DeadOrAlive", () {
expect(DeadOrAlive([13, 50], [3, 6], 50), equals('Dead!'));
});
test("DeadOrAlive", () {
expect(DeadOrAlive([0, 0], [4, 0], 3), equals('Alive!'));
});
}
In this kumite, I will test if a number is divisible by 3 or not.
If it is I will return True.
Or, if it isn't and leaves a remainder I shall return False.
But the only gimmick to my own challenge is that I am not allowed to mod that directly. Is that possible?
(NOTE: I am allowed to use modulus for other purposes)
def divisibility_by_3(x):
list_of_values = [int(d) for d in str(x)]
summation = sum(list_of_values)
if summation % 3 == 0:
return True
else:
return False
# TODO: Replace examples and use TDD development by writing your own tests
# These are some of the methods available:
# test.expect(boolean, [optional] message)
# test.assert_equals(actual, expected, [optional] message)
# test.assert_not_equals(actual, expected, [optional] message)
# You can use Test.describe and Test.it to write BDD style test groupings
test.assert_equals(divisibility_by_3(454), False)
test.assert_equals(divisibility_by_3(222), True)
test.assert_equals(divisibility_by_3(10593), True)
For a given string return a substring without first and last elements of the string.
If the given string has less than three characters then return an empty string.
func substringWithoutFirstAndLastElement(_ string: String) -> String {
guard string.count > 2 else { return "" }
return String(String(string.dropFirst()).dropLast())
}
import XCTest
// XCTest Spec Example:
// TODO: replace with your own tests (TDD), these are just how-to examples to get you started
class SolutionTest: XCTestCase {
static var allTests = [
("Test Empty", testEmpty),
("Test Single Character", testSingleCharacter),
("Test Two Characters", testTwoCharacters),
("Test Three Characters", testThreeCharacters),
("Test More Than Three Characters", testMoreThanThreeCharacters),
]
func testEmpty() {
XCTAssertEqual(substringWithoutFirstAndLastElement(""), "")
}
func testSingleCharacter() {
XCTAssertEqual(substringWithoutFirstAndLastElement("a"), "")
}
func testTwoCharacters() {
XCTAssertEqual(substringWithoutFirstAndLastElement("aa"), "")
}
func testThreeCharacters() {
XCTAssertEqual(substringWithoutFirstAndLastElement("aba"), "b")
}
func testMoreThanThreeCharacters() {
XCTAssertEqual(substringWithoutFirstAndLastElement("dzlaednzed"), "zlaednze")
}
}
XCTMain([
testCase(SolutionTest.allTests)
])