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.
An asymptoptic change.
I also decided to change the rest of the implementation a little to show a different way to do it.
from functools import reduce from operator import add def ultimate_string_jumble_method(s): return reduce(add, (ord(c) for c in s if c != " "), 0)
- from functools import reduce
- from operator import add
- def ultimate_string_jumble_method(s):
return sum(ord(c) for c in s.replace(' ', ''))- return reduce(add, (ord(c) for c in s if c != " "), 0)
in_array=lambda a,b:sorted(filter(lambda e:any(e in i for i in b),a))
% check for Xs in As that exist in B, in sorted orderin_array(A, B, X) :-msort(A, Sorted),member(X, Sorted),in_b(X, B).in_b(A, B) :-member(X, B),sub_string(X, _, _, _, A), !.- in_array=lambda a,b:sorted(filter(lambda e:any(e in i for i in b),a))
test.assert_equals(in_array(["live", "fail", "arp", "strong"],["lively", "alive", "harp", "sharp", "armstrong"]),["arp", "live", "strong"])
:- begin_tests(example).:- include(example).test(example_test) :-A = ["live", "arp", "strong"],B = ["lively", "alive", "harp", "sharp", "armstrong"],findall(R, in_array(A, B, R), Actual), % setof?assertion(Actual == ["arp", "live", "strong"]).:- end_tests(example).- test.assert_equals(in_array(["live", "fail", "arp", "strong"],["lively", "alive", "harp", "sharp", "armstrong"]),["arp", "live", "strong"])
I had to use this for the kyu 3 binomial expansion kata since I have no clue how to use the BigInts library for Java. Instead of calculating the total value of each factorial, this finds the factors of the numerator and denominator, simplifies, and divides the results.
Note: The n-choose-k formula
n!
------------
k!(n - k)!
import static java.util.stream.IntStream.rangeClosed; interface ArrayFactorial { static int factorial(int n, int k) { return rangeClosed(1, k).reduce(1, (r, i) -> r * (n + 1 - i) / i); } }
import java.util.stream.IntStream;- import static java.util.stream.IntStream.rangeClosed;
public class ArrayFactorial{public static int factorial(int n, int k) {return IntStream.rangeClosed(1, Math.min(k, n - k)).reduce(1, (r, i) -> r * (n - i + 1) / i);}- interface ArrayFactorial {
- static int factorial(int n, int k) {
- return rangeClosed(1, k).reduce(1, (r, i) -> r * (n + 1 - i) / i);
- }
- }
import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; class SolutionTest { @Test void basicTests() { assertEquals(3, ArrayFactorial.factorial(3, 2)); assertEquals(10, ArrayFactorial.factorial(5, 2)); assertEquals(15, ArrayFactorial.factorial(6, 4)); } @Test void largerTests() { assertEquals(1365, ArrayFactorial.factorial(15, 4)); assertEquals(19448, ArrayFactorial.factorial(17, 7)); } }
import org.junit.Test;import static org.junit.Assert.assertEquals;import org.junit.runners.JUnit4;- import static org.junit.jupiter.api.Assertions.assertEquals;
// TODO: Replace examples and use TDD by writing your own tests- import org.junit.jupiter.api.Test;
public class SolutionTest {@Testpublic void BasicTests() {assertEquals(3, ArrayFactorial.factorial(3, 2));assertEquals(10, ArrayFactorial.factorial(5, 2));assertEquals(15, ArrayFactorial.factorial(6, 4));}@Testpublic void LargerTests() {assertEquals(1365, ArrayFactorial.factorial(15, 4));assertEquals(19448, ArrayFactorial.factorial(17, 7));}- class SolutionTest {
- @Test
- void basicTests() {
- assertEquals(3, ArrayFactorial.factorial(3, 2));
- assertEquals(10, ArrayFactorial.factorial(5, 2));
- assertEquals(15, ArrayFactorial.factorial(6, 4));
- }
- @Test
- void largerTests() {
- assertEquals(1365, ArrayFactorial.factorial(15, 4));
- assertEquals(19448, ArrayFactorial.factorial(17, 7));
- }
- }
Removed that one testcase with o=3 because it's not well defined what the behaviour should be if o is 3, and I dislike writing hard-coding type solutions.
// int add(char*s,int o){return*s?*s%48*(!o|~*s+o&1)+add(s+1,o):0;}
# just squished your version a little moreadd=lambda s,o:sum(filter(lambda n:o<1or~n+o&1,map(int,s)))- //
- int add(char*s,int o){return*s?*s%48*(!o|~*s+o&1)+add(s+1,o):0;}
// TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example. #include <criterion/criterion.h> // replace with the actual method being tested // Test(the_multiply_function, should_pass_all_the_tests_provided) { cr_assert_eq(add("1234567", 0), 28); cr_assert_eq(add("1234567", 1), 16); cr_assert_eq(add("1234567", 2), 12); cr_assert_eq(add("0", 0), 0); cr_assert_eq(add("0", 1), 0); cr_assert_eq(add("0", 2), 0); // cr_assert_eq(add("0", 3), 0); cr_assert_eq(add("23232323", 0), 20); cr_assert_eq(add("23232323", 1), 12); cr_assert_eq(add("23232323", 2), 8); }
test.assert_equals(add("1234567" , 0),28)test.assert_equals(add("1234567" , 1),16)test.assert_equals(add("1234567" , 2),12)test.assert_equals(add("0" , 2),0)test.assert_equals(add("0" , 1),0)test.assert_equals(add("0" , 0),0)test.assert_equals(add("0" , 3),0) # what is thistest.assert_equals(add("23232323" , 2),8)test.assert_equals(add("23232323" , 1),12)- // TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example.
- #include <criterion/criterion.h>
- // replace with the actual method being tested
- //
- Test(the_multiply_function, should_pass_all_the_tests_provided)
- {
- cr_assert_eq(add("1234567", 0), 28);
- cr_assert_eq(add("1234567", 1), 16);
- cr_assert_eq(add("1234567", 2), 12);
- cr_assert_eq(add("0", 0), 0);
- cr_assert_eq(add("0", 1), 0);
- cr_assert_eq(add("0", 2), 0);
- // cr_assert_eq(add("0", 3), 0);
- cr_assert_eq(add("23232323", 0), 20);
- cr_assert_eq(add("23232323", 1), 12);
- cr_assert_eq(add("23232323", 2), 8);
- }
def match(pattern): def matcher(string): return len(pattern) == len(string) and all(a == '.' or a == b for a, b in zip(pattern, string)) return matcher
- def match(pattern):
- def matcher(string):
return len(pattern) == len(string) and all(a == b if a != '.' else True for a, b in zip(pattern, string))- return len(pattern) == len(string) and all(a == '.' or a == b for a, b in zip(pattern, string))
- return matcher
#include <stdint.h> uint_fast8_t number_of_digits(uint64_t n) { uint_fast8_t digits = 1; while(n /= 10) digits++; return digits; }
- #include <stdint.h>
- uint_fast8_t number_of_digits(uint64_t n)
- {
uint_fast8_t digits = 0;for (; n > 0; n /= 10) digits++;- uint_fast8_t digits = 1;
- while(n /= 10) digits++;
- return digits;
- }