Search
• ###### Filter by Language:
• 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.

### Sum of 2 squares

Given a and b, n is the sum of the squares of a and b. e.g. (a,b)=(1,2)-->n=5

Break 2n into a sum of two squares and output!
e.g.2n=10-->(a,b)=(1,3)
(yes it is always possible :)

Think before you code!Good luck!

``````using namespace std;
pair<int, int> two_squares(int a,int b){
return make_pair(b-a,a+b);
}``````

### Lost in New York

Fundamentals
Algorithms

Kevin McCallister now grown and living in New York, is serving time on probation. He has an ankle monitor and can't be more than 2025m from his house. (That is a direct line from his house) He wanders around New York city blocks which are 80 meters North to South and 274 meters East to West. We need to know if Kevin is going to jail for violation of probation.
you will recieve a list of number of blocks travel in each direction and have to figure out if on his journey he ever ended up violating his 2000m distance(He can Travel 2000m but not anything more). Kevin checks his distance from home every few blocks. (assume he walked the blocks for check-in in the safest way to avoid going over 2000m)
each member of the list will be another list formatted as below were the number is the number of blocks traveled in that direction:

(#North,#East,#South,#West)
You will have at least 2 check in so list length >= 2
List will always be integers.

Your Result with return True is he ends up going to jail or False if he is safe to foil robbers another day.

``````def goesToJail(directions):
location=[0,0]
#North+East are postive numbers West+South are a negative numbers
for direction in directions:
location=location+(direction*80)-(direction*80)
location=location+(direction*274)-(direction*274)
#a squared + b squared = c squared
if( (location**2+location**2)**(1/2) > 2000 ):
return True
return False``````

### Hello C#!

Code
Diff
• ``````using System;

class Kata
{
private static string LANGUAGE = "C#";

public static void Main()
{
string[] hello = {"H","e","l","l","o"};
var result = String.Join("", hello);

Console.WriteLine(\$"{result}, {LANGUAGE}!");

}

}``````
•  1 1 ```using System; ``` 2 2 3 3 ```class Kata ``` 4 4 ```{ ``` 5 5 ``` private static string LANGUAGE = "C#"; ``` 6 6 ``` ``` 7 7 ``` public static void Main() ``` 8 8 ``` { ``` 9 9 ``` string[] hello = {"H","e","l","l","o"}; ``` 10 − ``` string result = ""; ``` 10 + ``` var result = String.Join("", hello); ``` 11 11 ``` ``` 12 − ``` foreach(string s in hello){ ``` 13 − ``` result = result + s; ``` 14 − ``` } ``` 15 15 ``` ``` 16 − ``` Console.WriteLine(result + ", " + LANGUAGE + "!" ); ``` 13 + ``` Console.WriteLine(\$"{result}, {LANGUAGE}!"); ``` 17 17 ``` ``` 18 18 ``` } ``` 19 19 ``` ``` 20 20 ``` ``` 21 21 ```} ```

### Generate integer interval

Implement a function named generateRange(start, stop, step), which takes three arguments and generates a range of integers from start to stop, with the step. The first integer is value of the start, the second is the end of the range and the third is the step. (start may be less then stop (then step < 0)

Note: step != 0

Create a function named

``````generateInterval(2, 10, 2) // [2,4,6,8,10]
generateInterval(2, -10, -2) // [2,0,-2,-4,-6,-8,-10]
``````
Code
Diff
• ``````function generateInterval(start, stop, step) {
const arr = [];
let value = start;
for (let index = 0; index <= (stop - start) / step; index++) {
arr.push(value);
value += step;
}
return arr;
}``````
•  1 1 ```function generateInterval(start, stop, step) { ``` 2 2 ``` const arr = []; ``` 3 3 ``` let value = start; ``` 4 4 ``` for (let index = 0; index <= (stop - start) / step; index++) { ``` 5 5 ``` arr.push(value); ``` 6 6 ``` value += step; ``` 7 7 ``` } ``` 8 8 ``` return arr; ``` 9 9 ```} ```

Recent Moves:

### comb

Mathematics
Algorithms
Numbers

Combinations using big ints

``````#load "nums.cma";; open Num;;

let rec prod a b=
let cmp=Num.compare_num a b in
if cmp>0 then Num.num_of_int 0 else if cmp==0 then b else
let b1=Num.sub_num b (Num.num_of_int 1) in
Num.mult_num b (prod a b1);;

let num_comb n p=
let nlp=Num.sub_num n p in
let (p,nlp)=if (Num.compare_num p nlp)>0 then (nlp,p)else(p,nlp) in
let one=(Num.num_of_int 1) in
Num.div_num (
) (prod one p);;

let comb (n:int) (p:int) :string=Num.string_of_num (num_comb (Num.num_of_int n) (Num.num_of_int p));;

comb 76 12 |> print_endline;;``````

### Next smaller even

Fundamentals

Given integer `n`, return the next smaller even number.

### Examples

``````Input = 1
Output = 0

Input = 6
Output = 6

Input = 9
Output = 8
``````
Code
Diff
• ``e=lambda n:n-(n&1)``
•  1 − ```e=lambda n:n if n%2 == 0 else n-1 ``` 1 + ```e=lambda n:n-(n&1) ```

### Return Odd No Matter What

Code
Diff
• ``````o=lambda n:n-(n+1)%2
``````
•  1 − ```o=lambda n:(n-1,n)[n%2] ``` 1 + ```o=lambda n:n-(n+1)%2 ```

Recent Moves: