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.
module FindMaxNumber where find_max :: Ord a => [a] -> a find_max [] = error "find_max: Empty list" find_max (x:xs) = foldr (\ a b -> if a > b then a else b) x xs
- module FindMaxNumber where
- find_max :: Ord a => [a] -> a
find_max = maximum- find_max [] = error "find_max: Empty list"
- find_max (x:xs) = foldr (\ a b -> if a > b then a else b) x xs
module FindMaxNumberSpec where import Test.Hspec import Test.QuickCheck import FindMaxNumber spec = do describe "Test find_max" $ do it "find_max [1,2,3,4,5]" $ do find_max [1, 2, 3, 4, 5] `shouldBe` 5 it "Random tests" $ do property $ \ xs -> if null xs then True else find_max xs == maximum (xs :: [Int])
- module FindMaxNumberSpec where
- import Test.Hspec
- import Test.QuickCheck
- import FindMaxNumber
- spec = do
- describe "Test find_max" $ do
- it "find_max [1,2,3,4,5]" $ do
find_max [1, 2, 3, 4, 5] `shouldBe` 5- find_max [1, 2, 3, 4, 5] `shouldBe` 5
- it "Random tests" $ do
- property $ \ xs -> if null xs then True else find_max xs == maximum (xs :: [Int])
fn flip_the_number(x: &u64) -> u64 { x.to_string().chars().rev().collect::<String>().parse::<u64>().unwrap() }
def flip_the_number(x):return int(str(x)[::-1])- fn flip_the_number(x: &u64) -> u64 {
- x.to_string().chars().rev().collect::<String>().parse::<u64>().unwrap()
- }
fn test() { for num in NUMS.iter() { assert_eq!(num.1, flip_the_number(&num.0)); } }
from random import randinttest.describe("Basic Tests")test.assert_equals(flip_the_number("12345"), 54321)test.assert_equals(flip_the_number("1973572"), 2753791)test.assert_equals(flip_the_number(1973572), 2753791)test.describe("Random tests")for x in range(100):num = randint(0, 1000000000)if x % 2 == 0:test.assert_equals(flip_the_number(num), int(str(num)[::-1]))else:test.assert_equals(flip_the_number(str(num)), int(str(num)[::-1]))- #[test]
- fn test() {
- for num in NUMS.iter() {
- assert_eq!(num.1, flip_the_number(&num.0));
- }
- }
Numbers
Data Types
Integers
Algorithms
Logic
fn digits(n: u64) -> usize { match n { 0 => 1, _ => (n as f64).log10().floor() as usize + 1 } }
fn digits(n: u64, base: u64) -> usize {digits_iter(n, base).count()}fn digits_iter(n: u64, base: u64) -> impl Iterator<Item = u64> {let mut n = Some(n);std::iter::from_fn(move || match n {Some(x) => {let digit = x % base;n = Some(x / base);if let Some(0) = n {n = None;}Some(digit)}_ => None,})}- fn digits(n: u64) -> usize {
- match n {
- 0 => 1,
- _ => (n as f64).log10().floor() as usize + 1
- }
- }
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); } fn pow10_minus_10_perc() { for i in 1..20 { assert_eq!(digits(POW10[i] - (POW10[i]/10) as u64), i); } } fn pow10_half() { for i in 1..20 { assert_eq!(digits(POW10[i] / 2), i); } }
- #[test]
- fn pow10() {
assert_eq!(digits(0, 10), 1);- assert_eq!(digits(0), 1);
- for i in 0..20 {
assert_eq!(digits(POW10[i], 10), i+1);- assert_eq!(digits(POW10[i]), i+1);
- }
assert_eq!(digits(std::u64::MAX, 10), 20);- assert_eq!(digits(std::u64::MAX), 20);
- }
- #[test]
fn pow10_minus_1() {- fn pow10_minus_10_perc() {
- for i in 1..20 {
assert_eq!(digits(POW10[i] - 1, 10), i);- assert_eq!(digits(POW10[i] - (POW10[i]/10) as u64), i);
- }
- }
- #[test]
- fn pow10_half() {
- for i in 1..20 {
assert_eq!(digits(POW10[i] / 2, 10), i);- assert_eq!(digits(POW10[i] / 2), i);
- }
}#[test]fn base2(){for i in 1..20{assert_eq!(digits(2u64.pow(i), 2), (i+1) as usize);}}#[test]fn base16(){for i in 1..10{assert_eq!(digits(16u64.pow(i), 16), (i+1) as usize);}- }