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.

Failed Tests

### Finding the real number cube root of a number.

There is a unique real cube root of every real number.

For example, 5 is a real cube root of 125 because we can write 125 as the product of 3 positive 5's.

In Python, however, when it comes to finding a real cube root of a negative number n, simply raising n to the power of 1/3 results in a complex number.

For example, either pow(-125, (1/3)) or (-125) ** (1/3) evaluates to (2.5+4.330127018922192j) instead of -5.

In this kata, you are going to come up with a function that correctly calculates a real cube root of an input number, which can be zero, a positive real number or a negative one.

``````def real_cube_root(n):
if n >= 0: return n ** (1/3)
else: return -abs(n ** (1/3))``````

### Add a given separator to a string at every n characters

Add a given separator to a string at every n characters. When n is negative or equal to zero then return the orginal string.

``````func insert(seperator: String, afterEveryXChars: Int, intoString: String) -> String {
guard afterEveryXChars > 0 else { return intoString }
var output = ""
intoString.enumerated().forEach { index, c in
if index % afterEveryXChars == 0 && index > 0 {
output += seperator
}
output.append(c)
}
return output
}``````

### Caesar cipher (work out from word) -help needed!

Encryption
Algorithms
Cryptography
Logic
Security
Strings
Data Types

You've been tasked with decrypting an enemy message intercepted by your team. You do not know the offset, but you do know a part of the original string, the variable word, that was there before the message was encrypted. Using that word and the encrypted string, decrypt the string, and then the original number used to offset it. There may be multiple possible combinations, so you will print all of them, and their offsets (no duplicates!)

Details :
The message will have UPPERCASE and lowercase letters, numbers and punctuation. You will convert all uppercase to lowercase, but keep all punctuation exactly where it was.

If a letter is offsetted to the edge of the alphabet, loop it around to the other side (for example, 'y' offsetted by +2 is 'a')

When printing the offset, you must give the most optimal offset (for example, and offset of 25 is -1, an offset of -28 is +2)

All non-letters (e.g '1', '?', 'space') will not be changed, and will remain in the original position.

The word will consist of only letters (though maybe uppercase) of length exceeding 1

If the message can not contain the word (for example, abc can never be cba), print 'impossible'

The answer should be in a list, with each answer then followed by their offset. The order is, from left to right, when the word can appear first.
Example: The string is 'abcefgh', the word is 'zab'. The first time zab can appear is ['zabdefg', 1], the second time it can appear is ['vwxzabc', -5,] and the third and last time it can appear is ['uvwyzab', -6], so your porgram should print ['zabdefg', -1, 'vwxzabc', -5, 'uvwyzab', -6].

You can import the alphabet under the variable name 'lc' by using (from string import ascii_lowercase as lc)

My solution doesn't work all the time, can anyone help me on why?

``````def decrypt(string, word) :
tempword = word.lower()
tempstring = string.lower()
from string import ascii_lowercase as lc
letters = {letter: str(index) for index, letter in enumerate(lc, start=1)}
def change(text) :
temp = []
for dex in range(len(text)) :
chan = text[dex]
try:
while chan > 13 or chan < -13 :
if chan < -13 :
chan = chan + 26
elif chan > 13 :
chan = chan - 26
temp.append(str(chan))
except:
temp.append(str(chan))
return '.'.join(temp)
def convert(text):
text = text.lower()
numbers = ['0', '0']
change = []
for character in text + text[-1] :
if character in letters :
numbers.append(letters[character])
if numbers[-2].isdigit() :
change.append(int(numbers[-1])-int(numbers[-2]))
else :
change.append(str(character))
return change[1:-1]
string = change(convert(string))
word = change(convert(word))
if string.count(word) == 0 :
return 'impossible'
tempo = []
indexs = [i for i in range(len(string)) if string.startswith(word, i)]
for dex in range(sum(word == string[i:i+len(word)] for i in range(len(string)-(len(word)-1)))) :
nim = indexs[dex]+len(word)-1
location = string[:nim+1].count('.')
try :
if tempo.count(str(int(letters[tempstring[location]])-int(letters[tempword[0]]))) == 0 :
tempo.append(str(int(letters[tempstring[location]])-int(letters[tempword[0]])))
except :
True == True
tempo = change(tempo).split('.')
for dex in range(len(tempo)) :
offset = int(tempo[dex])
offset %= len(lc)
if (tempstring.translate(str.maketrans(lc, lc[-offset:] + lc[:-offset]))).count(tempword) != 0 :

### Round the number n to m decimal places using round half up algorithm

Round a given float number n according to the "Round half up" algorithm with a given number of decimal places m.

``````from decimal import Decimal, ROUND_HALF_UP

def roundHalfUp( n, m ):
return float( Decimal( str( n ) ).quantize( Decimal( "1." + "0" * m ), rounding = ROUND_HALF_UP ) )``````

### Kutman-a's Kumite #2

``````public class Kata {

public static String solution(String str) {
StringBuilder res = new StringBuilder(str.length());

for (int i = (str.length() - 1); i >= 0; i--){
res.append(str.charAt(i));
}

return res.toString();
}

}``````

### Kutman-a's Kumite #3

``````import java.util.stream.*;
public class Kata {
public static int findShort(String s) {
return Stream.of(s.split(" "))
.mapToInt(String::length)
.min()
.getAsInt();
}
}``````

### Kuba.As's Kumite #2

``````public class Kata
{
public static int opposite(int number)
{
return -number;
}
}``````
Failed Tests

### almahfuz's Kumite #2

``````describe("Solution", function() {
it("should test for something", function() {

});
});``````

### Prolog template

``add(A, B, R) :- R is A + B.``

### Kutman-a's Kumite #4

``import java.util.stream.*; public class Kata { public static int findShort(String s) { return Stream.of(s.split(" ")) .mapToInt(String::length) .min() .getAsInt(); } }``