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.

Flip the number

Code
Diff
• ``````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
• }
Failed Tests

02/05 TBS Engineering Morning Kick-off Dojo

# 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"));
}
}
``````
Code
Diff
• ``````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 kata
• func 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

Code
Diff
• ``const addArr = arr => arr.length ? arr.reduce((sum, num) => sum + num, 0) : null;``
• if(arr.length === 0) return null
• let final = 0
• arr.forEach(num => {
• final += num
• })
• return final
• }
• const addArr = arr => arr.length ? arr.reduce((sum, num) => sum + num, 0) : null;

SQL Left Join 1 (BIE)

Code
Diff
• ``````-- 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

Why you don't complete this kumite

Code
Diff
• ``def дима_лох(): return 'w - h - y'``
• def why():
• return 'w - h - y'
• def дима_лох(): return 'w - h - y'

Return 1!

def should_return_1():
import random
x = random.random()
return x**0

Code
Diff
• ``````def should_return_1():
import random
x = random.random()
return x**0``````
• def should_return_1():
• return 1
• import random
• x = random.random()
• return x**0

Basic Use Case 2 LIMIT (BIE)

Code
Diff
• ``````select *
from employees
order by salary desc
limit 10``````
• -- Code Here
• select *
• from employees
• order by salary desc
• limit 10

Basic Ordering 3 Multiple Order (BIE)

Code
Diff
• ``````-- Code Here
SELECT *
FROM transactions
WHERE customer IS NOT NULL
ORDER BY store, total_price DESC;``````
• --- Code Here
• -- Code Here
• SELECT *
• FROM transactions
• WHERE customer IS NOT NULL
• ORDER BY store, total_price DESC;

Basic Ordering 2 DESC (BIE)

Code
Diff
• ``select * from transactions order by total_price desc;``
• -- Code Here
• select * from transactions order by total_price desc;

Basic Ordering 1 ASC (BIE)

Code
Diff
• ``````SELECT *
FROM transactions
ORDER BY total_price ASC``````
• -- Code Here
• SELECT *
• FROM transactions
• ORDER BY total_price ASC