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.
const html = '<iframe width=100% height=640 src="https://stemkoski.github.io/Three.js/Particle-Engine.html"></iframe>';
console.log(html);
Determine number of decimal digits in an unsiged 64bit integer.
fn digits(mut n: u64) -> usize {
let mut l = 1;
while n >= 10 {
n /= 10;
l += 1;
}
l
}
#[test]
fn pow10() {
assert_eq!(digits(0), 1);
for i in 0..20 {
assert_eq!(digits(POW10[i]), i+1);
}
assert_eq!(digits(std::u64::MAX), 20);
}
#[test]
fn pow10_minus_1() {
for i in 1..20 {
assert_eq!(digits(POW10[i] - 1), i);
}
}
#[test]
fn pow10_half() {
for i in 1..20 {
assert_eq!(digits(POW10[i] / 2), i);
}
}
Return the factorial of a given input number.
Note that the number must be equal or greater than 1.
i.e.:
factorial(6) = 720
factorial(5) = 120
def factorial(x):
return 1 if x == 1 else x*factorial(x-1)
test.assert_equals(factorial(6), 720, "Wrong calculation!")
test.assert_equals(factorial(10), 3628800, "Wrong calculation!")
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char plaintext[100];
char ciphertext[100];
int length;
int key;
cout<<"enter the plain message\n\n";
cin.getline(plaintext,99,'\n');
cout<<"enter the key :";
cin>>key;
cout<<"----------\n";
cout<<"the cipher message\n\n";
length=strlen(plaintext);
int i = 0;
for(i=0;i<length;i++)
{
if(plaintext[i]==' ')
{
ciphertext[i]=' ';
cout<<ciphertext[i];
continue;
}
int y=(int)plaintext[i];
if (y>96)
{
y=y-32;
plaintext[i]=(char)y;
}
int x =((((int)plaintext[i]-65)+key)%26)+65;
ciphertext[i]=(char)x;
cout<<ciphertext[i];
}
cout<<"\n\n";
return(0);
}
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char plaintext[100];
char ciphertext[100];
int length;
int key;
cout<<"enter the plain message\n\n";
cin.getline(plaintext,99,'\n');
cout<<"enter the key :";
cin>>key;
cout<<"----------\n";
cout<<"the cipher message\n\n";
length=strlen(plaintext);
int i = 0;
for(i=0;i<length;i++)
{
if(plaintext[i]==' ')
{
ciphertext[i]=' ';
cout<<ciphertext[i];
continue;
}
int y=(int)plaintext[i];
if (y>96)
{
y=y-32;
plaintext[i]=(char)y;
}
int x =((((int)plaintext[i]-65)+key)%26)+65;
ciphertext[i]=(char)x;
cout<<ciphertext[i];
}
cout<<"\n\n";
return(0);
}
Code returns the int that is different from all other ints in an array. Function takes odd size array that contains all the same ints except for 1
int stray(std::vector<int> numbers) {
for(auto n = numbers.begin(); n != numbers.end(); ++n ){
if (*n != numbers[0]) {
if (*n != *(n + 1))
return *n;
else
return numbers[0];
}
}
};
// TODO: Replace examples and use TDD development by writing your own tests
Describe(array)
{
It(should_do_something)
{
Assert::That(stray({0,1,1,1}), Equals(0));
}
};
Sometimes one has a vector with pairs (key, value), where one wants to fold over all the values with the same key.
What is the best way to do that in Rust?
The example uses a vector, but perhaps it would be better with an iterator as argument, to make it more general?
fn reduce<TK, TV, TS, F>(v : Vec<(TK, TV)>,
s : TS,
f : F) -> Vec<(TK, TV)>
where F : Fn(TS, TV) -> TS {
// Code
vec![]
}
// Rust test example:
// TODO: replace with your own tests (TDD), these are just how-to examples.
// See: https://doc.rust-lang.org/book/testing.html
#[test]
fn returns_summariesed_word_count() {
assert_eq!(reduce(vec![("a", 2), ("b", 1), ("a", 1)],
0,
|s, v| s + v), vec![("a", 3), ("b", 1)])
}
Array and looping are in old-love story . Tonight we gonna play the game by separae them . given integer array , we want to sort it without the use of any kind of arrays .
Hint ::
You can write it in one line - Code
def sortinggggggggggg (arr) :
Soreteddddd = sorted (arr)
return Soreteddddd
sortinggggggggggg ([2,0,25,3])
# 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
Kumite Experiment!
public class HelloWorld
{
public static int Execute()
{
System.out.println("My first Kumite");
return 1;
}
}
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("expected", "actual");
assertEquals(1,HelloWorld.Execute());
}
}
given we are anonymous
then should say "Hello World!"
given we are "McFly"
then should say "Hello McFly!"
function sayHello() {
}
describe("given we are annonymous", () => {
it("should say hello world", () => {
Test.assertEquals(sayHello(), "Hello World!");
});
});
Function 'pick' in the Underscore.js (http://underscorejs.org/#pick)
"Return a copy of the object, filtered to only have values for the whitelisted keys (or array of valid keys). Alternatively accepts a predicate indicating which keys to pick."
_.pick({name: 'moe', age: 50, userid: 'moe1'}, 'name', 'age');
// {name: 'moe', age: 50}
_.pick({name: 'moe', age: 50, userid: 'moe1'}, function(value, key, object) {
return typeof value == 'number';
});
// {age: 50}
var _ = {};
_.pick = (target, ...keys) => {
if (typeof keys[0] == 'function') {
var predicate = keys[0];
keys = Object.keys(target);
return keys.reduce((obj, key) => {
return predicate(target[key], key, target) ? (obj[key] = target[key], obj) : obj;
}, {})
}
return keys.reduce((obj, key) => {
return obj[key] = target[key], obj;
}, {});
};
var result;
result = _.pick({name: 'moe', age: 50, userid: 'moe1'}, 'name', 'age');
Test.assertSimilar(result, {name: 'moe', age: 50});
result = _.pick({name: 'moe', age: 50, userid: 'moe1'}, function(value, key, object) {
return typeof value == 'number';
});
Test.assertSimilar(result, {age: 50});