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.
puzzle = {0 : [0,0,0,0,0,0,0,0,0],
1 : [0,3,0,0,0,0,1,6,0],
2 : [0,6,7,0,3,5,0,0,4],
3 : [6,0,8,1,2,0,9,0,0],
4 : [0,9,0,0,8,0,0,3,0],
5 : [0,0,2,0,7,9,8,0,6],
6 : [8,0,0,6,9,0,3,5,0],
7 : [0,2,6,0,0,0,0,9,0],
8 : [0,0,0,0,0,0,0,0,0]
}
def makeGrid(puzzle):
for a in list(range(1,10)):
#print('Checking for: {}'.format(a))
grid = []
# Set block list
blockList = []
for x in puzzle:
row = []
y = 0
for n in puzzle[x]:
if n == a:
row.append(0)
blockList.append([x,y])
elif n != 0:
row.append(1)
else:
row.append(0)
y += 1
grid.append(row)
# Block using standard logic
for b in blockList:
grid = blockGrid(b, grid)
# Block using simplified dancing links (algorithm X) for fun
blockDLX(grid, a)
solveRow(grid, a)
solveColumn(grid, a)
def blockGrid(b, grid):
# Block row
x = b[0]
y = 0
for n in grid[x]:
grid[x][y] = 1
y += 1
# Block column
x = 0
y = b[1]
for row in grid:
grid[x][y] = 1
x += 1
# Block square
x = b[0]
y = b[1]
rowRange = [0,3,6]
columnRange = [0,3,6]
for a in rowRange:
if x >= a and x < a + 3:
for b in columnRange:
if y >= b and y < b + 3:
i = 0
while i < 3:
j = 0
while j < 3:
grid[a + i][b + j] = 1
j += 1
i += 1
return(grid)
def blockDLX(grid, a):
# Reduce rows
x = 0
subGrid = {}
for row in grid:
if row.count(0) != 0:
subGrid[x] = row
x += 1
# Reduce columns
for x in subGrid:
y = 0
solvedCount = 0
checkColumns = []
blockColumn = []
for n in subGrid[x]:
if n == 1:
check = 0
for row in subGrid:
if subGrid[row][y] == 1:
check += 1
if check != len(subGrid):
checkColumns.append(y)
else:
solvedCount += 1
else:
blockColumn.append(y)
y += 1
# Check columns
if len(checkColumns) > 0:
blockRow = []
for z in subGrid:
match = 'y'
for column in checkColumns:
if subGrid[z][column] == 0:
match = 'n'
if match == 'y':
blockRow.append(z)
if len(blockRow) == subGrid[x].count(0) and len(blockRow) != (len(subGrid[x]) - solvedCount):
for column in blockColumn:
x = 0
for row in grid:
if x not in blockRow:
grid[x][column] = 1
x += 1
def solveRow(grid, a):
x = 0
for row in grid:
if row.count(0) == 1:
y = 0
for n in grid[x]:
if n == 0:
#print('Match found x:{} y:{}'.format(x, y))
puzzle[x][y] = a
y += 1
x += 1
def solveColumn(grid, a):
y = 0
while y < 9:
column = []
for row in grid:
column.append(row[y])
if column.count(0) == 1:
x = 0
for n in column:
if n == 0:
#print('Match found x:{} y:{}'.format(x, y))
puzzle[x][y] = a
x += 1
y += 1
while any(0 in puzzle[row] for row in puzzle):
makeGrid(puzzle)
print('\n\nSolved:')
for x in puzzle:
print(puzzle[x])
# TODO: Replace examples and use TDD 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
What is the best way to list all divisors of a number?
A divisor of a number n
is another number d
where there is some number k
such that n = d k
In particular 1
and n
are always divisors.
module Divisors where
divisors :: Integer -> [Integer]
divisors n = 1:n:(divisorsAux 2)
where
divisorsAux k
| (fromIntegral k) > sqrt (fromIntegral n) = []
| otherwise = if n `mod` k == 0
then if n`div`k ==k
then k:(divisorsAux (k+1))
else k:(n`div`k):(divisorsAux (k+1))
else divisorsAux (k+1)
module ExampleSpec where
import Test.Hspec
import Divisors
import Data.List
-- `spec` of type `Spec` must exist
spec :: Spec
spec = do
describe "divisorList" $ do
it "divisors of 5*4*3 = 60" $ do
(sort(divisors (5*4*3))) `shouldBe` [1,2,3,4,5,6,10,12,15,20,30,60]
it "divisors of 4" $ do
(sort(divisors 4)) `shouldBe` [1,2,4]
it "divisors of 5*3 = 15" $ do
(sort(divisors (5*3))) `shouldBe` [1,3,5,15]
it "divisors of 101" $ do
(sort(divisors 101)) `shouldBe` [1,101]
I want to show you task from Russian EGE exam
Given an array containing positive integers that do not exceed 15000. Find the number of even elements in the array that are not multiples of 3, replace all odd elements that are multiples of 3 with this number, and output the modified array. For example, for a source array of five elements 20, 89, 27, 92, 48, the program must output numbers 20, 89, 2, 92, 48.
using System;
public class RussianExam
{
public static int[] ExamTask(int[] array)
{
int count = 0;
for(int i = 0; i < array.Length; i++)
{
if (array[i] % 3 != 0 && array[i] % 2 == 0) count++;
}
for (int i = 0; i < array.Length; i++)
{
if (array[i] % 3 == 0 && array[i] % 2 != 0) array[i] = count;
}
return array;
}
}
namespace Solution {
using NUnit.Framework;
using System;
// TODO: Replace examples and use TDD by writing your own tests
[TestFixture]
public class SolutionTest
{
[Test]
public void MyTest()
{
int[] expected = new int[] { 20, 89, 2, 92, 48 };
int[] input = new int[] { 20, 89, 27, 92, 48 };
Assert.AreEqual(expected, RussianExam.ExamTask(input));
}
}
}
You need return the screen size on request
Find resolution can here:
[image]:https://upload.wikimedia.org/wikipedia/commons/thumb/0/0c/Vector_Video_Standards8.svg/1280px-Vector_Video_Standards8.svg.png
public string PrimitiveFlow(string s)
{
//Code here :3
return "";
}
namespace Solution {
using NUnit.Framework;
using System;
// TODO: Replace examples and use TDD by writing your own tests
[TestFixture]
public class SolutionTest
{
[ScreenTest]
public void ScreenResolution()
{
Assert.AreEqual("640 x 480", PrimitiveFlow("VGA"));
Assert.AreEqual("1280 x 720", PrimitiveFlow("HD 720"));
Assert.AreEqual("1280 x 800", PrimitiveFlow("WXGA"));
Assert.AreEqual("1920 x 1080", PrimitiveFlow("HD 1080"));
Assert.AreEqual("3440 x 1440", PrimitiveFlow("UWQHD"));
Assert.AreEqual("2560 x 1440", PrimitiveFlow("WQHD"));
Assert.AreEqual("2560 x 1080", PrimitiveFlow("UWHD"));
}
}
}
def numberplatereader(plate):
import re
if re.match("[A-Z]{2}[0-9]{2}\s[A-Z]{3}", plate) != None:
return True
else:
return False
Test.assert_equals(numberplatereader("KU63 NZZ"), True)
Test.assert_equals(numberplatereader("AB12 CDE"),True)
Test.assert_equals(numberplatereader("KU63 NZZ"), True)
Test.assert_equals(numberplatereader("12"),False)
Test.assert_equals(numberplatereader(""), False)
Test.assert_equals(numberplatereader("AB12 C0E"),False)
Test.assert_equals(numberplatereader("BDS 1"), False)
Test.assert_equals(numberplatereader("CBS 0"),False)
Test.assert_equals(numberplatereader("KV35 ZHE"), True)
Test.assert_equals(numberplatereader("BB12 BB8"),False)
You like to play card games, But this game has simple rules, There are 40 cards within it, 4 for each number from 1 to 10.
You have a function that takes two arguments: The card the player has played, and the cards on the floor.
If the player's card was equal to any of the cards on the floor or the sum of any cards on the floor, All These cards should be taken from the floor
For example: The player threw a 7 card on the floor.
There were cards: [ 6, 1, 3, 4 ] on the floor.
Since both the combinations [6, 1] and [4, 3] are equal to 7, Then all of them should be returned by the function.
But, If there were : [ 2 ,4, 1, 3 ] cards .
You can only take the sequence [2, 4, 1] from the floor. Not 3.
because after removing the three initial cards no 4s will be left for a 3 card to add up to the sum of 7.
Notice that we've chosen: [ 2, 4, 1 ]. Because they have a higher number of cards than the sequence [4, 3].
You need to write an algorithm that returns what should be taken from the floor if there were cards or sequences of cards that're equal to the player's card. And your time is short so what'll you do?
function GameOfCards(handCard, floorCards)
{
// your code here
}
// TODO: Add your tests here
// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
// are still available for now.
//
// For new tests, using [Chai](https://chaijs.com/) is recommended.
// You can use it by requiring:
// const assert = require("chai").assert;
// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.
describe("Solution", function() {
it("should test for something", function() {
Test.assertEquals(GameOfCards(7, [3,4,1,2]), [4,1,2]);
Test.assertEquals(GameOfCards(7, [3,4,1]), [3,4]);
Test.assertEquals(GameOfCards(8, [1,9]), []);
Test.assertEquals(GameOfCards(9, [3,4,8,2,1]), [[3,4,2], [8,1]]);
Test.assertEquals(GameOfCards(3, [3,8,7,4,2,6]), [3]);
// assert.strictEqual(1 + 1, 2);
});
});
Control.Lens is mind-bogglingly powerful.
Just playing with this amazing thing.
module Kumite where
import Control.Lens
main = do
print $ (1, 2, 3) ^.. each
print $ map (^..each) [(1, 2, 3), (4, 5, 6), (7, 8, 9)]
print $ both ^~ 2 $ (1,2,3,4)
print $ mapped._2 %~ succ . (* 2) $ [(1,2),(3,4)]
print $ over (mapped._2) succ [(1,2),(3,4)]
print $ (10,20) ^. _2
print $ _1 .~ "i changed this" $ ((), "world")
Get all prime numbers less than or equal to the input n
.
Examples
get_primes(10) # Output: [2, 3, 5, 7]
get_primes(50) # Output: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
get_primes(100) # Output: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
get_primes(10000) # Output: [1229 elements]
Algorithm Description
This is the algorithm I used originally, but, feel free to fork this kumite and use your own algorthm!
1) Start with a list of all the numbers from 2 to n.
2) Mark all of the numbers divisible by 2.
3) Choose the smallest number untouched so far.
4) Mark all of the numbers divisible by the chosen number.
5) Repeat 3) and 4) until you've touched everything.
6) The chosen numbers are all the primes up to n.
def get_primes(n):
nums = list(range(2, n+1))
primes = []
while len(nums) > 0:
prime = nums[0]
del nums[0]
primes.append(prime)
for i in range(len(nums)-1, -1, -1):
if nums[i] % prime == 0:
del nums[i]
return primes
test.assert_equals(get_primes(10), [2, 3, 5, 7])
test.assert_equals(get_primes(50), [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47])
test.assert_equals(get_primes(100), [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97])
test.assert_equals(len(get_primes(10000)), 1229)
Find the distance of
x**2 - ((x-1)**2)
given parameter x, without calculating the exponents itself
Challenges -
-
Create a formula that works for negatives.
-
Create a formula that works for all powers.
def power_distance(x):
return x * 2 - 1
test.assert_equals(power_distance(2), 3)
test.assert_equals(power_distance(3), 5)
test.assert_equals(power_distance(4), 7)
test.assert_equals(power_distance(5), 9)
test.assert_equals(power_distance(6), 11)
test.assert_equals(power_distance(7), 13)
Given integers, and only integers, a
and b
, return their sum.
Input
Line 1: 5,5
Line 2: 6,7
Line 3: 9,9
Output
Line 1: 10
Line 2: 13
Line 3: 18
# Write here your code
import unittest
def add(x,y):
return x+y
class MyTest(unittest.TestCase):
def test0(self):
self.assertEqual(add(3,4), 7)
def test1(self):
self.assertEqual(add(5,5), 10)
def test2(self):
self.assertEqual(add(9,9), 18)
if __name__ == '__main__':
unittest.main()