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.
One line reduction method
import java.util.*; public class Kata { public static int findMax(int[] my_array) {return Arrays.stream(my_array).reduce(my_array[0], (x, y) -> x > y ? x : y);} }
- import java.util.*;
- public class Kata {
public static int findMax(int[] my_array) {// Write a method that returns the largest integer in the list.// You can assume that the list has at least one element.Arrays.sort(my_array);return (my_array[my_array.length-1]);}- public static int findMax(int[] my_array) {return Arrays.stream(my_array).reduce(my_array[0], (x, y) -> x > y ? x : y);}
- }
Dictionary :)
def converter(number): dictionary = { 0: "zero", 1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 10: 10 } return dictionary[number]
- def converter(number):
match number:case 0:return 'zero'case 1:return 'one'case 2:return 'two'case 3:return 'three'case 4:return 'four'case 5:return 'five'case 6:return 'six'case 7:return 'seven'case 8:return 'eight'case 9:return 'nine'case _:return number- dictionary = {
- 0: "zero",
- 1: "one",
- 2: "two",
- 3: "three",
- 4: "four",
- 5: "five",
- 6: "six",
- 7: "seven",
- 8: "eight",
- 9: "nine",
- 10: 10
- }
- return dictionary[number]
def meaning_of_life_is(): return ord('*')
def meaning_of_life_is():return """go crazy with your imagination and return anything you like.strings, numbers, ... just don't return None.may the most creative answer win"""- def meaning_of_life_is():
- return ord('*')
import codewars_test as test # TODO Write tests from solution import meaning_of_life_is # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(meaning_of_life_is(), 42)
- import codewars_test as test
- # TODO Write tests
- from solution import meaning_of_life_is # or from solution import example
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_not_equals(meaning_of_life_is(), None)- test.assert_equals(meaning_of_life_is(), 42)
def numberprint(x): f = '' for i in range(x): f += str(i) for i in range(x,0,-1): f += str(i) return int(f)
- def numberprint(x):
nor = 0final = ''while nor < x:nor += 1final += str(nor)while nor > 1:nor -= 1final += str(nor)return int(final)- f = ''
- for i in range(x):
- f += str(i)
- for i in range(x,0,-1):
- f += str(i)
- return int(f)
def prime_checker(n): if n in [2, 3, 5]: return True elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0: return False a = int(n ** 0.5 / 30) b = [7, 11, 13, 17, 19, 23, 29, 31] for i in [30 * j for j in range(a + 1)]: if True in [n % (i + q) == 0 for q in b if i + q is not n]: return False return True
"""https://en.wikipedia.org/wiki/Primality_testThis one has lesser tests or usage of % operator.An alternative using primality mod 30 = 2 * 3 * 5 instead of 6 = 2 * 3"""- def prime_checker(n):
- if n in [2, 3, 5]:
- return True
- elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
- return False
- a = int(n ** 0.5 / 30)
- b = [7, 11, 13, 17, 19, 23, 29, 31]
- for i in [30 * j for j in range(a + 1)]:
- if True in [n % (i + q) == 0 for q in b if i + q is not n]:
- return False
- return True
I tried to finish in one line
public class FizzBuzz { public string GetOutput(int number) => number % 15 == 0 ? "FizzBuzz" : number % 3 == 0 ? "Fizz" : number % 5 == 0 ? "Buzz" : number.ToString(); }
- public class FizzBuzz
- {
public string GetOutput(int number) {if (number % 15 == 0) return "FizzBuzz";else if (number % 3 == 0) return "Fizz";else if (number % 5 == 0) return "Buzz";else return number.ToString();// Fizz buzz is a popular computer science interview question.// The function above is given a number - if the number is// divisible by 3, return "fizz", if it's divisible by 5,// return "buzz", if not divisble by 3 or 5 - return the// number itself.}- public string GetOutput(int number)
- => number % 15 == 0 ? "FizzBuzz" : number % 3 == 0 ? "Fizz" : number % 5 == 0 ? "Buzz" : number.ToString();
- }
let number_of_digits x = String.concat "" ["1"; String.make (x - 1) '0'] |> int_of_string;;
fn digits(mut n: u64) -> usize {let mut l = 1;while n >= 10 {n /= 10;l += 1;}l}- let number_of_digits x =
- String.concat "" ["1"; String.make (x - 1) '0'] |> int_of_string;;
module Tests = struct open OUnit let suite = [ "number_of_digits" >::: [ "1 -> 1" >:: (fun _ -> assert_equal (number_of_digits 1) 1); "10 -> 1000000000" >:: (fun _ -> assert_equal (number_of_digits 10) 1000000000); "18 -> 100000000000000000" >:: (fun _ -> assert_equal (number_of_digits 18) 100000000000000000); ] ] end
#[test]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);}#[test]fn pow10_minus_1() {for i in 1..20 {assert_eq!(digits(POW10[i] - 1), i);}}#[test]fn pow10_half() {for i in 1..20 {assert_eq!(digits(POW10[i] / 2), i);}}- module Tests = struct
- open OUnit
- let suite = [
- "number_of_digits" >::: [
- "1 -> 1"
- >:: (fun _ -> assert_equal (number_of_digits 1) 1);
- "10 -> 1000000000"
- >:: (fun _ -> assert_equal (number_of_digits 10) 1000000000);
- "18 -> 100000000000000000"
- >:: (fun _ -> assert_equal (number_of_digits 18) 100000000000000000);
- ]
- ]
- end
(ns reverseint.core) (defn reverse-int' [acc x] (let [quot-rem (.divideAndRemainder x java.math.BigInteger/TEN)] (if (= (nth quot-rem 0) 0) (+ (* 10 acc) (nth quot-rem 1)) (reverse-int' (+ (* 10 acc) (nth quot-rem 1)) (nth quot-rem 0))))) (defn reverse-int [n] (let [quot-rem (.divideAndRemainder (biginteger n) java.math.BigInteger/TEN)] (reverse-int' (nth quot-rem 1) (nth quot-rem 0))))
public class Algorithms {public static int reverseInt(int n) {int reversed = 0;while(n != 0){reversed = reversed * 10 + (n % 10);n /= 10;}return reversed;}}- (ns reverseint.core)
- (defn reverse-int' [acc x]
- (let [quot-rem (.divideAndRemainder
- x
- java.math.BigInteger/TEN)]
- (if (= (nth quot-rem 0) 0) (+ (* 10 acc) (nth quot-rem 1))
- (reverse-int' (+ (* 10 acc) (nth quot-rem 1)) (nth quot-rem 0)))))
- (defn reverse-int [n]
- (let [quot-rem (.divideAndRemainder
- (biginteger n)
- java.math.BigInteger/TEN)]
- (reverse-int' (nth quot-rem 1) (nth quot-rem 0))))
(ns reverseint.test (:require [clojure.test :refer :all] [reverseint.core :refer [reverse-int]])) (deftest reverse-int-test (is (= (reverse-int 12345) 54321)) (is (= (reverse-int 0) 0)))
import org.junit.Test;import static org.junit.Assert.assertEquals;import org.junit.runners.JUnit4;// TODO: Replace examples and use TDD development by writing your own testspublic class SolutionTest {@Testpublic void reverseIntTest() {assertEquals(54321, Algorithms.reverseInt(12345));}}- (ns reverseint.test
- (:require [clojure.test :refer :all]
- [reverseint.core :refer [reverse-int]]))
- (deftest reverse-int-test
- (is (= (reverse-int 12345) 54321))
- (is (= (reverse-int 0) 0)))