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.
Leading characters that are not letters should be ignored.
Added relevant test cases.
module ToUpperFirst where import Data.Char (toUpper, isLetter) toUpperFirst :: String -> String toUpperFirst str = case break isLetter str of (xs, y:ys) -> xs ++ toUpper y : ys _ -> str
- module ToUpperFirst where
import Data.Char (toUpper, isSpace)toUpperFirst (x : xs) = if isSpace x then x : toUpperFirst xs else toUpper x : xstoUpperFirst _ = ""- import Data.Char (toUpper, isLetter)
- toUpperFirst :: String -> String
- toUpperFirst str =
- case break isLetter str of
- (xs, y:ys) -> xs ++ toUpper y : ys
- _ -> str
module ExampleSpec where import Test.Hspec import ToUpperFirst spec :: Spec spec = do describe "toUpperFirst" $ do it "should capitalize first letter of a string" $ do toUpperFirst "" `shouldBe` "" toUpperFirst "finn the human" `shouldBe` "Finn the human" toUpperFirst "alice" `shouldBe` "Alice" toUpperFirst "Joe" `shouldBe` "Joe" toUpperFirst " bob" `shouldBe` " Bob" toUpperFirst "\nsteven" `shouldBe` "\nSteven" it "should work if the first letter occurs after digits" $ do toUpperFirst "3fish" `shouldBe` "3Fish" toUpperFirst "383\n 38boB" `shouldBe` "383\n 38BoB"
- module ExampleSpec where
- --- Tests can be written using Hspec http://hspec.github.io/
- --- Replace this with your own tests.
- import Test.Hspec
- import ToUpperFirst
- --- `spec` of type `Spec` must exist
- spec :: Spec
- spec = do
describe "toUpperFirst" $ doit "should capitalize first letter of a string" $ dotoUpperFirst "" `shouldBe` ""toUpperFirst "finn the human" `shouldBe` "Finn the human"toUpperFirst "alice" `shouldBe` "Alice"toUpperFirst "Joe" `shouldBe` "Joe"toUpperFirst " bob" `shouldBe` " Bob"toUpperFirst "steven" `shouldBe` "Steven"-- the following line is optional for 8.2main = hspec spec- describe "toUpperFirst" $ do
- it "should capitalize first letter of a string" $ do
- toUpperFirst "" `shouldBe` ""
- toUpperFirst "finn the human" `shouldBe` "Finn the human"
- toUpperFirst "alice" `shouldBe` "Alice"
- toUpperFirst "Joe" `shouldBe` "Joe"
- toUpperFirst " bob" `shouldBe` " Bob"
- toUpperFirst "
- steven" `shouldBe` "
- Steven"
- it "should work if the first letter occurs after digits" $ do
- toUpperFirst "3fish" `shouldBe` "3Fish"
- toUpperFirst "383\n 38boB" `shouldBe` "383\n 38BoB"
shorter code chars..
n=s=>[...s].map(e=>("aeiou".includes(e)?"aeiou".indexOf(e)+1:e)).join`` d=s=>[...s].map(e=>(+e&&e<6?"aeiou"[e-1]:e)).join``
- n=s=>[...s].map(e=>("aeiou".includes(e)?"aeiou".indexOf(e)+1:e)).join``
d=s=>[...s].map(e=>("12345".includes(e)?"aeiou"[e-1]:e)).join``- d=s=>[...s].map(e=>(+e&&e<6?"aeiou"[e-1]:e)).join``
class Disemvowel: def __init__(self, s): self.s = s def scalpel(self): return ("".join(x for x in self.s if x.lower() not in "aeiou"))
def disemvowel(string):return ("".join(char for char in string if char.lower() not in "aeiou"))- class Disemvowel:
- def __init__(self, s):
- self.s = s
- def scalpel(self):
- return ("".join(x for x in self.s if x.lower() not in "aeiou"))
import codewars_test as test from solution import Disemvowel # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def hi_guys(): test.assert_equals(Disemvowel("HI GUYS").scalpel(), "H GYS") test.assert_equals(Disemvowel("AEIOU").scalpel(), "") test.assert_equals(Disemvowel("Shrek is an orge").scalpel(), "Shrk s n rg") test.assert_equals(Disemvowel("Seraph is coding in Python").scalpel(), "Srph s cdng n Pythn") test.assert_equals(Disemvowel("C0ffee makes Code!").scalpel(), "C0ff mks Cd!")
- import codewars_test as test
# TODO Write testsimport solution # or from solution import example- from solution import Disemvowel
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def hi_guys():
test.assert_equals(disemvowel("HI GUYS"), "H GYS")test.assert_equals(disemvowel("AEIOU"), "")test.assert_equals(disemvowel("Shrek is an orge"), "Shrk s n rg")test.assert_equals(disemvowel("Seraph is coding in Python"), "Srph s cdng n Pythn")test.assert_equals(disemvowel("C0ffee makes Code!"), "C0ff mks Cd!")- test.assert_equals(Disemvowel("HI GUYS").scalpel(), "H GYS")
- test.assert_equals(Disemvowel("AEIOU").scalpel(), "")
- test.assert_equals(Disemvowel("Shrek is an orge").scalpel(), "Shrk s n rg")
- test.assert_equals(Disemvowel("Seraph is coding in Python").scalpel(), "Srph s cdng n Pythn")
- test.assert_equals(Disemvowel("C0ffee makes Code!").scalpel(), "C0ff mks Cd!")
class HelloWorld: def __init__(self, param=''): self.param = param def message(self): return f'Hello, {self.param.title()}!' if self.param else 'Hello, World!'
def hello_world(param=''):return f'Hello, {param.title()}!' if param else 'Hello, World!'- class HelloWorld:
- def __init__(self, param=''):
- self.param = param
- def message(self):
- return f'Hello, {self.param.title()}!' if self.param else 'Hello, World!'
import codewars_test as test from solution import HelloWorld @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(HelloWorld('seraph').message(), 'Hello, Seraph!' ) test.assert_equals(HelloWorld().message(), 'Hello, World!' )
- import codewars_test as test
from solution import hello_world- from solution import HelloWorld
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_equals(hello_world('seraph'), 'Hello, Seraph!' )test.assert_equals(hello_world(), 'Hello, World!' )- test.assert_equals(HelloWorld('seraph').message(), 'Hello, Seraph!' )
- test.assert_equals(HelloWorld().message(), 'Hello, World!' )
that's called "thinking outside the box"
dumbRockPaperScissors=(a,b)=>a==b?`Draw`:`Player ${(a.slice(0,1)!={'R':'P','P':'S','S':'R'}[b.slice(0,1)])+1} wins`
dumbRockPaperScissors=(a,b)=>a==b?`Draw`:`Player ${(a!={'Rock':'Paper','Paper':'Scissors','Scissors':'Rock'}[b])+1} wins`- dumbRockPaperScissors=(a,b)=>a==b?`Draw`:`Player ${(a.slice(0,1)!={'R':'P','P':'S','S':'R'}[b.slice(0,1)])+1} wins`
Can't beat this can you? 😏
The simple fix. Runtime around 3 seconds for 10000 calls.
use std::{thread, sync::atomic::{AtomicU32, Ordering::Relaxed}}; fn count() -> u32 { let count = AtomicU32::new(0); thread::scope(|s| { for _ in 0..10 { s.spawn(|| { for _ in 0..100 { count.fetch_add(1, Relaxed); } }); } }); count.into_inner() }
- use std::{thread, sync::atomic::{AtomicU32, Ordering::Relaxed}};
- fn count() -> u32 {
- let count = AtomicU32::new(0);
- thread::scope(|s| {
- for _ in 0..10 {
- s.spawn(|| {
- for _ in 0..100 {
let current = count.load(Relaxed);count.store(current + 1, Relaxed);- count.fetch_add(1, Relaxed);
- }
- });
- }
- });
- count.into_inner()
- }
use std::time::Instant; #[test] fn test_count() { let start = Instant::now(); for _ in 0..10_000 { assert_eq!(count(), 1_000); } let elapsed = start.elapsed(); println!("{}ms", elapsed.as_millis()); }
- use std::time::Instant;
- #[test]
- fn test_count() {
- let start = Instant::now();
- for _ in 0..10_000 {
- assert_eq!(count(), 1_000);
- }
- let elapsed = start.elapsed();
- println!("{}ms", elapsed.as_millis());
- }