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.
Obtain previous number
object Previous {
def previous(num: Int): Int =
num-1
}
// 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 ExampleSpec extends FlatSpec with Matchers {
"previous(4)" should "return 3" in {
Previous.previous(4) should be (3)
}
"previous(0)" should "return 1" in {
Previous.previous(0) should be (-1)
}
"previous(-1)" should "return -2" in {
Previous.previous(-1) should be (-2)
}
}
input two objects:
classroom={x:x1,y:y1};
teacher={x:x2,y:y2};
give another float d,
that is how long you shouts.
return 'fuck dude!'if the teachercannothear.
return 'shut up!'ifhe can hear out.
return 'sit well!'if he is in the classroom.
(i cannot say english so well.)
//
Test.assertEquals(f({x1:1,y1:2},{x2:5,y1:3},3.3),'fuck dude!')//he cannot hear that
Test.assertEquals(f({x1:1,y1:3},{x2:4,y1:3},3.3),'shut up!')//he can hear that
Test.assertEquals(f({x1:1,y1:2},{x2:1,y1:2},0.1),'sit well!')//he is in the classroom
Test.assertEquals(f({x1:1,y1:2},{x2:4,y1:2},3),'fuck dude!')//he cannot hear well of that
Test.assertEquals(f({x1:1,y1:2},{x2:5,y1:3},0),'dumb!')//the dist. is 0
//more tests here
/*var testInputs=[
[{x1:3,y1:4},{x2:3,y2:9},4.999], [{x1:},{},7]
]
var res=[
]
it will be finished*/
Ques 7: Input type String. Output type number. Print out the maximum even number which can be generated by making combinations of numbers present in the given string. Each number can be used only once ie. No Redundancy.
Example1:
Input String = Infytq@218412
Intermediate step (List of numbers //redundancy removed) = [2,1,8,4]
Output Number = 8412
Example2
Input String = someString&337
Intermediate step (List of numbers //redundancy removed) = [3,7]
Output Number = -1
def maximum_even_no(string):
list1=[]
list2=[]
for i in string:
if(i.isdigit()):
list1.append(i)
list1=list(dict.fromkeys(list1))
list2=sorted(list1,reverse=True)
if(int(list2[-1])%2==0 or int(list2[-1])==0):
return int("".join(list2))
list3=range(len(list2))
list3=sorted(list3,reverse=True)
for j in list3:
if(int(list2[j])%2==0):
temp=list2.pop(j)
list2.append(temp)
break
result="".join(list2)
if(int(result)%2==0):
return int(result)
else:
return -1
# 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(maximum_even_no("Infytq@218412"),8412)
test.assert_equals(maximum_even_no("Abhishek@4668557"),87654)
test.assert_equals(maximum_even_no("Ashish@913478"),987314)
test.assert_equals(maximum_even_no("someString&337"),-1)
# test.assert_not_equals(actual, expected, [optional] message)
# You can use Test.describe and Test.it to write BDD style test groupings
Takes a string of an even length, splits it in two and intertwines those to generate the output string.
e.g intertwine('135246') --> '123456'
intertwine('11223344') --> '13132424'
def intertwine(text):
return ''.join([val+'' for pair in zip(text[:len(text)//2], text[len(text)//2:]) for val in pair])
Test.describe("Basic tests")
Test.assert_equals(intertwine('135246'), '123456')
Test.assert_equals(intertwine('11223344'), '13132424')
Test.assert_equals(intertwine('abracadabra!'),'adbarbarcaa!')
Swing list sorting:
Examples:
special_sort(list) -> list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] # input
[0, 9, 1, 8, 2, 7, 3, 6, 4, 5] # output
def special_sort(list):
r = []
l = len(list)
for i in range(l // 2 + 1):
if i == 0 or (i == l // 2 and not l % 2):
r.append(list[i])
else: r.extend([list[-i], list[i]])
return r
# 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(special_sort([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), [0, 9, 1, 8, 2, 7, 3, 6, 4, 5])
test.assert_equals(special_sort([0, 1, 2, 3, 4, 5, 6, 7, 8]), [0, 8, 1, 7, 2, 6, 3, 5, 4])
# test.assert_not_equals(actual, expected, [optional] message)
# You can use Test.describe and Test.it to write BDD style test groupings
Sebastian and Patricia want to know if the sum digits of their years is greater than the sum digits of their mother's years?
Example: (27,3,1)
- Mother = 27
- Sebastian = 3
- Patricia = 1
Calculate: (2+7) < (3+1) => false
public class AgeSumDigits
{
public static boolean SumOfDigits(int[] ages) {
int m = ages[0];
int s = ages[1];
int p = ages[2];
// Coding with passion ;)
return (calcSum(m) < calcSum(s)+calcSum(p)) ? true : false;
}
static int calcSum(int age){
int sum = 0;
while(age>0){
sum += age % 10;
age /= 10;
}
return sum;
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
public class SolutionTest {
AgeSumDigits asd = new AgeSumDigits();
@Test
public void testSumDigits() {
assertEquals(false, asd.SumOfDigits(new int[]{27,3,1}));
assertEquals(true, asd.SumOfDigits(new int[]{33,9,7}));
assertEquals(true, asd.SumOfDigits(new int[]{50,26,24}));
}
}
You have received 2 names.
Verify if the sum of letters of the 1 name is the same as sum of the letters of the 2 name. If the name or surname is null output NULL.
For example:
-
"Anna" and "Nana"
"Anna" = 65+110+110+97 = 382
"Nana" = 78+97+110+97 = 382
Result: "Anna" and "Nana" => "TRUE" -
"Sebastian" and "Patricia" => "FALSE"
-
"John" and null => "NULL"
class Kata{
public static String verifySum(String nameOne, String nameTwo) {
int[] sumOfNames = new int[]{0, 0};
if (nameOne == null || nameTwo == null) {
return "NULL";
}
for (int i = 0; i < nameOne.length(); i++){
sumOfNames[0] += nameOne.charAt(i);
}
for (int i = 0; i < nameTwo.length(); i++){
sumOfNames[1] += nameTwo.charAt(i);
}
return sumOfNames[0] == sumOfNames[1] ? "TRUE" : "FALSE";
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
public class SolutionTest {
@Test
public void testName() {
assertEquals("FALSE", Kata.verifySum("Sebastian", "Patricia"));
assertEquals("TRUE", Kata.verifySum("Anna", "Nana"));
assertEquals("NULL", Kata.verifySum("John", null));
}
}
#include <stdlib.h>
#include <string.h>
char *my_strdup_1(const char *str) {
const size_t len = strlen(str);
char *const res = malloc(len); // <- BUG
memcpy(res, str, len);
return res;
}
char *my_strdup_2(const char *str) {
const size_t len = strlen(str);
char *const res = malloc(len); // <- BUG
memcpy(res, str, len + 1);
return res;
}
#include <criterion/criterion.h>
#include <stdlib.h>
char *my_strdup_1(const char *str);
char *my_strdup_2(const char *str);
Test(my_strdup_1, should_work_correctly) {
static const char str[] = "Qwerty";
char *const res = my_strdup_1(str);
cr_assert_str_eq(res, str);
free(res);
}
Test(my_strdup_2, should_work_correctly) {
static const char str[] = "Qwerty";
char *const res = my_strdup_2(str);
cr_assert_str_eq(res, str);
free(res);
}
const interwine = str =>
[...str]
.reduce((r,_,i,s) =>
i%2 ?
[...r,s[(s.length+i-1)/2]] :
[...r,s[i/2]], [])
.join('')
Test.assertEquals(interwine('13572468'), '12345678');
Test.assertEquals(interwine('acegbdfh'), 'abcdefgh');