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

A mistake they don't want to fix...

function describePhp() {
  return 2 * 2 == 4 ? 'php is good' : 2 * 2 == 5 ? 'php is weird' : 'php has features';
}

Don't know how this "kumite" stuff works yet, so i may be doing sth wrong.
This is about finding better/more efficient ways to permutate a list starting with my sorry attempt. The result requires types of the typeclass Ord, to get a common result for the test cases. Havent thought about a way to solve that differently yet.

module Permutation where

import Data.List (sort)

permu :: [a] ->[[a]]
permu []  = [[]]
permu [x] = [[x]]
permu x = fuzz (length x) 0 x
        where fuzz l n (x:xs) |n == l = []
                              |otherwise = map ((:) x) (permu xs) ++ fuzz l (n+1) (xs ++ [x])
                            
permutation :: Ord a => [a] -> [[a]]                           
permutation x = permu x

Lets go back to grade school!

Solve for the hypotenuse of a triangle.

Round a float to 4 decimal places.

def hypotenuse(a,b):

    import math
    h = round(math.sqrt(a**2 + b**2),4)
    #print(h)
    return h

In this Kata you will need to write a function that returns whether a password is strong or not.

Your code should return a Boolean of true if the provided password meets the following conditions

  1. password must be no less than 8 characters long
  2. password must have at least 1 capital letter
  3. password must have at least 1 number
  4. password must have at least 1 special character

for this Kata special characters are considered ( ! " # $ % & ' ( ) * + ' - . / ; : < > = or ?)

if the password doesn't meet these requirements return false.

function testPassword(password){
  var cap = false;
  var spec = false;
  var number = false;
  var temp;
  
  for(i=0;i<password.length;i++){
  temp = password[i].charCodeAt();
    if(temp > 32 && temp < 48){
      spec = true;
    } else if(temp > 57 && temp < 64){
      spec = true;
    }
  }
//check each digit and see if any are capital letters
for(i=0;i<password.length;i++){
  if(password.charCodeAt(i) > 64 && password.charCodeAt(i) < 91){
    cap = true;
  }
}

//see if the password is over 8 digits long
if(password.length > 7){
  number = true;
}
  
  //provide final answer
  if(cap && number && spec){
    return true;
  } else {
    return false;
  }

}

yawn I need a cup of coffee...

class GroundCoffee { }
class Coffee { }

class Cupboard { 
  constructor() {
    this.contents = {
      "GroundCoffee": new GroundCoffee(),
    };
  }
}

class CoffeeMaker {
  makeCoffee(groundCoffee) {
    if(!(groundCoffee instanceof GroundCoffee)) {
      throw new Error("Only GroundCoffee can be used to make Coffee");
    }
    
    return new Coffee();
  }
}

// -----

const cupboard = new Cupboard();
const coffeeMaker = new CoffeeMaker();

function makeCoffee() {  
  let groundCoffee = cupboard.contents["GroundCoffee"];
  return coffeeMaker.makeCoffee(groundCoffee);
}
Algorithms
Logic

a function that takes a list of connections on the following format:
connections[n] is the list of connections from node n.

connections={
	[1] ={ 1, 2, 6, 7 },
	[2] ={ 1, 2, 4, 5, 6 },
	[3] ={ 3, 4, 5, 6, 7 },
	[4] ={ 2, 3, 4, 5, 6 },
	[5] ={ 2, 3, 4, 5, 7 },
	[6] ={ 1, 2, 3, 4, 6 },
	[7] ={ 1, 3, 5, 7 },
	[8] ={ 8, 9, 11, 12, 13, 15 },
	[9] ={ 8, 9, 10, 12, 13, 15, 16 },
	[10]={ 9, 10, 11, 12, 16 },
	[11]={ 8, 10, 11, 12 },
	[12]={ 8, 9, 10, 11, 12, 13, 15 },
	[13]={ 8, 9, 12, 13, 14, 15 },
	[14]={ 13, 14, 15, 16 },
	[15]={ 8, 9, 12, 13, 14, 15, 16 },
	[16]={ 9, 10, 14, 15, 16 },
	[17]={ 17, 18, 19, 20, 21 },
	[18]={ 17, 18, 19, 20 },
	[19]={ 17, 18, 19, 21 },
	[20]={ 17, 18, 20, 21 },
	[21]={ 17, 19, 20, 21 },
}

The output should be a table of tables with nodes in a given net.

nets={
	{1,2,6,7,4,5,3},
	{8,9,11,12,13,15,10,16,14},
	{17,18,19,20,21}
}

This solution assumes symmetrical connections between nodes.

solution={}

local isIn=function(list,item)
  --simple function to find a vale in list
	if type(list)~="table" or item==nil then
		return false
	end
	local FoundAtIndex=""
	local found=false
	for index,value in pairs(list) do
		if value==item then
			found=true
			FoundAtIndex=index
			break
		end
	end
	return found,FoundAtIndex
end

solution.findConnectedNets=function(connections)
	local nets={}
	for i=1,#connections do --traverses nodes to build the nets
		local new=true
		for k=1,#nets do --if it already is in a net, skip it
			if isIn(nets[k],i) then
				new=false
				break
			end
		end
		if new then
			local net={}
			local queue={i}
			while #queue>0 do
				local vertex=queue[1]
				table.insert(net,vertex)
				table.remove(queue,1)
				for _,node in pairs(connections[vertex]) do
					if not isIn(net,node) and not isIn(queue,node) then
						table.insert(queue,node)
					end
				end
			end
			table.insert(nets,net)
		end
	end
	return nets
end


return solution

Create a function that will return the average grade of a an array of students grades.

def average (grades)
grade.sum/grade.length
end

Multiple the two attributes

def multiple(a,b):
    return a*b

Add two values.

def add(a,b):
    return a+b

add

def add(a,b):
    return 1