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.
#debug
#import combinators.lc
B = \ f g x . f (g x)
I = \ x . x
K = \ x _ . x
T = \ x f . f x
#import binary-scott-number.lc
# 0 = \ end _even _odd . end
Bit0 = \ n . \ _end even _odd . even n
Bit1 = \ n . \ _end _even odd . odd n
shift = \ n . n 0 I I
dbl = \ n . n 0 (K (Bit0 n)) (K (Bit0 n))
succ = \ n . n 1 Bit1 (B Bit0 succ)
pred = \ n . n 0 (B Bit1 pred) dbl
add = \ m n . m n
( \ zm . n m (B Bit0 (add zm)) (B Bit1 (add zm)) )
( \ zm . n m (B Bit1 (add zm)) (B Bit0 (B succ (add zm))) )
mul = \ m n . m 0
( \ zm . n 0
( \ zn . Bit0 (Bit0 (mul zm zn)) )
( \ _z . Bit0 (mul zm n) )
)
( \ zm . n 0
( \ zn . Bit0 (mul m zn) )
( \ zn . Bit1 (add (dbl (mul zm zn)) (add zm zn)) )
)
#import scott-tree.lc
Tree = \ x left right . \ tree . tree x left right # Tree = Tree Number Tree Tree
map = \ fn tree . tree \ x left right . Tree (fn x) (map fn left) (map fn right)
index = \ tree i . tree \ x left right . i x (B (index right) pred) (index left)
tree = Tree 1 (map Bit0 tree) (map Bit1 tree)
memo = \ fn . index (map (B fn pred) tree)
# fibonacci :: Number -> Number
fibonacci = memo \ n .
T (shift (succ n)) \ n' .
T (fibonacci n') \ fn .
T (fibonacci (pred n')) \ fn' .
n 0 # n == 0
(K (mul fn (add fn (Bit0 fn')))) # even n
( \ z . z 1 # n == 1
(K (add (mul fn fn) (mul fn' fn'))) # odd n
(K (add (mul fn fn) (mul fn' fn'))) # odd n
)
import { assert, LC, getSolution } from "./lc-test.js";
LC.configure({ purity: "LetRec", numEncoding: "BinaryScott", verbosity: "Calm" });
const { fibonacci: usrFibonacci } = LC.compile(getSolution());
const toBigInt = n => n (0n) ( n => 2n * toBigInt(n) ) ( n => 1n + 2n * toBigInt(n) ) ;
const fibonacci = n => toBigInt(usrFibonacci(n)) ;
const refFibonacci = n => function go(n,a,b) { return n ? go(n-1,b,a+b) : a ; } ( n, 0n, 1n ) ;
describe("Fibonacci", () => {
it("smaller example tests", () => {
assert.equal( fibonacci(0), 0n );
assert.equal( fibonacci(1), 1n );
assert.equal( fibonacci(2), 1n );
assert.equal( fibonacci(3), 2n );
assert.equal( fibonacci(4), 3n );
assert.equal( fibonacci(5), 5n );
});
it("larger example tests", () => {
assert.equal( fibonacci(10), 55n );
assert.equal( fibonacci(20), 6765n );
assert.equal( fibonacci(30), 832040n );
assert.equal( fibonacci(40), 102334155n );
assert.equal( fibonacci(50), 12586269025n );
});
it("huge example test", () => { // takes 7½ seconds on a good day, 10 on a bad
// assert.equal( fibonacci(800), refFibonacci(800) );
assert.equal( fibonacci(800), 69283081864224717136290077681328518273399124385204820718966040597691435587278383112277161967532530675374170857404743017623467220361778016172106855838975759985190398725n ); // 555 bits
});
});
function angka($a , $b) {
if ($a != 0 || $b != 0){
echo "ada angka. \n";
if( $a > 10 || $b > 10 ){
echo "angka lebih dari 10. \n";
if($a < $b) {
echo "a lebih besar dari b. \n";
} else {
echo "b lebih besar dari a. \n";
}
} else {
echo "angka kurang dari 10. \n";
}
} else{
echo "tidak ada angka.";
}
}
angka(11,11);
<?php
use PHPUnit\Framework\TestCase;
// PHPUnit Test Examples:
// TODO: Replace examples and use TDD by writing your own tests
class ExampleTest extends TestCase
{
// test function names should start with "test"
public function testThatSomethingShouldHappen() {
$this->assertEquals(11, 11);
$this->assertEquals([0], [0]);
}
}
Should return sum of two elements
def sum(i1, i2)
i1 + i2
end
# From Ruby 3.0, RSpec is used under the hood.
# See https://rspec.info/
# Defaults to the global `describe` for backwards compatibility, but `RSpec.desribe` works as well.
describe "Example" do
it "should return the sum" do
expect(sum(1, 1)).to eq(2)
# The following is still supported, but new tests should now use them.
# Test.assert_equals(add(1, 1), 2)
end
end
import javax.swing.JOptionPane;
public class Loop{
public static void main(String[] args){
while(1!=0){
JOptionPane.showMessageDialog(null, "Annoying");
}
}
}
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
// TODO: Replace examples and use TDD by writing your own tests
class SolutionTest {
@Test
void testSomething() {
// assertEquals("expected", "actual");
}
}
Given a matrix M and a vector v, linearly transform the vector using the matrix.
ex:
const M = [[2,0],[0,2]]
const v = [1,1]
transform(M, v); // [2,2]
More examples:
const M = [[2,2],[3,2]]
const v = [1,1]
transform(M, v); // [5,4]
const M = [[2,0],[0,2]]
const v = [2,3]
transform(M, v); // [4,6]
const M = [[2,5],[0,3]]
const v = [1,2]
transform(M, v); // [5,5]
function transpose(A) {
let arrs = []
/*
|4 5| -> |4 6|
|6 7| |5 7|
[[4,5], [6,7]] -> [[4,6], [5,7]]
*/
A.forEach((x,i)=>{
x.forEach((v,i2)=>{
if(!arrs[i2]){
arrs[i2] = [v]
}else arrs[i2].push(v)
})
})
return arrs
}
function scale(v,a) {
let ret = []
v.forEach((x,i)=>{
ret.push(x*a)
})
return ret
}
function transform(M, a) {
let m = transpose(M)
let ae = []
a.forEach((x,i)=>{
ae.push(scale(m[i], x))
})
return sum(ae)
}
function sum(v) {
let s = v[0]
v.forEach((x,i)=>{
if(i == 0) return
x.forEach((y)=>{
s[i] += y
})
})
return s
}
const chai = require("chai");
const assert = chai.assert;
chai.config.truncateThreshold = 0;
describe("Fixed tests", function() {
// |2,0;0,2| & |1,1|
it("Test 1", function() {
assert.strictEqual(transform([[2,0],[0,2]],[1,1]).toString(), [2,2].toString());
});
// it("3*4*2", function() {
// assert.strictEqual(30, 30);
// });
});
обычный простой калькулятор, но с использованием степеней
#include <iostream>
int main()
{
string operator = "+";
int a = 5, b = 6;
cin >> a >> opearator >> b;
//5 + 6 = 11
}
// TODO: Replace examples and use TDD by writing your own tests
Describe(any_group_name_you_want)
{
It(should_do_something)
{
Assert::That("some value", Equals("another value"));
}
};
жлджлджлд
def solution(s):
newStr = ''
for i in s:
newStr += i
if i.isupper() == True:
newStr = newStr[:-1]
newStr += ' ' + i
return newStr
test.assert_equals(solution("helloWorld"), "hello World")
test.assert_equals(solution("camelCase"), "camel Case")
test.assert_equals(solution("breakCamelCase"), "break Camel Case")
const board = [];
let player = "X";
for (let i = 0; i < 3; i++) {
board.push([" ", " ", " "]);
}
const printBoard = () => {
console.log(` ${board[0][0]} | ${board[0][1]} | ${board[0][2]} `);
console.log("---+---+---");
console.log(` ${board[1][0]} | ${board[1][1]} | ${board[1][2]} `);
console.log("---+---+---");
console.log(` ${board[2][0]} | ${board[2][1]} | ${board[2][2]} `);
};
const makeMove = (row, col) => {
board[row][col] = player;
player = player === "X" ? "O" : "X";
};
const isWin = () => {
for (let i = 0; i < 3; i++) {
if (board[i][0] === board[i][1] && board[i][1] === board[i][2] && board[i][0] !== " ") {
return true;
}
if (board[0][i] === board[1][i] && board[1][i] === board[2][i] && board[0][i] !== " ") {
return true;
}
}
if (board[0][0] === board[1][1] && board[1][1] === board[2][2] && board[0][0] !== " ") {
return true;
}
if (board[0][2] === board[1][1] && board[1][1] === board[2][0] && board[0][2] !== " ") {
return true;
}
return false;
};
printBoard();
makeMove(0, 0);
printBoard();
makeMove(1, 1);
printBoard();
makeMove(2, 2);
printBoard();
console.log(isWin());
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});
You're an author on CW.
Here is an 2D array. Pass it to user's function, and then receive it.
To determine whether array is modified.
Returns true
if modified. Otherwise returns false
.
var count=0
const dontTouchMyArray=(array,usersFunction)=>{
console.log("array:",array)
/*
var myArr=array.slice(),myArrs=array.map(x=>x.slice())
var userArr=usersFunction(array)
console.log(myArr)
console.log(myArrs)
console.log(userArr)
*/
/* Can you write a good solution heer? */
return ++count<12
}
const chai = require("chai");
const assert = chai.assert;
const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("test for bad users", function() {
var array=[[1,2,3],[4,5,6],[7,8,9]],
badUser1=arr=>{
arr[1][0]=0
return arr
},
badUser2=arr=>{
arr[1][0]=4n
return arr
},
badUser3=arr=>{
arr[1]=[0,0,0]
return arr
},
badUser4=arr=>{
arr[1]=[4,5,6,7]
return arr
},
badUser5=arr=>{
arr[1]=[4,5,6,,]
return arr
},
badUser6=arr=>{
arr[1]=[4,5,6]
return arr
},
badUser7=arr=>{
arr[1]={0:4,1:5,2:6}
return arr
},
badUser8=arr=>{
arr[1]="arr[1]"
return "This is your array."
},
badUser9=arr=>{
for(var i=0;i<arr.length;i++) console.log(arr[i])
/* return arr */
},
badUser10=arr=>{
for(var i=0;i<arr.length;i++) console.log(arr[i])
return arr.slice(0,1)
},
badUser11=arr=>{
for(var i=0;i<arr.length;i++) console.log(arr[i])
return arr[1]
}
Test.assertEquals(dontTouchMyArray(array,badUser1), true);
Test.assertEquals(dontTouchMyArray(array,badUser2), true);
Test.assertEquals(dontTouchMyArray(array,badUser3), true);
Test.assertEquals(dontTouchMyArray(array,badUser4), true);
Test.assertEquals(dontTouchMyArray(array,badUser5), true);
Test.assertEquals(dontTouchMyArray(array,badUser6), true);
Test.assertEquals(dontTouchMyArray(array,badUser7), true);
Test.assertEquals(dontTouchMyArray(array,badUser8), true);
Test.assertEquals(dontTouchMyArray(array,badUser9), true);
Test.assertEquals(dontTouchMyArray(array,badUser10), true);
Test.assertEquals(dontTouchMyArray(array,badUser11), true);
});
it("test for good users", function() {
var array=[[1,2,3],[4,5,6],[7,8,9]],
goodUser1=arr=>{
return arr
},
goodUser2=arr=>{
var arr1=arr.slice()
arr1[1][1]=0
return arr
},
goodUser3=arr=>{
var t1=arr[1][1], t2=arr[1]
arr[1][1]=12432234
arr[1]={0:4,1:5,2:6}
/* After doing something */
arr[1][1]=t1
arr[1]=t2
return arr
}
Test.assertEquals(dontTouchMyArray(array,goodUser1), false);
Test.assertEquals(dontTouchMyArray(array,goodUser2), false);
Test.assertEquals(dontTouchMyArray(array,goodUser3), false);
});
});