Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

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.

Ad
Ad
Mathematics
Algorithms
Logic
Numbers
Fundamentals
Data Types

-9 chars

Code
Diff
  • 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)

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]]

Code
Diff
  • 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 powerset
    • if L not in pset:
    • pset.append(L)
    • P=[]
    • for i in subset(L): #Calling subset(L) for adding subsets to pset
    • if i not in pset:
    • pset.append(i)
    • #building a List that has same elements as of pset but in right order
    • for z in range(len(L)+1):
    • for y in pset[::-1]: #iterating over pset in reverse order
    • if len(y)==z: #adding elements in ascending order of their lengths
    • P.append(y)
    • return P
    • def subset(L):
    • """
    • Takes a list L and returns a list of all possible subsets of L
    • """
    • List=L[:] #Copy of L
    • S=[] #List of subsets of L
    • i=0
    • while i<len(L):
    • #in each iteration removing ith element of List to get a subset
    • List.remove(List[i])
    • if List not in S: #avoiding copies
    • S.append(List[:])
    • #getting further subsets of mutated List
    • #but only if len(List)>2
    • if len(L)>2:
    • X=subset(List) #Recursive call
    • for x in X: #Extracting elements of returned S
    • if x not in S: #as S is a list of lists
    • S.append(x)
    • List=L[:] #Restoring List after several mutations
    • #so that next time mutated list is not
    • #encountered in line 16
    • i+=1
    • return 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)]
Code
Diff
  • int returnhundred()
    {
      return 100;
    }
    • int returnhundred()
    • {
    • return 'd';
    • }
    • return 100;
    • }
Code
Diff
  • square=lambda a:a*a
    • def square(a):
    • return(a*a)
    • square=lambda a:a*a

Shortened by 2 chars. No spaces.

Code
Diff
  • count_legs=lambda*x:sum(x)*4-x[2]*2
    • count_legs=lambda c,s,ch:(c+s)*4+ch*2
    • count_legs=lambda*x:sum(x)*4-x[2]*2