Begin a new Kumite
Search
About
  • 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.

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);
}
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[0]=location[0]+(direction[0]*80)-(direction[2]*80)
        location[1]=location[1]+(direction[1]*274)-(direction[3]*274)
        #a squared + b squared = c squared
        if( (location[0]**2+location[1]**2)**(1/2) > 2000 ):
            return True
    return False
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}!");
        
      }
      
      
    }
  • 11
    using System;
    
    22
    33
    class Kata
    
    44
    {
    
    55
      private static string LANGUAGE = "C#";
    
    66
      
    
    77
      public static void Main()
    
    88
      {
    
    99
        string[] hello = {"H","e","l","l","o"};
    
    10
        string result = "";
    
    10+
        var result = String.Join("", hello);
    
    1111
        
    
    12
        foreach(string s in hello){
    
    13
          result = result + s;
    
    14
        }
    
    1515
        
    
    16
        Console.WriteLine(result + ", " + LANGUAGE + "!" );
    
    13+
        Console.WriteLine($"{result}, {LANGUAGE}!");
    
    1717
        
    
    1818
      }
    
    1919
      
    
    2020
      
    
    2121
    }
    

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

Task
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;
    }
  • 11
    function generateInterval(start, stop, step) {
    
    22
      const arr = [];
    
    33
      let value = start;
    
    44
      for (let index = 0; index <= (stop - start) / step; index++) {
    
    55
          arr.push(value);
    
    66
          value += step;
    
    77
      }
    
    88
      return arr;
    
    99
    }
    

Recent Moves:

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 (Num.add_num nlp one) n
  ) (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;;
Fundamentals

Task

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)
    
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: