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.
here is mine updated and better
import java.util.stream.*; public class Average { public static int averageFinder(int[] arr) { return (int)IntStream.of(arr).average().orElse(0); } }
import java.util.*;- import java.util.stream.*;
- public class Average {
- public static int averageFinder(int[] arr) {
return (int)Arrays.stream(arr).average().orElse(0d);};- return (int)IntStream.of(arr).average().orElse(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 tests public class SolutionTest { @Test public void testSomething() { Average av = new Average(); int arr1[] = {96, 98}; assertEquals(97, av.averageFinder(arr1)); int arr2[] = {94, 96, 98}; assertEquals(96, av.averageFinder(arr2)); int arr3[] = {}; assertEquals(0, av.averageFinder(arr3)); int arr4[] = {5,6}; assertEquals(5, av.averageFinder(arr4)); } }
- 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 tests
- public class SolutionTest {
- @Test
- public void testSomething() {
- Average av = new Average();
- int arr1[] = {96, 98};
- assertEquals(97, av.averageFinder(arr1));
- int arr2[] = {94, 96, 98};
- assertEquals(96, av.averageFinder(arr2));
- int arr3[] = {};
- assertEquals(0, av.averageFinder(arr3));
- int arr4[] = {5,6};
- assertEquals(5, av.averageFinder(arr4));
- }
- }
(playing around with kumite)
for some this might be readable.
using System; namespace Solution { class FizzBuzz { public static string convert(int input) { bool divisableBy3 = (input % 3 == 0); bool divisableBy5 = (input % 5 == 0); if (!divisableBy3 & !divisableBy5) return input.ToString(); return (divisableBy3 ? "Fizz" : "") + (divisableBy5 ? "Buzz" : "");; } } }
- using System;
- namespace Solution {
- class FizzBuzz {
- public static string convert(int input)
- {
var output = "";output += (input % 3 == 0) ? "Fizz" : "";output += (input % 5 == 0) ? "Buzz" : "";output += (string.IsNullOrEmpty(output)) ? input.ToString() : "";return output;- bool divisableBy3 = (input % 3 == 0);
- bool divisableBy5 = (input % 5 == 0);
- if (!divisableBy3 & !divisableBy5)
- return input.ToString();
- return (divisableBy3 ? "Fizz" : "") + (divisableBy5 ? "Buzz" : "");;
- }
- }
- }
shorther version
import java.util.*; class Node { int value; Node left; Node right; public Node(int value) { this.value = value; } } class BST { public static boolean search(Node root, int key) { while(root != null) { if(root.value == key) { return true; } else root=(root.value > key)?root.left:root.right; } return false; } }
- import java.util.*;
- class Node {
- int value;
- Node left;
- Node right;
- public Node(int value) {
- this.value = value;
- }
- }
- class BST {
- public static boolean search(Node root, int key) {
if(root == null) {return false;}- while(root != null) {
- if(root.value == key) {
- return true;
- }
- else
- root=(root.value > key)?root.left:root.right;
if(root.value > key) {root = root.left;} else if(root.value < key) {root = root.right;}- }
- return false;
- }
- }
This is the fastest way I have found of calculating this. Approximately nine times faster than the standard solution.
All equal
is a property of a whole list. One of possile ways is to use folds that are more natual way to cacluate/check value/property on a foldable structures.
Also algorithm has O(n) complexity
module AllEqual where import Data.Foldable(foldl') allEqual :: [Int] -> Bool allEqual [] = True allEqual (x:xs) = foldl' (\b a -> b && (a==x)) True xs
- module AllEqual where
import Data.ListallEqual :: [Int] -> BoolallEqual xs = length (nub xs) <= 1- import Data.Foldable(foldl')
- allEqual :: [Int] -> Bool
- allEqual [] = True
- allEqual (x:xs) = foldl' (\b a -> b && (a==x)) True xs
Refactored to insert in order. This may run a bit faster due to no longer using sort() function.
def divisors(n): fact = [] for i in range(1, int(n**0.5) + 1): if not(n % i): v = n // i if v != i: fact.insert(len(fact)//2,v) fact.insert(len(fact)//2,i) return fact
- def divisors(n):
fact = [];- fact = []
- for i in range(1, int(n**0.5) + 1):
- if not(n % i):
fact.append(i)if n / i != i:fact.append(n / i)fact.sort()- v = n // i
- if v != i:
- fact.insert(len(fact)//2,v)
- fact.insert(len(fact)//2,i)
- return fact