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.
fn flip_the_number(mut x: u64) -> u64 { let mut y = 0; while x != 0 { y *= 10; y += x % 10; x /= 10; } y }
fn flip_the_number(x: &u64) -> u64 {let mut x = *x;- fn flip_the_number(mut x: u64) -> u64 {
- let mut y = 0;
- while x != 0 {
y = y * 10 + x % 10;- y *= 10;
- y += x % 10;
- x /= 10;
- }
- y
- }
#[test] fn test() { let nums = [ (1234, 4321), (1234567890, 987654321), (243, 342), (12, 21), (837583, 385738), (32851532, 23515823), (999999, 999999), (111, 111), (35832456789, 98765423853), (9223372036854775807, 7085774586302733229) ]; for num in nums { assert_eq!(flip_the_number(num.0), num.1); } }
- #[test]
- fn test() {
- let nums = [
- (1234, 4321),
- (1234567890, 987654321),
- (243, 342),
- (12, 21),
- (837583, 385738),
- (32851532, 23515823),
- (999999, 999999),
- (111, 111),
- (35832456789, 98765423853),
- (9223372036854775807, 7085774586302733229)
- ];
for num in nums.iter() {assert_eq!(num.1, flip_the_number(&num.0));- for num in nums {
- assert_eq!(flip_the_number(num.0), num.1);
- }
- }
# TBS Engineering Morning Kick-off Dojo
Roman Numerals Decoder
Create a function that takes a Roman numeral as its argument, and returns its value as a numeric decimal integer.
Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost digit and skipping any 0s. So 1990 is rendered "MCMXC" (1000 = M, 900 = CM, 90 = XC) and 2008 is rendered "MMVIII" (2000 = MM, 8 = VIII). The Roman numeral for 1666, "MDCLXVI", uses each letter in descending order.
Example:
solution('XXI'); // should return 21
You should assume that the Roman Numeral passed to your function is always valid.
Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1,000
Getting Started
First, decide which language you want to tackle the problem with. I've included some snippets below to help get started with the languages that were declared in our Tech Radar session (JavaScript, Python, Golang, C#, Java).
Feel free to pick a langauge you are comfortable with to solve this problem, or if you fancy a challenge, one that you may not be so comfortable with! You can also pick from any of the other languages CodeWars supports, however you will need to write your own test cases to validate your solutions for these.
#### JavaScript
# Copy into "Code" (top-right box)
function solution (roman) {
return 0;
}
---
# Copy into "Test Cases" (bottom-right box)
const strictEqual = require('chai').assert.strictEqual;
function doTest (romanString, expected) {
const actual = solution(romanString);
strictEqual(actual, expected, `for roman number ${romanString}`);
}
describe("Tests", () => {
it("sample tests", () => {
doTest('XXI', 21);
doTest('I', 1);
doTest('IV', 4);
doTest('MMVIII', 2008);
doTest('MDCLXVI', 1666);
});
});
### Python
# Copy into "Code" (top-right box)
def solution(roman):
return 0
---
# Copy into "Test Cases" (bottom-right box)
test.describe("Example Tests")
test.assert_equals(solution('XXI'), 21, 'XXI should == 21')
test.assert_equals(solution('I'), 1, 'I should == 1')
test.assert_equals(solution('IV'), 4, 'IV should == 4')
test.assert_equals(solution('MMVIII'), 2008, 'MMVIII should == 2008')
test.assert_equals(solution('MDCLXVI'), 1666, 'MDCLXVI should == 1666')
Go
# Copy into "Code" (top-right box)
package kata
func Decode(roman string) int {
return 0
}
---
# Copy into "Test Cases" (bottom-right box)
package kata_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "codewarrior/kata"
)
var _ = Describe("test roman to decimal converter", func() {
It("should give decimal number from roman", func() {
Expect(Decode("XXI")).To(Equal(21))
})
It("should give decimal number from roman", func() {
Expect(Decode("I")).To(Equal(1))
})
It("should give decimal number from roman", func() {
Expect(Decode("IV")).To(Equal(4))
})
It("should give decimal number from roman", func() {
Expect(Decode("MMVIII")).To(Equal(2008))
})
It("should give decimal number from roman", func() {
Expect(Decode("MDCLXVI")).To(Equal(1666))
})
})
C#
# Copy into "Code" (top-right box)
using System;
public class RomanDecode
{
public static int Solution(string roman)
{
throw new NotImplementedException();
}
}
---
# Copy into "Test Cases" (bottom-right box)
using System;
using NUnit.Framework;
[TestFixture]
public class RomanDecodeTests
{
[TestCase(21, "XXI")]
public void Test(int expected, string roman)
{
Assert.AreEqual(expected, RomanDecode.Solution(roman));
}
[TestCase(1, "I")]
public void Test(int expected, string roman)
{
Assert.AreEqual(expected, RomanDecode.Solution(roman));
}
[TestCase(4, "IV")]
public void Test(int expected, string roman)
{
Assert.AreEqual(expected, RomanDecode.Solution(roman));
}
[TestCase(2008, "MMVIII")]
public void Test(int expected, string roman)
{
Assert.AreEqual(expected, RomanDecode.Solution(roman));
}
[TestCase(1666, "MDCLXVI")]
public void Test(int expected, string roman)
{
Assert.AreEqual(expected, RomanDecode.Solution(roman));
}
}
Java
# Copy into "Code" (top-right box)
public class Roman {
public static int solve(String roman) {
return 0;
}
}
---
# Copy into "Test Cases" (bottom-right box)
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
public class SolutionTest {
@Test
public void testXXI() {
assertEquals(21, Roman.solve("XXI"));
}
@Test
public void testI() {
assertEquals(1, Roman.solve("I"));
}
@Test
public void testIV() {
assertEquals(4, Roman.solve("IV"));
}
@Test
public void testMMVIII() {
assertEquals(2008, Roman.solve("MMVIII"));
}
@Test
public void testMDCLXVI() {
assertEquals(1666, Roman.solve("MDCLXVI"));
}
}
def solution(roman): list = [*roman] pervious = '' current = '' current_int = 0 pervious_int = 0 result = 0 for i in range(len(list)): if i == 0: pervious = list[i] continue current = list[i] pervious = list[i - 1] if current == 'I': current_int = 1 elif current == 'V': current_int = 5 elif current == 'X': current_int = 10 elif current == 'L': current_int = 50 elif current == 'C': current_int = 100 elif current == 'D': current_int = 500 elif current == 'M': current_int = 1000 if pervious == 'I': pervious_int = 1 elif pervious == 'V': pervious_int = 5 elif pervious == 'X': pervious_int = 10 elif pervious == 'L': pervious_int = 50 elif pervious == 'C': pervious_int = 100 elif pervious == 'D': pervious_int = 500 elif pervious == 'M': pervious_int = 1000 if pervious_int < current_int: result += current_int - pervious_int else: result += pervious_int if i == len(list) - 1: result += current_int print('Current: {} - {}, Pervious: {} - {}'.format(current, current_int, pervious, pervious_int)) # if item.index return result
package katafunc Decode(roman string) int {return 0}- def solution(roman):
- list = [*roman]
- pervious = ''
- current = ''
- current_int = 0
- pervious_int = 0
- result = 0
- for i in range(len(list)):
- if i == 0:
- pervious = list[i]
- continue
- current = list[i]
- pervious = list[i - 1]
- if current == 'I':
- current_int = 1
- elif current == 'V':
- current_int = 5
- elif current == 'X':
- current_int = 10
- elif current == 'L':
- current_int = 50
- elif current == 'C':
- current_int = 100
- elif current == 'D':
- current_int = 500
- elif current == 'M':
- current_int = 1000
- if pervious == 'I':
- pervious_int = 1
- elif pervious == 'V':
- pervious_int = 5
- elif pervious == 'X':
- pervious_int = 10
- elif pervious == 'L':
- pervious_int = 50
- elif pervious == 'C':
- pervious_int = 100
- elif pervious == 'D':
- pervious_int = 500
- elif pervious == 'M':
- pervious_int = 1000
- if pervious_int < current_int:
- result += current_int - pervious_int
- else:
- result += pervious_int
- if i == len(list) - 1:
- result += current_int
- print('Current: {} - {}, Pervious: {} - {}'.format(current, current_int, pervious, pervious_int))
- # if item.index
- return result
test.describe("Example Tests") test.assert_equals(solution('XXI'), 21, 'XXI should == 21') test.assert_equals(solution('I'), 1, 'I should == 1') test.assert_equals(solution('IV'), 4, 'IV should == 4') test.assert_equals(solution('MMVIII'), 2008, 'MMVIII should == 2008') test.assert_equals(solution('MDCLXVI'), 1666, 'MDCLXVI should == 1666')
package kata_testimport (. "github.com/onsi/ginkgo". "github.com/onsi/gomega". "codewarrior/kata")var _ = Describe("test roman to decimal converter", func() {It("should give decimal number from roman", func() {Expect(Decode("XXI")).To(Equal(21))})It("should give decimal number from roman", func() {Expect(Decode("I")).To(Equal(1))})It("should give decimal number from roman", func() {Expect(Decode("IV")).To(Equal(4))})It("should give decimal number from roman", func() {Expect(Decode("MMVIII")).To(Equal(2008))})It("should give decimal number from roman", func() {Expect(Decode("MDCLXVI")).To(Equal(1666))})})- test.describe("Example Tests")
- test.assert_equals(solution('XXI'), 21, 'XXI should == 21')
- test.assert_equals(solution('I'), 1, 'I should == 1')
- test.assert_equals(solution('IV'), 4, 'IV should == 4')
- test.assert_equals(solution('MMVIII'), 2008, 'MMVIII should == 2008')
- test.assert_equals(solution('MDCLXVI'), 1666, 'MDCLXVI should == 1666')
const addArr = arr => arr.length ? arr.reduce((sum, num) => sum + num, 0) : null;
function addArr(arr){if(arr.length === 0) return nulllet final = 0arr.forEach(num => {final += num})return final}- const addArr = arr => arr.length ? arr.reduce((sum, num) => sum + num, 0) : null;
const chai = require("chai"); const assert = chai.assert; describe("Solution", function() { it("should test for something", function() { assert.strictEqual(addArr([1, 2, 3, 4, 5]), 15); assert.strictEqual(addArr([1, 100]), 101) assert.strictEqual(addArr([]), null) }); });
- const chai = require("chai");
- const assert = chai.assert;
- describe("Solution", function() {
- it("should test for something", function() {
- assert.strictEqual(addArr([1, 2, 3, 4, 5]), 15);
- assert.strictEqual(addArr([1, 100]), 101)
- assert.strictEqual(addArr([]), null)
- });
- });
-- Code Here SELECT city_name AS kota, sum(confirmed_cases) AS confirmed_cases, sum(recovered_cases) AS recovered_cases, sum(death_cases) AS death_cases FROM cases INNER JOIN dati ON cases.dati_code = dati.code GROUP BY city_name ORDER BY confirmed_cases DESC
- --- Code Here
- -- Code Here
- SELECT
- city_name AS kota,
- sum(confirmed_cases) AS confirmed_cases,
- sum(recovered_cases) AS recovered_cases,
- sum(death_cases) AS death_cases
- FROM cases
- INNER JOIN dati ON cases.dati_code = dati.code
- GROUP BY city_name
- ORDER BY confirmed_cases DESC
def дима_лох(): return 'w - h - y'
def why():return 'w - h - y'- def дима_лох(): return 'w - h - y'
import codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(дима_лох(), 'w - h - y')
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_equals(why(), 'w - h - y')- test.assert_equals(дима_лох(), 'w - h - y')
def should_return_1():
import random
x = random.random()
return x**0