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.
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
module AreThereThree where solution :: Int -> Bool solution 0 = False solution x = y == 3 || solution x' where (x', y) = divMod (abs x) 10
- module AreThereThree where
- solution :: Int -> Bool
solution = go . abswherego 0 = Falsego x = let (x', y) = x `divMod` 10 in y == 3 || go x'- solution 0 = False
- solution x = y == 3 || solution x'
- where (x', y) = divMod (abs x) 10
dumbRockPaperScissors =(a,b)=> a==b?`Draw`:`Player ${(a!={'Rock':'Paper','Paper':'Scissors','Scissors':'Rock'}[b])+1} wins`
function dumbRockPaperScissors(player1, player2) {if (player1 === player2) return "Draw";const condition = {Scissors: "Paper",Rock: "Scissors",Paper: "Rock",};return player2 === condition[player1] ? "Player 1 wins" : "Player 2 wins";}- dumbRockPaperScissors
- =(a,b)=>
- a==b?`Draw`:`Player ${(a!={'Rock':'Paper','Paper':'Scissors','Scissors':'Rock'}[b])+1} wins`
#[cfg(test)] mod tests { use super::disemvowel; use rand::Rng; fn do_test(string: &str, expected: &str) { assert_eq!(disemvowel(string), expected); } #[test] fn test() { do_test("HI GUYS", "H GYS"); do_test("AEIOU", ""); do_test("Shrek is an orge", "Shrk s n rg"); } #[test] fn random_tests() { for _ in 0..100 { let string = (0..rand::thread_rng().gen_range(0..20)) .map(|_| rand::Rng::sample(&mut rand::thread_rng(), rand::distributions::Alphanumeric) as char) .collect::<String>(); let expected = string.chars().filter(|&c| !"AEIOUaeiou".contains(c)).collect::<String>(); do_test(&string, &expected); } } }
- #[cfg(test)]
- mod tests {
- use super::disemvowel;
- use rand::Rng;
- fn do_test(string: &str, expected: &str) {
- assert_eq!(disemvowel(string), expected);
- }
- #[test]
- fn test() {
assert_eq!(disemvowel("HI GUYS"), "H GYS");assert_eq!(disemvowel("AEIOU"), "");assert_eq!(disemvowel("Shrek is an orge"), "Shrk s n rg");- do_test("HI GUYS", "H GYS");
- do_test("AEIOU", "");
- do_test("Shrek is an orge", "Shrk s n rg");
- }
- #[test]
- fn random_tests() {
- for _ in 0..100 {
- let string = (0..rand::thread_rng().gen_range(0..20))
- .map(|_| rand::Rng::sample(&mut rand::thread_rng(), rand::distributions::Alphanumeric) as char)
- .collect::<String>();
- let expected = string.chars().filter(|&c| !"AEIOUaeiou".contains(c)).collect::<String>();
- do_test(&string, &expected);
- }
- }
- }
#[cfg(test)] mod test { use super::make_move; fn do_test(init: (i32, i32), sequence: &str, expected: (i32, i32)) { assert_eq!(make_move(init, sequence), expected); } #[test] fn simple_test() { do_test((0, 0), "ttrbrrbllrt", (2, 1)); do_test((4, 1), "bllbrt", (3, 0)); do_test((-2, 4), "trlbb", (-2, 3)); do_test((5, 5), "trlbrb", (6, 4)); } #[test] fn random_test() { use rand::Rng; use std::iter; fn generate(len: usize) -> String { const CHARSET: &[u8] = b"lrbt"; let mut rng = rand::thread_rng(); let one_char = || CHARSET[rng.gen_range(0..CHARSET.len())] as char; iter::repeat_with(one_char).take(len).collect() } fn solution(init: (i32, i32), sequence: &str) -> (i32, i32) { sequence.chars().fold(init, |(x, y), c| { ( x + match c { 'r' => 1, 'l' => -1, _ => 0, }, y + match c { 't' => 1, 'b' => -1, _ => 0, }, ) }) } for _ in 0..100 { let init = ( rand::thread_rng().gen_range(-100..100), rand::thread_rng().gen_range(-100..100), ); let sequence = generate(rand::thread_rng().gen_range(0..100)); let expected = solution(init, &sequence); do_test(init, &sequence, expected); } } }
#[test]fn test() {assert_eq!(make_move((0, 0), "ttrbrrbllrt"), (2, 1));assert_eq!(make_move((4, 1), "bllbrt"), (3, 0));assert_eq!(make_move((-2, 4), "trlbb"), (-2, 3));assert_eq!(make_move((5, 5), "trlbrb"), (6, 4));- #[cfg(test)]
- mod test {
- use super::make_move;
- fn do_test(init: (i32, i32), sequence: &str, expected: (i32, i32)) {
- assert_eq!(make_move(init, sequence), expected);
- }
- #[test]
- fn simple_test() {
- do_test((0, 0), "ttrbrrbllrt", (2, 1));
- do_test((4, 1), "bllbrt", (3, 0));
- do_test((-2, 4), "trlbb", (-2, 3));
- do_test((5, 5), "trlbrb", (6, 4));
- }
- #[test]
- fn random_test() {
- use rand::Rng;
- use std::iter;
- fn generate(len: usize) -> String {
- const CHARSET: &[u8] = b"lrbt";
- let mut rng = rand::thread_rng();
- let one_char = || CHARSET[rng.gen_range(0..CHARSET.len())] as char;
- iter::repeat_with(one_char).take(len).collect()
- }
- fn solution(init: (i32, i32), sequence: &str) -> (i32, i32) {
- sequence.chars().fold(init, |(x, y), c| {
- (
- x + match c {
- 'r' => 1,
- 'l' => -1,
- _ => 0,
- },
- y + match c {
- 't' => 1,
- 'b' => -1,
- _ => 0,
- },
- )
- })
- }
- for _ in 0..100 {
- let init = (
- rand::thread_rng().gen_range(-100..100),
- rand::thread_rng().gen_range(-100..100),
- );
- let sequence = generate(rand::thread_rng().gen_range(0..100));
- let expected = solution(init, &sequence);
- do_test(init, &sequence, expected);
- }
- }
- }