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.
I tried to make it as readable a possible without comments.
def numberprint(peak): up = ''.join(map(str, range(1,peak))) down = up[::-1] return int(up + str(peak) + down)
def numberprint(x):nor = 0final = ''while nor < x:nor += 1final += str(nor)while nor > 1:nor -= 1final += str(nor)return int(final)- def numberprint(peak):
- up = ''.join(map(str, range(1,peak)))
- down = up[::-1]
- return int(up + str(peak) + down)
def prime_checker(n): if n in [2, 3, 5]: return True elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0: return False a = int(n ** 0.5 / 30) b = [7, 11, 13, 17, 19, 23, 29, 31] for i in [30 * j for j in range(a + 1)]: if True in [n % (i + q) == 0 for q in b if i + q is not n]: return False return True
"""https://en.wikipedia.org/wiki/Primality_testThis one has lesser tests or usage of % operator.An alternative using primality mod 30 = 2 * 3 * 5 instead of 6 = 2 * 3"""- def prime_checker(n):
- if n in [2, 3, 5]:
- return True
- elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
- return False
- a = int(n ** 0.5 / 30)
- b = [7, 11, 13, 17, 19, 23, 29, 31]
- for i in [30 * j for j in range(a + 1)]:
- if True in [n % (i + q) == 0 for q in b if i + q is not n]:
- return False
- return True
from __future__ import annotations from collections import Counter def sort_values(vals:list[int]) -> list[int]: #Given an array of size N containing only 0s, 1s, and 2s; #sort the array in ascending order. assert set(vals) <= {0,1,2} return counting_sort(vals) # O(n+k) instead of n log(n) def counting_sort(vals:list[T]) -> list[T]: res = [] c = Counter(vals) for k,amt in sorted(c.items()): res += [k]*amt return res
- from __future__ import annotations
- from collections import Counter
- def sort_values(vals:list[int]) -> list[int]:
- #Given an array of size N containing only 0s, 1s, and 2s;
- #sort the array in ascending order.
- assert set(vals) <= {0,1,2}
- return counting_sort(vals)
- # O(n+k) instead of n log(n)
- def counting_sort(vals:list[T]) -> list[T]:
- res = []
- c = Counter(vals)
- for k,amt in sorted(c.items()):
- res += [k]*amt
- return res
Kumite page 1 is a little lonely.
I feel like there is a lot that can be chopped off from this, may revisit later.
f(r,n)=r^r<n ? -1 : r<2 ? 1 : parse(Int,lpad(h(r,n-1),r,"1"));h(r,n)=n<1 ? 0 : 10h(r,n÷r)+n%r+1
using System;using System.Linq;using System.Collections.Generic;public class NumbersFinder{public static int Generator(int size , int position){if ( Math.Pow( size , size ) < position )return -1;List<string> arr = new List<string>();for (int i = 0; i < size; ++i)arr.Add((i+1).ToString());List<string> newArr;while (arr.Count != Math.Pow(size,size)){newArr = new List<string>();for (int j = 0; j < arr.Count; j++)for (int i = 0; i < size; i++)newArr.Add(arr[j]+(i+1));arr.Clear();arr.AddRange(newArr);}return Convert.ToInt32(arr[position - 1]);}}- f(r,n)=r^r<n ? -1 : r<2 ? 1 : parse(Int,lpad(h(r,n-1),r,"1"));h(r,n)=n<1 ? 0 : 10h(r,n÷r)+n%r+1
# FactCheck example: # TODO: replace with your own tests (TDD), these are just how-to examples. using FactCheck facts("Testing basics") do @fact f(1,1) --> 1 @fact f(5,2595) --> 51445 @fact f(7,200017) --> 2573176 @fact f(4,257) -->-1 @fact f(3,2)--> 112 end
using NUnit.Framework;using System;using System.Collections.Generic;[TestFixture]public class SolutionTest{[Test]public void MyTest(){Assert.AreEqual(1 , NumbersFinder.Generator(1 , 1));Assert.AreEqual(51445 , NumbersFinder.Generator(5 , 2595));Assert.AreEqual(2573176 , NumbersFinder.Generator(7 , 200017));Assert.AreEqual(-1 , NumbersFinder.Generator(4 , 257));}}- # FactCheck example:
- # TODO: replace with your own tests (TDD), these are just how-to examples.
- using FactCheck
- facts("Testing basics") do
- @fact f(1,1) --> 1
- @fact f(5,2595) --> 51445
- @fact f(7,200017) --> 2573176
- @fact f(4,257) -->-1
- @fact f(3,2)--> 112
- end
let ReverseInt x = let rec ReverseInt'(acc, x) = match System.Math.DivRem(x, 10) with | (0, rem) -> 10 * acc + rem | (quot, rem) -> ReverseInt'(10 * acc + rem, quot) match System.Math.DivRem(x, 10) with | (0, rem) -> rem | (quot, rem) -> ReverseInt'(rem, quot) ;;
public class Algorithms {public static int reverseInt(int n) {int reversed = 0;while(n != 0){reversed = reversed * 10 + (n % 10);n /= 10;}return reversed;}}- let ReverseInt x =
- let rec ReverseInt'(acc, x) =
- match System.Math.DivRem(x, 10) with
- | (0, rem) -> 10 * acc + rem
- | (quot, rem) -> ReverseInt'(10 * acc + rem, quot)
- match System.Math.DivRem(x, 10) with
- | (0, rem) -> rem
- | (quot, rem) -> ReverseInt'(rem, quot)
- ;;
// Fuchu Spec example: // TODO: replace with your own tests (TDD), these are just how-to examples. // See https://github.com/mausch/Fuchu for documentation module Tests = begin open Fuchu let suite = testList "Solution" [ testCase "Example Test" <| fun _ -> Assert.Equal("12345 => 54321", (54321), ReverseInt(12345)); testCase "Example Test Two" <| fun _ -> Assert.Equal("0 -> 0", (0), ReverseInt(0)) ] end
import org.junit.Test;import static org.junit.Assert.assertEquals;import org.junit.runners.JUnit4;- // Fuchu Spec example:
- // TODO: replace with your own tests (TDD), these are just how-to examples.
- // See https://github.com/mausch/Fuchu for documentation
// TODO: Replace examples and use TDD development by writing your own testspublic class SolutionTest {@Testpublic void reverseIntTest() {assertEquals(54321, Algorithms.reverseInt(12345));}}- module Tests = begin
- open Fuchu
- let suite =
- testList "Solution" [
- testCase "Example Test" <|
- fun _ -> Assert.Equal("12345 => 54321", (54321), ReverseInt(12345));
- testCase "Example Test Two" <|
- fun _ -> Assert.Equal("0 -> 0", (0), ReverseInt(0))
- ]
- end
calculating_the_amount_energy=\ lambda c:sum(abs(c[n]-c[n+1])for n in range(len(c)-1))
using System;public static class Kata{public static int CalculatingTheAmountEnergy(int[] coordinates){// here's your code}}- calculating_the_amount_energy=\
- lambda c:sum(abs(c[n]-c[n+1])for n in range(len(c)-1))
test.assert_equals(calculating_the_amount_energy([1,5,10]),9) test.assert_equals(calculating_the_amount_energy([1,5,10,3,20]),33) test.assert_equals(calculating_the_amount_energy([0,0,1]),1)
using NUnit.Framework;using System;[TestFixture]public class SolutionTest{[TestCase(new int[] { 1, 5, 10}, ExpectedResult = 9)][TestCase(new int[] { 1, 5, 10, 3, 20}, ExpectedResult = 33)][TestCase(new int[] { 0, 0, 1}, ExpectedResult = 1)]public int Tests(int[] values) => Kata.CalculatingTheAmountEnergy(values);}- test.assert_equals(calculating_the_amount_energy([1,5,10]),9)
- test.assert_equals(calculating_the_amount_energy([1,5,10,3,20]),33)
- test.assert_equals(calculating_the_amount_energy([0,0,1]),1)
Please never actually use this method of counting digits.
#include <stdint.h> uint_fast8_t number_of_digits(uint64_t n) { return printf("%lu", n); }
fn digits(mut n: u64) -> usize {let mut l = 1;while n >= 10 {n /= 10;l += 1;}l- #include <stdint.h>
- uint_fast8_t number_of_digits(uint64_t n)
- {
- return printf("%lu", n);
- }
#include <criterion/criterion.h> #include <stdint.h> uint_fast8_t number_of_digits(uint64_t); Test(number_of_digits_tester, should_pass_all_the_tests_provided) { cr_assert_eq(number_of_digits(1ull), 1); cr_assert_eq(number_of_digits(10ull), 2); cr_assert_eq(number_of_digits(100ull), 3); cr_assert_eq(number_of_digits(1000ull), 4); cr_assert_eq(number_of_digits(10000ull), 5); cr_assert_eq(number_of_digits(100000ull), 6); cr_assert_eq(number_of_digits(1000000ull), 7); cr_assert_eq(number_of_digits(10000000ull), 8); cr_assert_eq(number_of_digits(100000000ull), 9); cr_assert_eq(number_of_digits(1000000000ull), 10); cr_assert_eq(number_of_digits(10000000000ull), 11); cr_assert_eq(number_of_digits(100000000000ull), 12); cr_assert_eq(number_of_digits(1000000000000ull), 13); cr_assert_eq(number_of_digits(10000000000000ull), 14); cr_assert_eq(number_of_digits(100000000000000ull), 15); cr_assert_eq(number_of_digits(1000000000000000ull), 16); cr_assert_eq(number_of_digits(10000000000000000ull), 17); cr_assert_eq(number_of_digits(100000000000000000ull), 18); cr_assert_eq(number_of_digits(1000000000000000000ull), 19); cr_assert_eq(number_of_digits(10000000000000000000ull), 20); }
#[test]fn pow10() {assert_eq!(digits(0), 1);for i in 0..20 {assert_eq!(digits(POW10[i]), i+1);}assert_eq!(digits(std::u64::MAX), 20);}- #include <criterion/criterion.h>
#[test]fn pow10_minus_1() {for i in 1..20 {assert_eq!(digits(POW10[i] - 1), i);}}- #include <stdint.h>
#[test]fn pow10_half() {for i in 1..20 {assert_eq!(digits(POW10[i] / 2), i);}- uint_fast8_t number_of_digits(uint64_t);
- Test(number_of_digits_tester, should_pass_all_the_tests_provided)
- {
- cr_assert_eq(number_of_digits(1ull), 1);
- cr_assert_eq(number_of_digits(10ull), 2);
- cr_assert_eq(number_of_digits(100ull), 3);
- cr_assert_eq(number_of_digits(1000ull), 4);
- cr_assert_eq(number_of_digits(10000ull), 5);
- cr_assert_eq(number_of_digits(100000ull), 6);
- cr_assert_eq(number_of_digits(1000000ull), 7);
- cr_assert_eq(number_of_digits(10000000ull), 8);
- cr_assert_eq(number_of_digits(100000000ull), 9);
- cr_assert_eq(number_of_digits(1000000000ull), 10);
- cr_assert_eq(number_of_digits(10000000000ull), 11);
- cr_assert_eq(number_of_digits(100000000000ull), 12);
- cr_assert_eq(number_of_digits(1000000000000ull), 13);
- cr_assert_eq(number_of_digits(10000000000000ull), 14);
- cr_assert_eq(number_of_digits(100000000000000ull), 15);
- cr_assert_eq(number_of_digits(1000000000000000ull), 16);
- cr_assert_eq(number_of_digits(10000000000000000ull), 17);
- cr_assert_eq(number_of_digits(100000000000000000ull), 18);
- cr_assert_eq(number_of_digits(1000000000000000000ull), 19);
- cr_assert_eq(number_of_digits(10000000000000000000ull), 20);
- }
Ternary opertor FTW.
public static class Kata { public static bool IsOdd(int input) { return input % 2 != 0 ? true : false; } }
- public static class Kata
- {
- public static bool IsOdd(int input)
- {
return ((input % 10 == 1) || (input % 10 == 3) || (input % 10 == 5) || (input % 10 == 7) || (input % 10 == 9));- return input % 2 != 0 ? true : false;
- }
- }