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.
Quick Science Lesson:
There are four major types of temparature scales (Celsius, Kelvin, Fahrenheit, and Rankine).
To convert Celsius to Kelvin simply add 273.15
EX:
3°C = 276.15K
To convert Celsius to Fahrenheit simply multiply by 9/5 and add 32
EX:
3°C = 37.4°F
To convert Celsius to Rankine simply multiply by 9/5 and add 491.67
EX:
3°C = 497.07°R
NOTE: Remember you can convert from different if you wanted
Actual Program:
Basically you will be given three parameters: initial temperature (float), source scale (string), and target scale (string) from which you will have to convert a result.
Ex #1:
Input:
21, 'r', 'c'
Output:
-261
Ex #2:
Input:
234.21, 'f', 'r'
Output:
693
Ex #3:
Input:
-122, 'k', 'c'
Output:
-395
NOTE: Make sure you return only ints
# the affine transformations of the form "y = a*x + b" # from Kelvin (k) to Celsius (c), Rankine (r) or Fahrenheit (F) convert = { "c": (1.0, -273.15), "r": (1.8, 0.0 ), "f": (1.8, -459.67), "k": (1.0, 0.0 ), } def temperature_convert(temp, source, target): # convert source unit to Kelvins : invert from_kelvin, x = (y - b) / a temp = (temp - convert[source][1]) / convert[source][0] # convert Kelvins to target unit, rounded to integer return int(temp * convert[target][0] + convert[target][1])
1 1 # the affine transformations of the form "y = a*x + b"
2 2 # from Kelvin (k) to Celsius (c), Rankine (r) or Fahrenheit (F)
3 − from_kelvin = {
4 − "c": {"a": 1.0, "b": -273.15},
5 − "r": {"a": 1.8, "b": 0.0},
6 − "f": {"a": 1.8, "b": -273.15 * 1.8 + 32.0},
7 − "k": {"a": 1.0, "b": 0.0},
3 + convert = {
4 + "c": (1.0, -273.15),
5 + "r": (1.8, 0.0 ),
6 + "f": (1.8, -459.67),
7 + "k": (1.0, 0.0 ),
8 8 }
9 9 10 − 11 − def temperature_convert(params):
12 − value, src, tgt = params
10 + def temperature_convert(temp, source, target):
13 13 # convert source unit to Kelvins : invert from_kelvin, x = (y - b) / a
14 − value_in_k = (value - from_kelvin[src]["b"]) / from_kelvin[src]["a"]
12 + temp = (temp - convert[source][1]) / convert[source][0]
15 15 # convert Kelvins to target unit, rounded to integer
16 − return int(value_in_k * from_kelvin[tgt]["a"] + from_kelvin[tgt]["b"])
14 + return int(temp * convert[target][0] + convert[target][1])
test.assert_equals(temperature_convert( 21, 'r', 'c'), -261) test.assert_equals(temperature_convert( 234.21, 'f', 'r'), 693) test.assert_equals(temperature_convert( -122, 'k', 'c'), -395) test.assert_equals(temperature_convert(31253245, 'c', 'c'), 31253245) test.assert_equals(temperature_convert( 531, 'f', 'c'), 277) test.assert_equals(temperature_convert( 8658, 'k', 'f'), 15124) test.assert_equals(temperature_convert( 22, 'r', 'f'), -437) test.assert_equals(temperature_convert( 234.21, 'f', 'k'), 385) test.assert_equals(temperature_convert( -1222, 'k', 'k'), -1222) test.assert_equals(temperature_convert( 431, 'r', 'r'), 431) test.assert_equals(temperature_convert( 2324.21, 'f', 'c'), 1273) test.assert_equals(temperature_convert( 0, 'k', 'r'), 0) test.assert_equals(temperature_convert( 2, 'r', 'r'), 2) test.assert_equals(temperature_convert( 4, 'f', 'c'), -15)
1 − test.assert_equals(temperature_convert([21, 'r', 'c']), -261)
2 − test.assert_equals(temperature_convert([234.21, 'f', 'r']),693)
3 − test.assert_equals(temperature_convert([-122, 'k', 'c']), -395)
4 − test.assert_equals(temperature_convert([31253245, 'c', 'c']), 31253245)
5 − test.assert_equals(temperature_convert([531, 'f', 'c']),277)
6 − test.assert_equals(temperature_convert([8658, 'k', 'f']), 15124)
7 − test.assert_equals(temperature_convert([22, 'r', 'f']), -437)
8 − test.assert_equals(temperature_convert([234.21, 'f', 'k']),385)
9 − test.assert_equals(temperature_convert([-1222, 'k', 'k']), -1222)
10 − test.assert_equals(temperature_convert([431, 'r', 'r']), 431)
11 − test.assert_equals(temperature_convert([2324.21, 'f', 'c']),1273)
12 − test.assert_equals(temperature_convert([0, 'k', 'r']), 0)
13 − test.assert_equals(temperature_convert([2, 'r', 'r']), 2)
14 − test.assert_equals(temperature_convert([4, 'f', 'c']),-15)
1 + test.assert_equals(temperature_convert( 21, 'r', 'c'), -261)
2 + test.assert_equals(temperature_convert( 234.21, 'f', 'r'), 693)
3 + test.assert_equals(temperature_convert( -122, 'k', 'c'), -395)
4 + test.assert_equals(temperature_convert(31253245, 'c', 'c'), 31253245)
5 + test.assert_equals(temperature_convert( 531, 'f', 'c'), 277)
6 + test.assert_equals(temperature_convert( 8658, 'k', 'f'), 15124)
7 + test.assert_equals(temperature_convert( 22, 'r', 'f'), -437)
8 + test.assert_equals(temperature_convert( 234.21, 'f', 'k'), 385)
9 + test.assert_equals(temperature_convert( -1222, 'k', 'k'), -1222)
10 + test.assert_equals(temperature_convert( 431, 'r', 'r'), 431)
11 + test.assert_equals(temperature_convert( 2324.21, 'f', 'c'), 1273)
12 + test.assert_equals(temperature_convert( 0, 'k', 'r'), 0)
13 + test.assert_equals(temperature_convert( 2, 'r', 'r'), 2)
14 + test.assert_equals(temperature_convert( 4, 'f', 'c'), -15)
Recent Moves:
# the affine transformations of the form "y = a*x + b" # from Kelvin (k) to Celsius (c), Rankine (r) or Fahrenheit (F) from_kelvin = { "c": {"a": 1.0, "b": -273.15}, "r": {"a": 1.8, "b": 0.0}, "f": {"a": 1.8, "b": -273.15 * 1.8 + 32.0}, "k": {"a": 1.0, "b": 0.0}, } def temperature_convert(params): value, src, tgt = params # convert source unit to Kelvins : invert from_kelvin, x = (y - b) / a value_in_k = (value - from_kelvin[src]["b"]) / from_kelvin[src]["a"] # convert Kelvins to target unit, rounded to integer return int(value_in_k * from_kelvin[tgt]["a"] + from_kelvin[tgt]["b"])
1 − converters = {
2 − 'ck': lambda value: value + 273.15,
3 − 'cr': lambda value: (value * 1.8) + 491.67,
4 − 'cf': lambda value: (value * 1.8) + 32,
5 − 'rc': lambda value: (value - 491.67) * (5/9),
6 − 'rk': lambda value: value * (5/9),
7 − 'rf': lambda value: value - 459.67,
8 − 'kc': lambda value: value - 273.15,
9 − 'kr': lambda value: value * 1.8,
10 − 'kf': lambda value: ((value - 273.15) * 1.8) + 32,
11 − 'fc': lambda value: (value - 32) * (5/9),
12 − 'fk': lambda value: ((value - 32) * (5/9)) + 273.15,
13 − 'fr': lambda value: value + 459.67
1 + # the affine transformations of the form "y = a*x + b"
2 + # from Kelvin (k) to Celsius (c), Rankine (r) or Fahrenheit (F)
3 + from_kelvin = {
4 + "c": {"a": 1.0, "b": -273.15},
5 + "r": {"a": 1.8, "b": 0.0},
6 + "f": {"a": 1.8, "b": -273.15 * 1.8 + 32.0},
7 + "k": {"a": 1.0, "b": 0.0},
14 14 }
15 15 16 − def temperature_convert(temperature):
17 − (value, a, b) = temperature
18 − return int(converters.get(a + b, lambda value: value)(value))
10 + 11 + def temperature_convert(params):
12 + value, src, tgt = params
13 + # convert source unit to Kelvins : invert from_kelvin, x = (y - b) / a
14 + value_in_k = (value - from_kelvin[src]["b"]) / from_kelvin[src]["a"]
15 + # convert Kelvins to target unit, rounded to integer
16 + return int(value_in_k * from_kelvin[tgt]["a"] + from_kelvin[tgt]["b"])
Two bytes shorter.
Recent Moves:
Combination of List
Instructions
Below are Instructions for this Kumite.
Introduction
Given the two list or arrays, filter and combine the numbers into one list or arrays. There will only be numbers in the list.
Requirements
There will be no negative number in the list
The list must be ordered in ascending order.
There must be no repeating number in the list.
It must support an empty list.
Combination of List
Instructions
Below are Instructions for this Kumite.
Introduction
Given the two list or arrays, filter and combine the numbers into one list or arrays. There will only be numbers in the list.
Requirements
There will be no negative number in the list
The list must be ordered in ascending order.
There must be no repeating number in the list.
It must support an empty list.
def combine_list(a, b): return sorted(set((*(n for n in a if n > 0), *(n for n in b if n > 0))))
1 − def combine_list(list1,list2):
2 − solution = set(x for x in list1 if x > 0)
3 − solution.update(x for x in list2 if x > 0)
4 − return list(solution)
1 + def combine_list(a, b):
2 + return sorted(set((*(n for n in a if n > 0), *(n for n in b if n > 0))))
enumerating over vector, equivelent to python's enumerate(list)
#include <vector>
#include <tuple>
#include <iostream>
template <class T>
void enumerate(std::vector<T> A)
{
for(auto [a,i]=std::tuple{A.begin(), 0}; a < A.end(); a++, i++)
{
std::cout << i << ":" << *a << "\n";
}
}
Describe(enumerating)
{
It(should_enumerate)
{
enumerate<int>({1, 5, 'a', 32});
}
};
Iterating over two vectors at the same time till end of one of them
#include <vector>
#include <tuple>
#include <iostream>
template <class T, class U>
void iterateTwoVectors(std::vector<T> A, std::vector<U> B)
{
for (auto [a,b] = std::tuple{A.begin(), B.begin()}; a != A.end() && b != B.end(); a++, b++)
{
std::cout << *a << ":" << *b << "\n";
}
}
// TODO: Replace examples and use TDD by writing your own tests
Describe(iterating)
{
It(should_iterate_both)
{
iterateTwoVectors<int, char>({1, 'a', 3}, {'a', 'b'});
}
};
Macro to get max of two integers
can be used as a new pseudo-command
; A macro with two parameters
; Implements actual int max(int a, int b)
%macro _max 2
cmp %2, %1 ; compare a ?= b
jle _lower ; jump to lower if a <= b
jmp _greater ; jump to greater if a > b
_lower:
mov rax, %1 ; assgine rax to b
jmp _end ; end program
_greater:
mov rax, %2 ; assgine rax to a
_end:
ret
%endmacro
section .text
global max ; declaring int max(int a, int b)
max:
_max rdi, rsi ; using inner _max macro
ret
#include <criterion/criterion.h>
int max(int, int);
Test(max, should_return_max) {
cr_assert_eq(max(3, 2), 3);
}
Get Max of two integers
section .text
global max ; declare max function
max: ; int max(int a, int b)
cmp rdi, rsi ; compare a ?= b
jle _lower ; jump to lower if a <= b
jmp _greater ; jump to greater if a > b
_lower:
mov rax, rsi ; assgine rax to b
jmp _end ; end program
_greater:
mov rax, rdi ; assgine rax to a
_end:
ret
#include <criterion/criterion.h>
int max(int, int);
Test(max, should_return_max) {
cr_assert_eq(max(1, 2), 2);
cr_assert_eq(max(3, 2), 3);
}