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.

### fibonnaci

Code
Diff
• ``````def output(thing=[1,1]):
for _ in range(100): thing.append(thing[-1]+thing[-2])
return thing``````
• def output():
• return [1, 1, 2, 3, 5, 8]
• def output(thing=[1,1]):
• for _ in range(100): thing.append(thing[-1]+thing[-2])
• return thing

### Sum Of Positive

Fundamentals
Arrays
Code
Diff
• ``````function Sum-OfPositive(\$NumberArray)
{
[Func[int,bool]]\$Delegate = {param(\$v); return \$v -ge 0}
[Linq.Enumerable]::Sum([Linq.Enumerable]::Where([int[]]\$NumberArray,\$Delegate))
}
``````
• function Sum-OfPositive(\$NumberArray)
• {
• (\$NumberArray | ?{\$_ -gt 0} | Measure -sum).Sum
• [Func[int,bool]]\$Delegate = {param(\$v); return \$v -ge 0}
• [Linq.Enumerable]::Sum([Linq.Enumerable]::Where([int[]]\$NumberArray,\$Delegate))
• }

### Find maximum number that can be formed using digits of a given number

Added a small benchmark, the output can be shown with "cargo test -- --nocapture" locally.

Code
Diff
• ``````pub fn sort_desc(mut n: u64) -> u64 {
let mut digit_counts = [0; 10];
while n > 0 {
let digit = (n % 10) as usize;
digit_counts[digit] += 1;
n /= 10;
}
let mut result = 0;
let mut fac = 1;
for digit in 0..10 {
for _ in 0..digit_counts[digit] {
result += (digit as u64) * fac;
fac *= 10;
}
}
result
}
use std::iter::repeat;

pub fn sort_desc_it(mut n: u64) -> u64 {
let mut digit_counts = [0; 10];
while n > 0 {
digit_counts[n as usize % 10] += 1;
n /= 10;
}
digit_counts
.into_iter()
.enumerate()
.rev()
.flat_map(|(digit, count)| repeat(digit as u64).take(count))
.fold(0, |result, digit| result * 10 + digit)
}
use std::time::Instant;

fn benchmark<F>(func: F, input: u64, iterations: u32) -> (u64, f64)
where
F: Fn(u64) -> u64,
{
let mut total_duration = 0.0;
let mut result = 0;
for _ in 0..iterations {
let start = Instant::now();
result = func(input);
let duration = start.elapsed();
total_duration += duration.as_secs_f64();
}
let avg_duration = total_duration / iterations as f64;
(result, avg_duration)
}
``````
• pub fn sort_desc(mut n: u64) -> u64 {
• let mut digit_counts = [0; 10];
• while n > 0 {
• let digit = (n % 10) as usize;
• digit_counts[digit] += 1;
• n /= 10;
• }
• let mut result = 0;
• let mut fac = 1;
• for digit in 0..10 {
• for _ in 0..digit_counts[digit] {
• result += (digit as u64) * fac;
• fac *= 10;
• }
• }
• result
• }
• use std::iter::repeat;
• pub fn sort_desc(mut n: u64) -> u64 {
• pub fn sort_desc_it(mut n: u64) -> u64 {
• let mut digit_counts = [0; 10];
• while n > 0 {
• digit_counts[n as usize % 10] += 1;
• n /= 10;
• }
• digit_counts
• .into_iter()
• .enumerate()
• .rev()
• .flat_map(|(digit, count)| repeat(digit as u64).take(count))
• .fold(0, |result, digit| result * 10 + digit)
• }
• }
• use std::time::Instant;
• fn benchmark<F>(func: F, input: u64, iterations: u32) -> (u64, f64)
• where
• F: Fn(u64) -> u64,
• {
• let mut total_duration = 0.0;
• let mut result = 0;
• for _ in 0..iterations {
• let start = Instant::now();
• result = func(input);
• let duration = start.elapsed();
• total_duration += duration.as_secs_f64();
• }
• let avg_duration = total_duration / iterations as f64;
• (result, avg_duration)
• }

### Deleting vowels in a text

Code
Diff
• ``````fn disemvowel(string: &str) -> String {
string.replace(['A','E','I','O','U','a','e','i','o','u'], "")
}``````
• fn disemvowel(string: &str) -> String {
• string.chars().filter(|&c| !"AEIOUaeiou".contains(c)).collect()
• string.replace(['A','E','I','O','U','a','e','i','o','u'], "")
• }

### String Remover

Algorithms
Strings

Fixed the end of the string problem. Now, the char array has a double null terminator character to denote that it has reached the end of the array.

Code
Diff
• ``````#include <stdlib.h>
#include <string.h>

/*
Heap allocate the string and return it.
*/

char* remove_string(const char *input, const int n)
{
if (n <= 0 || input == NULL) return NULL;
for (int c = 1; !(*input == '\0' && *(input + 1) == '\0') && (c < n); (*input == '\0') ? c++ : c, input++);
return (*input == '\0') ? NULL : strdup(input);
}``````
• #include <stdlib.h>
• #include <string.h>
• /*
• Heap allocate the string and return it.
• */
• char* remove_string(const char *input, const int n)
• {
• if (n <= 0 || input == NULL) return NULL;
• for (size_t i = 0, len = 0; i < (size_t)n; i++)
• {
• input += len;
• if ((len = strlen(input) + 1) == 1) return NULL;
• }
• return strdup(input);
• for (int c = 1; !(*input == '\0' && *(input + 1) == '\0') && (c < n); (*input == '\0') ? c++ : c, input++);
• return (*input == '\0') ? NULL : strdup(input);
• }