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.
-9 chars
compute=lambda n:sum(i for i in range(n)if i%3*i%5<1)
compute=lambda n:sum([i for i in range(n)if i%3==0 or i%5==0])- compute=lambda n:sum(i for i in range(n)if i%3*i%5<1)
Test.describe("Basic tests") Test.assert_equals(compute(1000), 233168) Test.assert_equals(compute(48237), 542917083) Test.assert_equals(compute(1928), 866894) Test.assert_equals(compute(758), 133889)
- Test.describe("Basic tests")
- Test.assert_equals(compute(1000), 233168)
- Test.assert_equals(compute(48237), 542917083)
- Test.assert_equals(compute(1928), 866894)
Test.assert_equals(compute(758), 133889)# 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- Test.assert_equals(compute(758), 133889)
Given an array of 'n' elements
You have to return an array of arrays that contain all possible combinations of the elements of the provided array
e.g. if given array is
L=[1,2]
you have to return an array containing [],[1],[2],[1,2]
i.e. [[],[1],[2],[1,2]]
check that the array you return is having elements in the ascending fashion of their lengths
i.e. if L=[1,2,3]
your program should return [[],[1],[2].[3],[1,2],[1,3],[2,3],[1,2,3]]
from itertools import combinations powerset = lambda arr: [list(c) for i in range(len(arr) + 1) for c in combinations(arr, i)]
def powerset(L):pset=[[]] #empty list and original list are always part#of powersetif L not in pset:pset.append(L)P=[]for i in subset(L): #Calling subset(L) for adding subsets to psetif i not in pset:pset.append(i)#building a List that has same elements as of pset but in right orderfor z in range(len(L)+1):for y in pset[::-1]: #iterating over pset in reverse orderif len(y)==z: #adding elements in ascending order of their lengthsP.append(y)return Pdef subset(L):"""Takes a list L and returns a list of all possible subsets of L"""List=L[:] #Copy of LS=[] #List of subsets of Li=0while i<len(L):#in each iteration removing ith element of List to get a subsetList.remove(List[i])if List not in S: #avoiding copiesS.append(List[:])#getting further subsets of mutated List#but only if len(List)>2if len(L)>2:X=subset(List) #Recursive callfor x in X: #Extracting elements of returned Sif x not in S: #as S is a list of listsS.append(x)List=L[:] #Restoring List after several mutations#so that next time mutated list is not#encountered in line 16i+=1return S #list of subsets- from itertools import combinations
- powerset = lambda arr: [list(c) for i in range(len(arr) + 1) for c in combinations(arr, i)]
Shortened by 2 chars. No spaces.