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

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

Showing how sync events work in c#, not so pratical as in c# 6 and forward is a good practice writing async code.

using System;

namespace delegates
{
	class Program
	{
		static void Main()
		{
		    // Creates a new instance
			Message hi = new Message();
			
			/*
			set the event of the class instance to a 
			lambda expression, beeing an event handler that has the same parameter
			and return type of the delegate in the class instance.
			
			equivalent of creating a new void method with the same
			parameters and seting it to the event in the class instance
			
			*/
			hi.writed += (string hello) =>
			{
			    Console.WriteLine(hello);
			};
			
			// executes the method to validate the event and add it to the delegate
			hi.write = "write property";
		}
	}
	
	public class Message
	{
	    
	    //creates the delegate that will handle the method/ lambda expression/ anonnymous method passed through it
	    public delegate void handler(string hello);
	    
	    //creates the event with the delegate
	    public event handler writed;
	    
	    //method that will check for the event while executing
	    
	    private string _write;
	    public string write
	    {
	        get
	        {
	            return _write;
	        }
	        set
	        {
	            if(value == "write property")
	            {
	               writed?.Invoke("the event was thrown!!!");
	            }
	            
	            Console.WriteLine(value);
	            
	            _write = value;
	        }
	    }
	    
	   //The same as:
	   
	   // public void write(string text)
	   // {
	   //     //you have to check if the event is not null becouse you can't execute a delegates method if it does not exist
	   //     //(the event handler was not set yet)
	   //     if(text == "write method" && writed != null)
	   //     {
	   //         writed("the event was thrown!!!");
	   //     }
	   //     Console.WriteLine(text);
	       
    }
}
list = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
for i in list :
    if i % 15 == 0 :
        print('Fizz Buzz')
    elif i % 3 == 0 :
        print('Fizz')
    elif i % 5 ==0 :
        print('Buzz')
    else :
        print(i)

Test

function main()
{
  return 12
}