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.
const nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] function digitToText(digit) { return nums[digit] }
- const nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
- function digitToText(digit) {
if (digit == 1) {return 'one'}if (digit == 2) {return 'two'}if (digit == 3) {return 'three'}if (digit == 4) {return 'four'}if (digit == 5) {return 'five'}if (digit == 6) {return 'six'}if (digit == 7) {return 'seven'}if (digit == 8) {return 'eight'}if (digit == 9) {return 'nine'}if (digit == 0) {return 'zero'}- return nums[digit]
- }
class Triangle: @staticmethod def other_angle(a, b): return 180 - (a + b) @staticmethod def triangle_type_angle(a, b, c): if all( angle < 90 for angle in (a, b ,c)): return "Acute Triangle" if any(angle == 90 for angle in (a, b, c)): return "Right Triangle" return "Obtuse Triangle" @staticmethod def triangle_type_sides(s1, s2, s3): if s1 == s2 == s3: return "Equilateral Triangle" elif s1 == s2 or s2 == s3 or s1 == s3: return "Isoceles Triangle" return "Scalene Triangle"
- class Triangle:
- @staticmethod
- def other_angle(a, b):
- return 180 - (a + b)
- @staticmethod
- def triangle_type_angle(a, b, c):
- if all( angle < 90 for angle in (a, b ,c)):
- return "Acute Triangle"
- if any(angle == 90 for angle in (a, b, c)):
- return "Right Triangle"
- return "Obtuse Triangle"
- @staticmethod
- def triangle_type_sides(s1, s2, s3):
- if s1 == s2 == s3:
- return "Equilateral Triangle"
- elif s1 == s2 or s2 == s3 or s1 == s3:
- return "Isoceles Triangle"
- return "Scalene Triangle"
const BLOCK_WIDTH: i32 = 274; const BLOCK_HEIGHT: i32 = 80; const PROBATION_LIMIT: i32 = 2000; fn goes_to_jail(directions: &[[i32;4]]) -> bool { let (mut x, mut y) = (0, 0); directions.iter().any(|[north, east, south, west]| { x += (east - west) * BLOCK_WIDTH; y += (north - south) * BLOCK_HEIGHT; x.pow(2) + y.pow(2) > PROBATION_LIMIT.pow(2) }) }
- const BLOCK_WIDTH: i32 = 274;
- const BLOCK_HEIGHT: i32 = 80;
- const PROBATION_LIMIT: i32 = 2000;
- fn goes_to_jail(directions: &[[i32;4]]) -> bool {
let mut x = 0;let mut y = 0;for [north, east, south, west] in directions {- let (mut x, mut y) = (0, 0);
- directions.iter().any(|[north, east, south, west]| {
- x += (east - west) * BLOCK_WIDTH;
- y += (north - south) * BLOCK_HEIGHT;
if x.pow(2) + y.pow(2) > PROBATION_LIMIT.pow(2) {return true}}false- x.pow(2) + y.pow(2) > PROBATION_LIMIT.pow(2)
- })
- }
Added tests for negative integers, modified solution so it doesn't rely on Show
instance of Int
.
module AreThereThree where solution :: Int -> Bool solution = go . abs where go 0 = False go x = let (x', y) = x `divMod` 10 in y == 3 || go x'
- module AreThereThree where
- solution :: Int -> Bool
solution = elem '3' . show- solution = go . abs
- where
- go 0 = False
- go x = let (x', y) = x `divMod` 10 in y == 3 || go x'
module AreThereThreeSpec where import Test.Hspec import AreThereThree spec :: Spec spec = do describe "Fixed Tests" $ do it "should return True if contains 3" $ do solution 354523 `shouldBe` True solution 35 `shouldBe` True it "should return False if doesn't contain 3" $ do solution 1 `shouldBe` False solution 264568 `shouldBe` False it "works with negative numbers" $ do solution (-49283) `shouldBe` True solution (-2849829) `shouldBe` False main = hspec spec
- module AreThereThreeSpec where
- import Test.Hspec
- import AreThereThree
- spec :: Spec
- spec = do
describe "Tests" $ do- describe "Fixed Tests" $ do
- it "should return True if contains 3" $ do
- solution 354523 `shouldBe` True
- solution 35 `shouldBe` True
- it "should return False if doesn't contain 3" $ do
- solution 1 `shouldBe` False
- solution 264568 `shouldBe` False
- it "works with negative numbers" $ do
- solution (-49283) `shouldBe` True
- solution (-2849829) `shouldBe` False
- main = hspec spec
pub struct Account { password: String, secret: String, } impl Account { pub fn new(password: String, secret: String) -> Self { Self { password, secret } } pub fn request_secret(&self, input: &str) -> Option<&str> { if input == self.password { Some(&self.secret) } else { None } } }
mod preloaded;use preloaded::Account;- pub struct Account {
- password: String,
- secret: String,
- }
- impl Account {
- pub fn new(password: String, secret: String) -> Self {
- Self { password, secret }
- }
- pub fn request_secret(&self, input: &str) -> Option<&str> {
- if input == self.password {
- Some(&self.secret)
- } else {
- None
- }
- }
- }
#[test] fn test() { let account = Account::new("password123".into(), "I don't like pizza".into()); assert_eq!(account.request_secret("password123"), Some("I don't like pizza")); assert_eq!(account.request_secret("supersecret"), None); }
- #[test]
- fn test() {
let mut account = Account::new("password123".into(), "I don't like pizza".into());assert_eq!(account.secret(), None);account.login("password123");assert_eq!(account.secret(), Some("I don't like pizza"));account.logout();assert_eq!(account.secret(), None);account.login("supersecret");assert_eq!(account.secret(), None);- let account = Account::new("password123".into(), "I don't like pizza".into());
- assert_eq!(account.request_secret("password123"), Some("I don't like pizza"));
- assert_eq!(account.request_secret("supersecret"), None);
- }
let [min, max] = [iter.next()?;2]; let minmax = iter.fold((min, max), |(min, max), num| (num.min(min), num.max(max))); Some(minmax)}
fn find_largest_and_smallest(nums: &[i32]) -> Option<(i32, i32)> {let mut iter = nums.iter().copied();let [min, max] = [iter.next()?;2];let minmax = iter.fold((min, max), |(min, max), num| (num.min(min), num.max(max)));Some(minmax)}- let [min, max] = [iter.next()?;2]; let minmax = iter.fold((min, max), |(min, max), num| (num.min(min), num.max(max))); Some(minmax)}