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.
write a divide program
def div(num1, num2):
return(num1 / num2)
test.assert_equals(div(50, 10), 5)
test.assert_equals(div(10, 5), 2)
test.assert_equals(div(100, 10), 10)
test.assert_equals(div(64, 8), 8)
test.assert_equals(div(30, 6), 5)
test.assert_equals(div(55, 5), 11)
test.assert_equals(div(144, 12), 12)
test.assert_equals(div(66, 6), 11)
test.assert_equals(div(132, 12), 11)
test.assert_equals(div(1, 1), 1)
Input any number and this will return what number is in that place in the Fibonacci sequence
def fibonacci(x):
if x == 0:
return 0
elif x == 1:
return 1
else :
return fibonacci(x-1) + fibonacci(x-2)
# 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(fibonacci(8),21 )
# test.assert_not_equals(actual, expected, [optional] message)
# You can use Test.describe and Test.it to write BDD style test groupings
In international chess, a knight is a chess piece which can move in an L-shape (possibly mirrored) of size 2x1 in any orientation. Due to its unique movement patterns, it is the only chess piece able to "jump" past chess pieces of any color that may be blocking its way.
However, what is more interesting is that its movement patterns allow it to move to any desired square on a given chessboard provided that no same-color chess piece is occupying that desired square. This Haskell program seeks to prove this statement, extending the chessboard to an infinite chessboard (in the rightwards and upwards directions) characterized by an ordered tuple of natural numbers.
{-# LANGUAGE KindSignatures, GADTs #-}
module KnightsOnAChessboard where
-- Peano's axioms for the natural numbers
data Z
data S n
-- Definition of natural numbers (to prevent nonsensical types like `S Bool`)
data Natural :: * -> * where
NumZ :: Natural Z
NumS :: Natural n -> Natural (S n)
-- Legal moves of a knight in international chess
data KnightCanReach :: * -> * where
NoMoves :: KnightCanReach (Z, Z)
MoveRL :: KnightCanReach (n, m) -> KnightCanReach (S (S n), S m)
MoveRR :: KnightCanReach (n, S m) -> KnightCanReach (S (S n), m)
MoveUL :: KnightCanReach (S n, m) -> KnightCanReach (n, S (S m))
MoveUR :: KnightCanReach (n, m) -> KnightCanReach (S n, S (S m))
MoveLL :: KnightCanReach (S (S n), S m) -> KnightCanReach (n, m)
MoveLR :: KnightCanReach (S (S n), m) -> KnightCanReach (n, S m)
MoveDL :: KnightCanReach (n, S (S m)) -> KnightCanReach (S n, m)
MoveDR :: KnightCanReach (S n, S (S m)) -> KnightCanReach (n, m)
-- Proof that knight can reach any square on a chessboard starting from (0, 0)
knightCanMoveAnywhere :: Natural n -> Natural m -> KnightCanReach (n, m)
knightCanMoveAnywhere NumZ NumZ = NoMoves
knightCanMoveAnywhere NumZ (NumS n) =
MoveDR $ MoveUL $ MoveRL $ knightCanMoveAnywhere NumZ n
knightCanMoveAnywhere (NumS n) m =
MoveLL $ MoveRR $ MoveUR $ knightCanMoveAnywhere n m
module DummySpec where
import Test.Hspec
import KnightsOnAChessboard
spec :: Spec
spec = do
describe "Proof for \"Knights On A Chessboard\"" $ do
it "should type-check" $ do
"Proof" `shouldNotBe` "Good luck!"
Define a method/function that removes from a given array of integers all the values contained in a second array.
Examples:
int[] integerList = new int[]{ 1, 2, 2, 3, 1, 2, 3, 4 }
int[] valuesList = new int[]{ 1, 3 }
Kata.Remove(integerList, valuesList) == new int[]{ 2, 2, 4 } // --> true
int[] integerList = new int[]{ 1, 1, 2, 3, 1, 2, 3, 4, 4, 3 ,5, 6, 7, 2, 8 }
int[] valuesList = new int[]{ 1, 3, 4, 2 }
Kata.Remove(integerList, valuesList) == new int[]{ 5, 6 ,7 ,8 } // --> true
int[] integerList = new int[]{ 8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2 , 3 }
int[] valuesList = new int[]{ 2, 4, 3 }
Kata.Remove(integerList, valuesList) == new int[]{ 8, 7, 6, 5, 1 } // --> true
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Kata
{
public static int[] Remove(int[] integerList,int[] valuesList)
{
if (integerList==null||integerList.length<1) return new int[0];
if (valuesList==null||valuesList.length<1) return integerList;
List<Integer> list= Arrays.stream(valuesList).boxed().collect(Collectors.toList());
return Arrays.stream(integerList).filter(i->!list.contains(i)).toArray();
}
}
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.runners.JUnit4;
import java.util.Arrays;
// TODO: Replace examples and use TDD development by writing your own tests
public class SolutionTest {
@Test
public void test1()
{
int[] integerList = new int[]{ 1, 1, 2, 3, 1, 2, 3, 4 };
int[] valuesList = new int[]{ 1, 3 };
assertTrue(Arrays.equals(new int[]{ 2, 2, 4 },Kata.Remove(integerList,valuesList)));
}
@Test
public void test2()
{
int[] integerList = new int[]{1, 1, 2, 3, 1, 2 ,3 , 4, 4, 3 ,5, 6, 7, 2, 8 };
int[] valuesList = new int[]{1, 3, 4, 2 };
assertTrue(Arrays.equals(new int[]{ 5, 6 ,7 ,8 },Kata.Remove(integerList,valuesList)));
}
@Test
public void test3()
{
int[] integerList = new int[]{8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2 , 3 };
int[] valuesList = new int[]{2, 4, 3 };
assertTrue(Arrays.equals(new int[]{ 8, 7, 6, 5, 1 },Kata.Remove(integerList,valuesList)));
}
@Test
public void nullTest1()
{
int[] integerList = null;
int[] valuesList = new int[]{2, 4, 3 };
assertTrue(Arrays.equals(new int[]{},Kata.Remove(integerList,valuesList)));
}
@Test
public void nullTest2()
{
int[] integerList = new int[]{8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2 , 3 };
int[] valuesList = null;
assertTrue(Arrays.equals(new int[]{8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2 , 3 },Kata.Remove(integerList,valuesList)));
}
}
It is not uncommon to see a middle schooler incorrectly simplify the expression (a + b)^2
to a^2 + b^2
in his/her algebra assignments. While the two expressions may be equivalent for particular values of a
and b
(e.g. (0 + 0)^2 = 0^2 = 0 + 0^2 = 0^2 + 0^2
), it is not true in general. So, how can we convince said middle-schooler that (a + b)^2
is not equal to a^2 + b^2
in general? This is equivalent to saying:
-- N.B. The domain of a, b is the natural numbers for
-- sake of simplicity
exists a b. (a + b)^2 /= a^2 + b^2
The general method for proving statements involving existential quantifiers is to provide a specific value or set of values such that the statement to be proven holds true - such value(s) are called witnesses. So, for example, we could provide the witnesses a = 1
and b = 1
in our case which reduces the statement to:
(1 + 1)^2 /= 1^2 + 1^2
And, of course, evaluating both sides of our equation gives 4 /= 2
which trivially holds.
Unfortunately, there is no direct way to encode existential quantifiers (and inequality) as a Haskell type. So what we could do is transform our original statement using known logical equivalences. The first thing to notice is that a /= b
is defined as not (a = b)
for any a, b:
exists a b. not ((a + b)^2 = a^2 + b^2)
Then, de Morgan's law for quantifiers tells us that exists a. not b
is logically equivalent to not (forall a. b)
for any b
(which may or may not be related to a
). Finally, to prove that not (forall a. b)
, it suffices to prove that asserting forall a. b
leads to a contradiction (Void
in Haskell). So our final type (minus a bit of required Haskell boilerplate code) is:
(forall a b. (a + b)^2 = a^2 + b^2) -> Void
See the code provided for the exact type signature of our proof and additional clarifications/explanations.
{-# LANGUAGE
KindSignatures,
GADTs,
TypeOperators,
TypeFamilies,
UndecidableInstances,
RankNTypes,
EmptyCase #-}
module TheMiddleSchoolersMistake where
-- Void - the type representing contradictions in Haskell
import Data.Void
-- Peano's axioms for the natural numbers
data Z
data S n
data Natural :: * -> * where
NumZ :: Natural Z
NumS :: Natural n -> Natural (S n)
-- Axiom of reflexivity of equality: The very notion
-- of equality itself mandates that everything be
-- considered equal to itself
data (:=:) :: * -> * -> * where
Refl :: a -> a :=: a
-- Peano addition, multiplication and exponentation
type family (:+:) (n :: *) (m :: *) :: *
type instance Z :+: n = n
type instance S n :+: m = S (n :+: m)
type family (:*:) (n :: *) (m :: *) :: *
type instance Z :*: n = Z
type instance S n :*: m = m :+: (n :*: m)
type family (:^:) (n :: *) (m :: *) :: *
type instance n :^: Z = S Z
type instance n :^: S m = n :*: (n :^: m)
-- Useful type synonyms for readability
type N1 = S Z -- The natural number 1
type N2 = S N1 -- The natural number 2
type N4 = N2 :+: N2 -- The natural number 4
-- Our proof that (a + b)^2 /= a^2 + b^2 in general
proof ::
(forall n m.
Natural n ->
Natural m ->
((n :+: m) :^: N2) :=: ((n :^: N2) :+: (m :^: N2))) -> Void
proof mistake = let
-- 1 is a natural number
one :: Natural N1
one = NumS NumZ
-- To disprove (a + b)^2 = a^2 + b^2, we provide witnesses
-- a = 1, b = 1 to our counterexample. A witness is a
-- value demonstrating the correctness of a logical statement
-- involving existential quantifiers
-- N.B. The witnesses could be anything else as long as it
-- proves our point. For example, we could've chosen a = 2,
-- b = 3 instead and show that (2 + 3)^2 = 5^2 = 25 /= 13 =
-- 2^2 + 3^2
erroneous :: N4 :=: N2
erroneous = mistake one one in
-- Now we consider all possible cases where 4 = 2 and
-- describe how to construct a proof of Void in each case
-- However, there are no constructors that would allow us
-- to construct a value of such a type! The only possible
-- constructor we could consider is Refl, but Refl always
-- constructs values of a :=: a, never a :=: b where a and
-- b are distinct types. Therefore, we have already
-- considered all (0) possible cases of 4 = 2 and we are
-- done here.
case erroneous of {}
module DummySpec where
import Test.Hspec
import TheMiddleSchoolersMistake
spec :: Spec
spec = do
describe "Proof" $ do
it "should type-check" $ do
"Proof" `shouldNotBe` "Good luck!"
Update getIDS to get the iterated digit sum.
The iterated digit sum of 1563 e.g is 1 + 5 + 6 + 3 = 15.
function getIDS($number) {
return array_sum(str_split($number));
}
// PHPUnit Test Examples:
// TODO: Replace examples and use TDD development by writing your own tests
class MyTestCases extends TestCase
{
// test function names should start with "test"
public function testOutput() {
$this->assertEquals(getIDS(1345), 13);
$this->assertEquals(getIDS(12), 3);
}
}
Write a function which would take two figures as a parameters and generate List of numbers which would contains figures from 1 fo n (n - first input) and lenght of each number should be equals to n .
Then return number at m position ( m - second input).
If number at that position doesn't exist return -1;
Examples :
Generator(2 ,3) => 11 12 21 22
should return 21
Generator(3, 10) => 111 112 113 121 122 123 131 132 133 211 212 213 221 222 223 231 232 233 311 312 313 321 322 323 331 332 333
should return 211
Good luck :)
using System;
using System.Linq;
using System.Collections.Generic;
public class NumbersFinder
{
public static int Generator(int size , int position){
if ( Math.Pow( size , size ) < position )
return -1;
List<string> arr = new List<string>();
for (int i = 0; i < size; ++i)
arr.Add((i+1).ToString());
List<string> newArr;
while (arr.Count != Math.Pow(size,size)){
newArr = new List<string>();
for (int j = 0; j < arr.Count; j++)
for (int i = 0; i < size; i++)
newArr.Add(arr[j]+(i+1));
arr.Clear();
arr.AddRange(newArr);
}
return Convert.ToInt32(arr[position - 1]);
}
}
using NUnit.Framework;
using System;
using System.Collections.Generic;
[TestFixture]
public class SolutionTest
{
[Test]
public void MyTest()
{
Assert.AreEqual(1 , NumbersFinder.Generator(1 , 1));
Assert.AreEqual(51445 , NumbersFinder.Generator(5 , 2595));
Assert.AreEqual(2573176 , NumbersFinder.Generator(7 , 200017));
Assert.AreEqual(-1 , NumbersFinder.Generator(4 , 257));
}
}
Challenge
Implement a linked list function
const linkedList = {
list: {},
addNode: {}
}
// TODO: Replace examples and use TDD development by writing your own tests
// These are some CW specific test methods available:
// Test.expect(boolean, [optional] message)
// Test.assertEquals(actual, expected, [optional] message)
// Test.assertSimilar(actual, expected, [optional] message)
// Test.assertNotEquals(actual, expected, [optional] message)
// NodeJS assert is also automatically required for you.
// assert(true)
// assert.strictEqual({a: 1}, {a: 1})
// assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]})
// You can also use Chai (http://chaijs.com/) by requiring it yourself
// var expect = require("chai").expect;
// var assert = require("chai").assert;
// require("chai").should();
describe("Solution", function(){
// it("should test for something", function(){
// Test.assertEquals("actual", "expected", "This is just an example of how you can write your own TDD tests");
// });
});
const linkedList = {};
// TODO: Replace examples and use TDD development by writing your own tests
// These are some CW specific test methods available:
// Test.expect(boolean, [optional] message)
// Test.assertEquals(actual, expected, [optional] message)
// Test.assertSimilar(actual, expected, [optional] message)
// Test.assertNotEquals(actual, expected, [optional] message)
// NodeJS assert is also automatically required for you.
// assert(true)
// assert.strictEqual({a: 1}, {a: 1})
// assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]})
// You can also use Chai (http://chaijs.com/) by requiring it yourself
// var expect = require("chai").expect;
// var assert = require("chai").assert;
// require("chai").should();
describe("Solution", function(){
it("should test for something", function(){
Test.assertEquals(linkedList, linkedList, "This is just an example of how you can write your own TDD tests");
});
});
Validate a porperty in object
function validateProperty(objectForValidate, specificProperty) {
if(objectForValidate[specificProperty]){
return true;
} else{
return false;
}
}
describe("Validate property in object", function(){
it("should be return true when the property exists", function(){
const test = { a: 2 };
const validation = validateProperty(test, 'a');
Test.assertEquals(validation, true);
});
it("should be return false when the property not exists", function(){
const test = {};
const validation = validateProperty(test, 'a');
Test.assertEquals(validation, false);
});
it("should be return false when the property is equals to empty", function(){
const test = { a: '' };
const validation = validateProperty(test, 'a');
Test.assertEquals(validation, false);
});
});