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

Given a collection of JSON with a structure of id, name and description. Sort them by name.

e.g:
[ { "id": 100, "name": "John", "description":"A real gentleman" }, { "id": 101, "name": "Gary", "description":"A clever person" }, { "id": 102, "name": "Anna", "description":"A charming lass" }, { "id": 103, "name": "Zoltan", "description":"A financial wizard" } ]

should be:

[ { "id": 102, "name": "Anna", "description":"A charming lass" }, { "id": 101, "name": "Gary", "description":"A clever person" }, { "id": 100, "name": "John", "description":"A real gentleman" }, { "id": 103, "name": "Zoltan", "description":"A financial wizard" } ]

function  sortByName(collection) { 
    return collection.sort((a, b) => {
        let alpha = a.name.toLowerCase();
        let beta = b.name.toLowerCase();
        return (alpha < beta) ? -1 : (alpha > beta) ? 1 : 0;
    });
}
Mathematics
Algorithms
Logic
Numbers
Data Types

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
Algorithms
Logic

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

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);
}

Implement a function, which gets string, splits it onto numbers and words. After it wraps numbers in div tag, words in span and remove spaces at the end and begining.

Example:

  1. transformText("Two 2"):<span>Two</span><div>2</div>
  2. transformText('12 people in 2 rooms'): <div>12</div><span>people in</span><div>2</div><span>rooms</span>
function transformText(string) {
  const regExp = /[\D]+|([\d+\.]+)/g
  const numsRegExp = /[0-9\.]+/g
  
  const splited = string.match(regExp)
  
  const res = splited.map((item) => {
    if (numsRegExp.test(item)) {
      return `<div>${item}</div>`
    } else {
      return `<span>${item.replace(/^\s|\s$/g, "")}</span>`
    }
  })
  
  return res.join("")
}
Numbers
Data Types
Algorithms
Logic

Summary

In this kata you have to make a function named converter.

What Does the converter Function do?

It converts a negitive number to a positive one and a positive number to a negetive one.

  1. Check the parameter
  • If it is not integer just return False
  1. Check the word if it is negitive or positive

  2. Convert the number

  • if negitive convert to positive
  • if positive convert to negitive

Now just return the final answer... Done!

Examples

  • # Negitive to Positive
    convert(-1) === 1
    convert(-72) === 72
    
    # Positive to Negitive
    convert(24) === -24
    convert(32) === -32
    
    # Invalid Sequences
    convert("23") === False
    convert("-94") === False
    convert(True) === False
    convert([123, 321]) == False
    convert({123, 1232, 34}) === False
    
def convert(number):
        if isinstance(number, int):
            # Check if number is negitive
            if number < 0:
                # negitive -> positive
                return (abs(number))

            else:
                # positive -> negitive
                return (number * -1)
        
        else:
            return False

I have undertaken a study of recursion. I find myself reaching for it fairly consistenly to solve different Kata but often find my understanding of certain concepts laking enough that I end up going with an iterative approach instead.

the goal of this was to produce in exponent notation the prime factors of a number.

The problem with this one is that because I created a new dictionary at the top of primeFactoring and because there is not an array or dictionary passed into it I ended up creating another function (factorPart) to fill the dictionary.
even ignoring all the messy formating code the solution seems convoluted.

What would be a better approach and what concepts should be understood to improve this answer?

def primeFactoring(n):
    dict = {}
    print(n)
    factorPart(n,dict)
    output = ""
    for d, v in dict.items():
        if v > 1:
            output += str(d)+"^"+str(v)+" X "
        else: output += str(d)+" X "
    output = output.strip(" X ")
    print(dict) #key being the factor and value being the number of occurrences
    print(output) #formated in exponant form
    return output
    
def factorPart(num, dict):
    x = 2
    while x <= num:
        if num / x == num // x:
            dict[x] = dict[x] + 1 if x in dict else 1
            return factorPart(num // x, dict)
        x+=1

Write a function that takes an integer array, and without sorting the array returns its largest and smallest number as a two element array.

INPUT:                             OUTPUT:
{-1,-2,-3,-4,-5,-6,-7,-8,-9,-1} -> {-9,-1}
public class HighLow{
  public static int[] printLargestAndSmallest(int[] nums){
		int low[] = nums;
		int high[] = nums;
		int lowest = nums[0];
		int highest = nums[0];
		int count = 0;
		
		for(int i = 0; i < nums.length;i+=2){
			int num1 = nums[i];
			int num2 = nums[i+1];
			
			if(num1<num2){
				low[count] = num1;
				high[count] = num2;
				count++;
			}else{
				low[count] = num2;
				high[count] = num1;
				count++;
			}
			
			lowest = low[0];
			highest = high[0];
			
			for(int j = 1; j < low.length; j++){
				if(low[j] < lowest){
					lowest = low[j];			
				}
			}
			
			for(int j = 1; j < high.length; j++){
				if(high[j] > highest){
					highest = high[j];
				}
			}

		}
    int[] finalHighLow = new int[2];
    finalHighLow[0] = lowest;
    finalHighLow[1] = highest;
    return finalHighLow;
	}
}
Fundamentals
Numbers
Data Types
Integers

Make a function that determines if a number is odd.

public static class Kata
{
    public static bool IsOdd(int input)
    {
        return ((input % 10 == 1) || (input % 10 == 3) || (input % 10 == 5) || (input % 10 == 7) || (input % 10 == 9));
    }
}

Given a list of strings, return an object that represents the tree structure.

getTree([
'src/main.js',
'src/second.js',
'src/components/header.js',
'src/components/helpers/sidebar.js'
]) -> {
  "src": {
      "main.js": "file",
      "second.js": "file",
      "components": {
          "header.js": "file",
          "helpers": {
            "sidebar.js": "file",
          },
      }    
  }
}
function getTree(strings) {
  // code
}