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.
fn remove_symbols(s: &str) -> String { s.chars().filter(|c| c.is_alphabetic() || c.is_whitespace()).collect() }
function removeSymbols(str) {let newStr = "";// list of possible symbolsconst symbols = "@#$%&=^*()-_=+<>/[]|?!,.£`".split("");// iterate through each characters in the input str, ignore character if it is a symbolfor (const char of str){if (!symbols.includes(char)){newStr += char;}}// return new string with no symbolsreturn (newStr);}- fn remove_symbols(s: &str) -> String {
- s.chars().filter(|c| c.is_alphabetic() || c.is_whitespace()).collect()
- }
#[test] fn test() { assert_eq!(remove_symbols("y&%ou sho!!!uld! no@t e@at yell==ow sn**ow"), "you should not eat yellow snow"); assert_eq!(remove_symbols("whe%%re ar*@e th£e birds"), "where are the birds"); assert_eq!(remove_symbols("b@an@anas are fu£@ll of potassi&%&um"), "bananas are full of potassium"); }
// Since Node 10, we're using Mocha.// You can use `chai` for assertions.const chai = require("chai");const assert = chai.assert;// Uncomment the following line to disable truncating failure messages for deep equals, do:// chai.config.truncateThreshold = 0;// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.// Uncomment the following to use the old assertions:const Test = require("@codewars/test-compat");describe("Solution", function() {it("should test for something", function() {Test.assertEquals(removeSymbols("y&%ou sho!!!uld! no@t e@at yell==ow sn**ow"), "you should not eat yellow snow");Test.assertEquals(removeSymbols("whe%%re ar*@e th£e birds"), "where are the birds");Test.assertEquals(removeSymbols("b@an@anas are fu£@ll of potassi&%&um"), "bananas are full of potassium");// assert.strictEqual(1 + 1, 2);});});- #[test]
- fn test() {
- assert_eq!(remove_symbols("y&%ou sho!!!uld! no@t e@at yell==ow sn**ow"), "you should not eat yellow snow");
- assert_eq!(remove_symbols("whe%%re ar*@e th£e birds"), "where are the birds");
- assert_eq!(remove_symbols("b@an@anas are fu£@ll of potassi&%&um"), "bananas are full of potassium");
- }
! Use vocabulary tools.testest for testing. ! See https://github.com/codewars/testest USING: kernel math foo sequences tools.testest ; IN: example.tests ! won't compile without 'first4' : y ( seq -- zero? ) x first4 [ - zero? ] 2bi@ and ; inline : run-tests ( -- ) "Example" describe#{ "test case" it#{ <{ { "nsew" } y -> t }> }# }# ; MAIN: run-tests
- ! Use vocabulary tools.testest for testing.
- ! See https://github.com/codewars/testest
USING: foo tools.testest ;- USING: kernel math foo sequences tools.testest ;
- IN: example.tests
- ! won't compile without 'first4'
- : y ( seq -- zero? ) x first4 [ - zero? ] 2bi@ and ; inline
- : run-tests ( -- )
- "Example" describe#{
- "test case" it#{
<{ { "s" } x -> { 0 0 0 1 } }>- <{ { "nsew" } y -> t }>
- }#
- }#
- ;
- MAIN: run-tests
added translation for \n
exec(f"{[].__doc__[26]}{ZeroDivisionError.__doc__[21]}{type({None}).__name__[1]}{type(1.0).__name__[0]} {(None,).__class__.__name__[2]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}{type(1).__name__[0]}{dict.__doc__[15] }{type({None}).__name__[1]}_{type(1.0).__name__[0]}{type(1.0).__name__[3]}{str(print.__module__.__class__)[1]}{type(str(), (), {}).__bases__[0].__name__[-1]}{type(1.0).__name__[2]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}{str.__name__[0]}({type(1).__name__[1]}):{[].__doc__[26]} {ZeroDivisionError.__doc__[21]}{type(1).__name__[0]}{property.__doc__[77]}{type(1).__name__[0]}{ZeroDivisionError.__doc__[21]}{type({None}).__name__[1]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]} = {type(1.0).__name__[1]}{type(1.0).__name__[3]}{dict.__doc__[15] }{type(True).__name__[0]}{ZeroDivisionError.__doc__[21]}{type(1.0).__name__[3]} {list(zip(enumerate(type(().__class__.__subclasses__()).__dict__)))[28][0][1][1] }: {type(1).__name__[1]}{type({None}).__name__[1]}{list(zip(enumerate(type(().__class__.__subclasses__()).__dict__)))[28][0][1][1] }{type(str(), (), {}).__bases__[0].__name__[-1]}(({type(1).__name__[0]} {type(1.0).__name__[0]}{type(1.0).__name__[2]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]} {type(1).__name__[0]} {type(1).__name__[0]}{type(1).__name__[1]} {().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}{type(1.0).__name__[3]}{type(1).__name__[1]}{globals.__name__[0]}{type({None}).__name__[1]}(2, {list(zip(enumerate(type(().__class__.__subclasses__()).__dict__)))[28][0][1][1] }) {type(1).__name__[0]}{type(1.0).__name__[0]} {list(zip(enumerate(type(().__class__.__subclasses__()).__dict__)))[28][0][1][1] } % {type(1).__name__[0]} == 0), -1){[].__doc__[26]}{[].__doc__[26]} {().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}{type({None}).__name__[1]}{type(str(), (), {}).__bases__[0].__name__[-1]}{(None,).__class__.__name__[1]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}{type(1).__name__[1]} ([] {type(1).__name__[0]}{type(1.0).__name__[0]} {type(1).__name__[1]} == 1 {type({None}).__name__[1]}{type(1.0).__name__[1]}{str.__name__[0]}{type({None}).__name__[1]} [{type(1).__name__[1]}]) {type(1).__name__[0]}{type(1.0).__name__[0]} {ZeroDivisionError.__doc__[21]}{type(1).__name__[0]}{property.__doc__[77]}{type(1).__name__[0]}{ZeroDivisionError.__doc__[21]}{type({None}).__name__[1]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}({type(1).__name__[1]}) == -1 {type({None}).__name__[1]}{type(1.0).__name__[1]}{str.__name__[0]}{type({None}).__name__[1]} ([{ZeroDivisionError.__doc__[21]}{type(1).__name__[0]}{property.__doc__[77]}{type(1).__name__[0]}{ZeroDivisionError.__doc__[21]}{type({None}).__name__[1]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}({type(1).__name__[1]})] + {(None,).__class__.__name__[2]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}{type(1).__name__[0]}{dict.__doc__[15] }{type({None}).__name__[1]}_{type(1.0).__name__[0]}{type(1.0).__name__[3]}{str(print.__module__.__class__)[1]}{type(str(), (), {}).__bases__[0].__name__[-1]}{type(1.0).__name__[2]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}{str.__name__[0]}({type(1).__name__[1]} // {ZeroDivisionError.__doc__[21]}{type(1).__name__[0]}{property.__doc__[77]}{type(1).__name__[0]}{ZeroDivisionError.__doc__[21]}{type({None}).__name__[1]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}({type(1).__name__[1]}))){[].__doc__[26]}")
fn prime_factors(n: u32) -> Vec<u32> {let factors: Vec<u32> = (2..=n).filter(|i| n % i == 0).collect();return factors.into_iter().take_while(|i| i * i <= n).find(|x| n % x == 0).map(|i| {let mut sub_factors = vec![i];sub_factors.extend(prime_factors(n / i));sub_factors}).unwrap_or(vec![n])}- exec(f"{[].__doc__[26]}{ZeroDivisionError.__doc__[21]}{type({None}).__name__[1]}{type(1.0).__name__[0]} {(None,).__class__.__name__[2]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}{type(1).__name__[0]}{dict.__doc__[15] }{type({None}).__name__[1]}_{type(1.0).__name__[0]}{type(1.0).__name__[3]}{str(print.__module__.__class__)[1]}{type(str(), (), {}).__bases__[0].__name__[-1]}{type(1.0).__name__[2]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}{str.__name__[0]}({type(1).__name__[1]}):{[].__doc__[26]} {ZeroDivisionError.__doc__[21]}{type(1).__name__[0]}{property.__doc__[77]}{type(1).__name__[0]}{ZeroDivisionError.__doc__[21]}{type({None}).__name__[1]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]} = {type(1.0).__name__[1]}{type(1.0).__name__[3]}{dict.__doc__[15] }{type(True).__name__[0]}{ZeroDivisionError.__doc__[21]}{type(1.0).__name__[3]} {list(zip(enumerate(type(().__class__.__subclasses__()).__dict__)))[28][0][1][1] }: {type(1).__name__[1]}{type({None}).__name__[1]}{list(zip(enumerate(type(().__class__.__subclasses__()).__dict__)))[28][0][1][1] }{type(str(), (), {}).__bases__[0].__name__[-1]}(({type(1).__name__[0]} {type(1.0).__name__[0]}{type(1.0).__name__[2]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]} {type(1).__name__[0]} {type(1).__name__[0]}{type(1).__name__[1]} {().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}{type(1.0).__name__[3]}{type(1).__name__[1]}{globals.__name__[0]}{type({None}).__name__[1]}(2, {list(zip(enumerate(type(().__class__.__subclasses__()).__dict__)))[28][0][1][1] }) {type(1).__name__[0]}{type(1.0).__name__[0]} {list(zip(enumerate(type(().__class__.__subclasses__()).__dict__)))[28][0][1][1] } % {type(1).__name__[0]} == 0), -1){[].__doc__[26]}{[].__doc__[26]} {().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}{type({None}).__name__[1]}{type(str(), (), {}).__bases__[0].__name__[-1]}{(None,).__class__.__name__[1]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}{type(1).__name__[1]} ([] {type(1).__name__[0]}{type(1.0).__name__[0]} {type(1).__name__[1]} == 1 {type({None}).__name__[1]}{type(1.0).__name__[1]}{str.__name__[0]}{type({None}).__name__[1]} [{type(1).__name__[1]}]) {type(1).__name__[0]}{type(1.0).__name__[0]} {ZeroDivisionError.__doc__[21]}{type(1).__name__[0]}{property.__doc__[77]}{type(1).__name__[0]}{ZeroDivisionError.__doc__[21]}{type({None}).__name__[1]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}({type(1).__name__[1]}) == -1 {type({None}).__name__[1]}{type(1.0).__name__[1]}{str.__name__[0]}{type({None}).__name__[1]} ([{ZeroDivisionError.__doc__[21]}{type(1).__name__[0]}{property.__doc__[77]}{type(1).__name__[0]}{ZeroDivisionError.__doc__[21]}{type({None}).__name__[1]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}({type(1).__name__[1]})] + {(None,).__class__.__name__[2]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}{type(1).__name__[0]}{dict.__doc__[15] }{type({None}).__name__[1]}_{type(1.0).__name__[0]}{type(1.0).__name__[3]}{str(print.__module__.__class__)[1]}{type(str(), (), {}).__bases__[0].__name__[-1]}{type(1.0).__name__[2]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}{str.__name__[0]}({type(1).__name__[1]} // {ZeroDivisionError.__doc__[21]}{type(1).__name__[0]}{property.__doc__[77]}{type(1).__name__[0]}{ZeroDivisionError.__doc__[21]}{type({None}).__name__[1]}{().__class__.__bases__[0].__subclasses__()[40].__name__[-1]}({type(1).__name__[1]}))){[].__doc__[26]}")
import codewars_test as test import solution # or from solution import example @test.describe("Prime factors test") def test_case(): test.assert_equals(prime_factors(100), [2, 2, 5, 5]) test.assert_equals(prime_factors(37), [37]) test.assert_equals(prime_factors(18), [2, 3, 3])
#[cfg(test)]mod tests {use super::*;#[test]fn prime_factors_test() {assert_eq!(prime_factors(100), vec![2, 2, 5, 5]);assert_eq!(prime_factors(37), vec![37]);assert_eq!(prime_factors(18), vec![2, 3, 3]);}}- import codewars_test as test
- import solution # or from solution import example
- @test.describe("Prime factors test")
- def test_case():
- test.assert_equals(prime_factors(100), [2, 2, 5, 5])
- test.assert_equals(prime_factors(37), [37])
- test.assert_equals(prime_factors(18), [2, 3, 3])
Changes
- the function now only accepts references to the input cuz duh
- the types has to implement copy so basically all integers from the standard library (RIP bigint)
use num::Num; fn sum<'a, S>(arr: impl IntoIterator<Item = &'a S>) -> S where S: 'a + Num + Copy { let mut sum = S::zero(); for i in arr { sum = sum + *i; } return sum; }
use std::iter::Sum;- use num::Num;
fn sum<T, S>(arr: T) -> S where T: IntoIterator<Item = S>, S: Sum {return arr.into_iter().sum();- fn sum<'a, S>(arr: impl IntoIterator<Item = &'a S>) -> S where S: 'a + Num + Copy {
- let mut sum = S::zero();
- for i in arr {
- sum = sum + *i;
- }
- return sum;
- }
#[cfg(test)] mod tests { use super::*; use std::collections::*; #[test] fn test_sum() { let (a, b, c) = ([1], Vec::from([3, 1]), LinkedList::from([1, 2, 3])); assert_eq!(sum(&a), 1); assert_eq!(sum(&b), 4); assert_eq!(sum(&c), 6); } }
- #[cfg(test)]
- mod tests {
- use super::*;
- use std::collections::*;
- #[test]
- fn test_sum() {
assert_eq!(sum([1]), 1);assert_eq!(sum(Vec::from([3, 1])), 4);assert_eq!(sum(LinkedList::from([1, 2, 3])), 6);- let (a, b, c) = ([1], Vec::from([3, 1]), LinkedList::from([1, 2, 3]));
- assert_eq!(sum(&a), 1);
- assert_eq!(sum(&b), 4);
- assert_eq!(sum(&c), 6);
- }
- }