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.

Code
Diff
  • def square(a):
        return(a**2)
  • 1
    def square(ty):
    
    2
        a = a * a
    
    3
        return b
    
    1+
    def square(a):
    
    2+
        return(a**2)
    

Shortened by 2 chars. No spaces.

Code
Diff
  • count_legs=lambda*x:sum(x)*4-x[2]*2
  • 1
    count_legs=lambda c,s,ch:(c+s)*4+ch*2
    
    1+
    count_legs=lambda*x:sum(x)*4-x[2]*2
    
Code
Diff
  • function lisaCipher(keyword, msg) {
        var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        var plainText = "";
        var remainderAlphabet = alphabet.split("");
        var plainAlphabet = alphabet.split("");
        var cypherAlphabet = [];
        var cypherChars = ((keyword.replace(/\s/g, '')).toUpperCase()).split("");
        var msgText = msg.toUpperCase().split("");
        for (i=0; i < cypherChars.length;i++) {
            if (cypherAlphabet.includes(cypherChars[i]) === false) {
              cypherAlphabet.push(cypherChars[i]);
            }
        }
        remainderAlphabet = remainderAlphabet.filter(char => cypherAlphabet.includes(char) === false);
        remainderAlphabet.forEach(char => cypherAlphabet.push(char));
        for (char of msgText) {
          if (plainAlphabet.includes(char) === false) {
            plainAlphabet.push(char);
            cypherAlphabet.push(char);
          }
          plainText = plainText + plainAlphabet[cypherAlphabet.findIndex(cipherChar => cipherChar === char)];
        }    
        return plainText;
        
    }
  • 11
    function lisaCipher(keyword, msg) {
    
    2+
        var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    
    3+
        var plainText = "";
    
    4+
        var remainderAlphabet = alphabet.split("");
    
    5+
        var plainAlphabet = alphabet.split("");
    
    6+
        var cypherAlphabet = [];
    
    7+
        var cypherChars = ((keyword.replace(/\s/g, '')).toUpperCase()).split("");
    
    8+
        var msgText = msg.toUpperCase().split("");
    
    9+
        for (i=0; i < cypherChars.length;i++) {
    
    10+
            if (cypherAlphabet.includes(cypherChars[i]) === false) {
    
    11+
              cypherAlphabet.push(cypherChars[i]);
    
    12+
            }
    
    13+
        }
    
    14+
        remainderAlphabet = remainderAlphabet.filter(char => cypherAlphabet.includes(char) === false);
    
    15+
        remainderAlphabet.forEach(char => cypherAlphabet.push(char));
    
    16+
        for (char of msgText) {
    
    17+
          if (plainAlphabet.includes(char) === false) {
    
    18+
            plainAlphabet.push(char);
    
    19+
            cypherAlphabet.push(char);
    
    20+
          }
    
    21+
          plainText = plainText + plainAlphabet[cypherAlphabet.findIndex(cipherChar => cipherChar === char)];
    
    22+
        }    
    
    23+
        return plainText;
    
    22
        
    
    33
    }
    
Code
Diff
  • // Description:
    // Write a function caesar() that will return the input message with each character 
    // shifted to the right n times in the alphabet. Make sure the encoded message is in 
    // all caps since the Romans didn't use lowercase letters. Only punks use lowercase letters.
    
    // Example : 'James is the greatest at kumite!' => 'MDPHV LV WKH JUHDWHVW DW NXPLWH!'
    
    // Make sure to preserve the spaces and punctuation of the original message, you know, for clarity's sake.
    
    
    const caesar = (shift, msg) => {
      return msg
        .toUpperCase()
        .split('')
        .map(chr => {
          let charcode = chr.charCodeAt();
          if(charcode > 64 && charcode < 91) charcode += shift;
          return String.fromCharCode(charcode);
        })
        .join('')
    };
  • 66
    // Example : 'James is the greatest at kumite!' => 'MDPHV LV WKH JUHDWHVW DW NXPLWH!'
    
    77
    88
    // Make sure to preserve the spaces and punctuation of the original message, you know, for clarity's sake.
    
    99
    1010
    1111
    const caesar = (shift, msg) => {
    
    12
      let encoded = "";
    
    13
      msg = msg.toUpperCase();
    
    14
      
    
    15
      for(let i = 0; i < msg.length; i++) {
    
    16
        let charcode = (msg[i].charCodeAt());
    
    17
        if(charcode > 64 && charcode < 91) {
    
    18
          charcode += shift;
    
    19
        } encoded += String.fromCharCode(charcode);
    
    20
      }
    
    21
      
    
    22
      return encoded;
    
    23
    12+
      return msg
    
    13+
        .toUpperCase()
    
    14+
        .split('')
    
    15+
        .map(chr => {
    
    16+
          let charcode = chr.charCodeAt();
    
    17+
          if(charcode > 64 && charcode < 91) charcode += shift;
    
    18+
          return String.fromCharCode(charcode);
    
    19+
        })
    
    20+
        .join('')
    
    2424
    };
    

Can anyone help with this? The code is supposed to take a string such as "it is nine 'oclock" and output the numerical position of each letter(letters only). my ouput seems to match both examples given exactly, but still says incorrect. any suggestions would be appreciated.

import string

def alphabet_position(text):
    aaa = ""
    
    for i in text:
        if i.isalpha() == True:
            i = i.lower()
            aaa = aaa + str(string.ascii_lowercase.index(i) + 1 )
            aaa = aaa + " "
        else:
            pass
    
    print(aaa)

Shortened to one line

Code
Diff
  • def find_triple(a, b):
        return sorted([a**2+b**2, a**2-b**2, 2*a*b])
  • 11
    def find_triple(a, b):
    
    2
        ans1 = a**2 + b**2
    
    3
        ans2 = a**2 - b**2
    
    4
        ans3 = 2 * a * b
    
    5
        triple = [ans1, ans2, ans3]
    
    6
        triple.sort()
    
    7
        return triple
    
    2+
        return sorted([a**2+b**2, a**2-b**2, 2*a*b])
    

Merge sort uses Divide and Conquer to split inputs and merge the halfs so they are sorted.

Given some numbers sort via merge sort:

    [1,3,2]
  [1] , [3, 2]
[1] , [3] , [2]
  [1,2], [3]
    [1,2,3]

Can someone help me with adding in the GinkGo Tests?

package main

import "fmt"

func merge_sort(slice []int) []int {
	length := len(slice)
	if length < 2 {
		return slice
	}
	mid := (length) / 2
	return merge(merge_sort(slice[:mid]), merge_sort(slice[mid:]))
}

func merge(left, right []int) []int {
	size, l, r := len(left)+len(right), 0, 0
	slice := make([]int, size, size)

	for i := 0; i < size; i++ {
		if l > len(left)-1 && r <= len(right)-1 {
			slice[i] = right[r]
			r++
		} else if r > len(right)-1 && l <= len(left)-1 {
			slice[i] = left[l]
			l++
		} else if left[l] < right[r] {
			slice[i] = left[l]
			l++
		} else {
			slice[i] = right[r]
			r++
		}
	}
	return slice
}

func main() {
	arr := []int{3, 4, 1, 2, 5}
	fmt.Print(merge_sort(arr))
}