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.
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());
- }
Para que se devuelva el numero maximo formado de los numeros dados:
Hay que convertir el numero es un cadena de strings y juntarlos en un array, ordenarlos de menor a mayor y luego invertir el orden, devolver el array ordenado de mayor a menor pasado a formato Long.
import java.util.Arrays; class MaxNumber { public static long print(long number) { String stringDeNumber= Long.toString(number); //convierto la variable number de Long a String char[] arrayNumeros = stringDeNumber.toCharArray(); // creo un array a partir del string number Arrays.sort(arrayNumeros); //los ordeno de menos a mayor StringBuilder numerosOrdenados = new StringBuilder(new String(arrayNumeros)).reverse(); // creo una variable tipo StringBuilder para cambiar el orden y que se acomoden de mayor a menor return Long.parseLong(numerosOrdenados.toString()); // paso la cadena ordenada de nuevo a Long } } //La notacion Big-O es: O(n log n) Tiempo lineal-logarítmico. Ya que usa ordenamientos y reordenamientos de strings
- import java.util.Arrays;
public class MaxNumber {- class MaxNumber {
- public static long print(long number) {
return number- String stringDeNumber= Long.toString(number); //convierto la variable number de Long a String
- char[] arrayNumeros = stringDeNumber.toCharArray(); // creo un array a partir del string number
- Arrays.sort(arrayNumeros); //los ordeno de menos a mayor
- StringBuilder numerosOrdenados = new StringBuilder(new String(arrayNumeros)).reverse(); // creo una variable tipo StringBuilder para cambiar el orden y que se acomoden de mayor a menor
- return Long.parseLong(numerosOrdenados.toString()); // paso la cadena ordenada de nuevo a Long
- }
}- }
- //La notacion Big-O es: O(n log n) Tiempo lineal-logarítmico. Ya que usa ordenamientos y reordenamientos de strings