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.
take a number as input say (n) and add all the digit of this numnber until result is not equal to a single digit no.
EX. 1245358,
output=1+2+4+5+3+5+8=28, 28=2+8=10, 10=1+0=1
so, output=1
n=int(input())
for i in range(n):
add=add+n[i]
if add>9:
while add<10:
for j in range(add):
add+=add[j]
print(add)
else:
print(add)
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(1 + 1, 2)
A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.
For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binary representation 10100 and contains one binary gap of length 1. The number 15 has binary representation 1111 and has no binary gaps. The number 32 has binary representation 100000 and has no binary gaps.
Write a function:
that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap.
For example, given N = 1041 the function should return 5, because N has binary representation 10000010001 and so its longest binary gap is of length 5. Given N = 32 the function should return 0, because N has binary representation '100000' and thus no binary gaps.
function binaryGap($n) {
}
<?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(5, binaryGap(1041));
$this->assertEquals(9, binaryGap(9));
$this->assertEquals(0, binaryGap(15));
}
}
def abbrev(str):
return str[0] + str(len(str[1::-1])) + str[-1]
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(1 + 1, 2)
unit module Solution;
error-here
use Test;
use Solution;
pass();
done-testing;
const s = `6,3,15,13,1,0`;
const input = s.split(',').map(Number);
const a = Array(2020);
const indexes = {};
const lastIndexes = {};
input.forEach((x, i) => ((a[i] = x), (indexes[x] = i), (lastIndexes[x] = i === input.length - 1 ? -1 : i)));
for (let i = input.length; i < 2020; i++) {
const x = a[i - 1];
if (indexes[x] === i - 1) {
a[i] = 0;
if (indexes[0] === undefined) indexes[0] = i;
lastIndexes[x] = i - 1;
continue;
}
a[i] = i - 1 - lastIndexes[x];
lastIndexes[x] = i - 1;
if (indexes[a[i]] === undefined) indexes[a[i]] = i;
}
console.log(a[2020 - 1]);
const add = (a, b) => a + b + 1;
const { assert } = require("chai");
const fc = require('fast-check');
describe("Solution", () => {
it("should test for something", () => {
fc.assert(fc.property(fc.integer(1, 100), fc.integer(1, 100), (a, b) => {
assert.equal(add(a, b), a + b);
}));
});
});
Ваша задача - написать тело функции которая будет вычислять формулы.
Формула передаётся через параметр forlmula
. Формулы могут содержать в себе все значения, но также можно передать переменные вида $1
, $2
, $3
и т.д.
Значения переменных передаются вторым параметром в неограниченном кол-ве.
Посмотрите тесты что бы понять что от вас требуется.
Удачи! Она вам потребуется ;)
======
Your task is to write the body of a function that will calculate formulas.
The formula is passed through the forlmula
parameter. Formulas can contain all values, but you can also pass variables like $1
, $2
, $3
, etc.
Variable values are passed as the second parameter in an unlimited number.
Look at the tests to understand what is required of you.
Good luck! You will need it;)
using System;
public class Calculator
{
public static float Calculate(string forlmula, params float[] values)
{
// your code
}
}
using System;
using NUnit.Framework;
[TestFixture]
public class KataTests {
[Test]
public static void MyTest()
{
Assert.AreEqual(10, Calculator.Calculate("(2 + 3) * 4 / 2"));
Assert.AreEqual(25, Calculator.Calculate("50 - 10 * 2.5"));
Assert.AreEqual(3, Calculator.Calculate("2 ^ 3 - 1 * 5"));
Assert.AreEqual(5, Calculator.Calculate("2 + |-(-20 + 50)| / (5 * 2)"));
Assert.AreEqual(40, Calculator.Calculate("$1 * $2 - $1", 5, 9));
}
}
module Kata where
add_ :: Int -> Int -> Int
add_ a b = a + b
module ExampleSpec where
import Test.Hspec
import Test.QuickCheck
import Data.Foldable (for_)
import Kata
spec :: Spec
spec = do
describe "test" $ do
it "test" $ do
for_ tests $ \ (a, b) -> shouldBe a b
shouldBe 1 1
tests = [(add_ 1 2, 3), (add_ 10 20, 30), (add_ 30 40, 70)]
I would love to see a generator which accepts [(Gen s, Int)] and uses a set of generators, generates n inputs from each of them, shuffles them, and uses the inputs to feed test cases.
For example, for "Is a number prime?" kata, I'd like to have a composite generator built like compositeGen([(genPrimes, 100), (genOddComposites, 100), (genNegativePrime, 10), (genSquareOfAPrime, 20)]) or something like this, and it would run test cases over 230 shuffled inputs.
Bonus points if such generator were able to generate not only Int, but also (Int, Bool) (input + expected answer) or even (Int, Bool, String) (input, expected answer, and assertion message).
The one thing I can't fix is that if it fails, it's always after 1 test. Because that's what it sees.
module Example (isPrime) where
isPrime :: Int -> Bool
isPrime = odd
module ExampleSpec (spec) where
import Example (isPrime)
import Test.Hspec hiding (shouldBe)
import Test.QuickCheck
import Data.Foldable (for_)
import Control.Monad (unless,replicateM)
import Data.List ((\\))
import Data.Traversable (for,mapM)
type Input = Int
type Actual = Bool
type Expected = Actual -- necessarily
type Message = String
solution :: Input -> Actual
solution = isPrime
primes,composites :: [Input]
primes = [2,3,5,7,11,13,17,19]
composites = [1..20] \\ primes
genPrimes :: Gen (Input,Expected,Message)
genPrimes = ( \ prime -> (prime,True,show prime ++ " is prime") ) <$> elements primes
genComposites :: Gen (Input,Expected,Message)
genComposites = ( \ composite -> (composite,False,show composite ++ " is composite") ) <$> elements composites
-- generators could also use a reference solution
spec :: Spec
spec = do
it "random tests" $ do
once $ forAllBlind (gen [(genPrimes,50),(genComposites,100)]) $ \ tests -> do
for_ tests $ \ (arg,expected,msg) -> do
print arg
solution arg `shouldBe` expected $ msg
-- can also factor out the specific plumbing
it "random tests" $ do
forAllGenerators [(genPrimes,50),(genComposites,100)] $ \ (arg,expected,msg) -> do
print arg
solution arg `shouldBe` expected $ msg
gen :: [(Gen (Input,Expected,Message),Int)] -> Gen [(Input,Expected,Message)]
gen gens = do
shuffle =<< concat <$> for gens ( \ (gen,n) -> replicateM n gen )
forAllGenerators :: [(Gen (Input,Expected,Message),Int)] -> ((Input,Expected,Message) -> Expectation) -> Property
forAllGenerators gens prop = do
once $ forAllBlind (gen gens) $ \ tests -> do
for_ tests prop
shouldBe :: (Show a,Eq a) => a -> a -> Message -> Expectation
shouldBe actual expected msg = unless (actual == expected) $ expectationFailure $ concat [ msg, "\nexpected : ", show expected, "\nbut got : ", show actual ]
-- a shouldBe that can show a message
give me two candy!
pekora(a,b)=> 'candy';
add(a)=> 'candy';