Begin a new Kumite
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.
let tryParseInt s =
try
let i = System.Int32.Parse s
Some i
with _ -> None
let v1 = tryParseInt "1"
printfn "%O" v1
printfn "%O" v1.Value
printfn "%O" v1.IsSome
printfn "%O" v1.IsNone
printfn ""
let v2 = tryParseInt "?"
printfn "%O" v2
printfn "%O" v2.IsSome
printfn "%O" v2.IsNone
int f() { }
Describe(t) {
It(t1) {
Assert::That(true, Equals(true));
}
It(t2) {
Assert::That(f(), Equals(0));
Assert::That(false, Equals(true));
}
};
[for i in 1 .. 30 -> if i % 3 = 0 && i % 5 = 0 then "FizzBuzz" elif i % 3 = 0 then "Fizz" elif i % 5 = 0 then "Buzz" else i.ToString()] |> List.map(fun v -> printfn "%s" v)
let add n x = x + n
let times n x = x * n
let f1 = add 1 >> times 2
let f2 = add 1 << times 2
printfn "%i" (f1 2) // (2+1)*2
printfn "%i" (f2 2) // 2*2+1
let add x y = x + y
let add1 = add 1
let add2 = add 2
let add3 = add 3
let add1and2and3 = add1 >> add2 >> add3
printfn "%i" (0 |> add1and2and3)
let add x y = x + y
let add1 = add 1
let add2 = add 2
let add3 = add 3
printfn "%i" (add1 1)
printfn "%i" (add2 1)
printfn "%i" (add3 1)
public class Primes { public static boolean isAPrime(int number) { if (number == 1) { return false; } if (number == 2) { return true; } if (number % 2 == 0) { return false; } for (int i = 3; i*i <= number; i += 2) { if (number % i == 0) return false; } return true; } }
1 1 public class Primes {
2 − public static boolean isAPrime(int number) {
3 − for (int i=2;i*i<=number;i++)
4 − {
2 + public static boolean isAPrime(int number) {
3 + if (number == 1) {
4 + return false;
5 + }
6 + 7 + if (number == 2) {
8 + return true;
9 + }
10 + 11 + if (number % 2 == 0) {
12 + return false;
13 + }
14 + 15 + for (int i = 3; i*i <= number; i += 2) {
5 5 if (number % i == 0)
6 6 return false;
7 7 }
8 8 9 9 return true;
10 10 }
11 11 }
import org.junit.Test; import static org.junit.Assert.assertEquals; import org.junit.runners.JUnit4; import java.util.Random; public class SolutionTest { private static final Random RANDOM = new Random(); @Test public void twoShouldBeAPrime() { testPrime(2, true); } @Test public void fourShouldNotBeAPrime() { testPrime(4, false); } @Test public void aSquareShouldNotAPrime() { for (int i = 0; i < 10000; ++i) { int randomNumber = RANDOM.nextInt(Short.MAX_VALUE) + 2; int numberToCheck = randomNumber * randomNumber; testPrime(numberToCheck, false); } } @Test public void aProductOfTwoIntegersShouldNotBeAPrime() { for (int i = 0; i < 100000; ++i) { int a = RANDOM.nextInt(Short.MAX_VALUE) + 2; int b = RANDOM.nextInt(Short.MAX_VALUE) + 2; int numberToCheck = a * b; testPrime(numberToCheck, false); } } private static void testPrime(int numberToCheck, boolean expected) { boolean actual = Primes.isAPrime(numberToCheck); assertEquals(Integer.toString(numberToCheck), expected, actual); } }
1 1 import org.junit.Test;
2 2 import static org.junit.Assert.assertEquals;
3 3 import org.junit.runners.JUnit4;
4 + import java.util.Random;
4 4 5 5 public class SolutionTest {
7 + private static final Random RANDOM = new Random();
8 + 6 6 @Test
7 7 public void twoShouldBeAPrime() {
8 − int numberToCheck = 2;
9 − 10 − boolean expected = true;
11 + testPrime(2, true);
12 + }
13 + 14 + @Test
15 + public void fourShouldNotBeAPrime() {
16 + testPrime(4, false);
17 + }
18 + 19 + @Test
20 + public void aSquareShouldNotAPrime() {
21 + for (int i = 0; i < 10000; ++i) {
22 + int randomNumber = RANDOM.nextInt(Short.MAX_VALUE) + 2;
23 + int numberToCheck = randomNumber * randomNumber;
24 + testPrime(numberToCheck, false);
25 + }
26 + }
27 + 28 + @Test
29 + public void aProductOfTwoIntegersShouldNotBeAPrime() {
30 + for (int i = 0; i < 100000; ++i) {
31 + int a = RANDOM.nextInt(Short.MAX_VALUE) + 2;
32 + int b = RANDOM.nextInt(Short.MAX_VALUE) + 2;
33 + int numberToCheck = a * b;
34 + testPrime(numberToCheck, false);
35 + }
36 + }
37 + 38 + private static void testPrime(int numberToCheck, boolean expected) {
11 11 boolean actual = Primes.isAPrime(numberToCheck);
12 − 13 − assertEquals(expected, actual);
40 + assertEquals(Integer.toString(numberToCheck), expected, actual);
14 14 }
15 15 }
Recent Moves:
public class Primes { public static boolean isAPrime(int number) { for (int i=2;i*i<=number;i++) { if (number % i == 0) return false; } return true; } }
1 1 public class Primes {
2 2 public static boolean isAPrime(int number) {
3 + for (int i=2;i*i<=number;i++)
4 + {
5 + if (number % i == 0)
6 + return false;
7 + }
8 + 3 3 return true;
4 4 }
5 5 }
public class Primes { public static boolean isAPrime(int number) { if (number == 2) return true; if (number % 2 == 0) return false; if (Math.sqrt(number) % 1 == 0) return false; return true; } }
1 1 public class Primes {
2 2 public static boolean isAPrime(int number) {
3 − return number == 2 || number % 2 != 0;
3 + if (number == 2) return true;
4 + if (number % 2 == 0) return false;
5 + if (Math.sqrt(number) % 1 == 0) return false;
6 + return true;
4 4 }
5 5 }
import org.junit.Test; import static org.junit.Assert.assertEquals; import org.junit.runners.JUnit4; import java.util.*; public class SolutionTest { private static final Random RANDOM = new Random(); @Test public void twoShouldBeAPrime() { testPrime(2, true); } @Test public void fourShouldNotBeAPrime() { testPrime(4, false); } @Test public void aSquareShouldNotAPrime() { for (int i = 0; i < 10; ++i) { int randomNumber = RANDOM.nextInt(Short.MAX_VALUE); int numberToCheck = randomNumber * randomNumber; testPrime(numberToCheck, false); } } @Test public void aProductOfTwoIntegersShouldNotBeAPrime() { for (int i = 0; i < 10; ++i) { int a = RANDOM.nextInt(Short.MAX_VALUE); int b = RANDOM.nextInt(Short.MAX_VALUE); int numberToCheck = a * b; testPrime(numberToCheck, false); } } private static void testPrime(int numberToCheck, boolean expected) { boolean actual = Primes.isAPrime(numberToCheck); assertEquals(Integer.toString(numberToCheck), expected, actual); } }
1 1 import org.junit.Test;
2 2 import static org.junit.Assert.assertEquals;
3 3 import org.junit.runners.JUnit4;
4 + import java.util.*;
4 4 5 5 public class SolutionTest {
7 + private static final Random RANDOM = new Random();
8 + 6 6 @Test
7 7 public void twoShouldBeAPrime() {
8 − int numberToCheck = 2;
9 − 10 − boolean expected = true;
11 − boolean actual = Primes.isAPrime(numberToCheck);
12 − 13 − assertEquals(expected, actual);
11 + testPrime(2, true);
14 14 }
15 15 16 16 @Test
17 17 public void fourShouldNotBeAPrime() {
18 − int numberToCheck = 4;
19 − 20 − boolean expected = false;
16 + testPrime(4, false);
17 + }
18 + 19 + @Test
20 + public void aSquareShouldNotAPrime() {
21 + for (int i = 0; i < 10; ++i) {
22 + int randomNumber = RANDOM.nextInt(Short.MAX_VALUE);
23 + int numberToCheck = randomNumber * randomNumber;
24 + testPrime(numberToCheck, false);
25 + }
26 + }
27 + 28 + @Test
29 + public void aProductOfTwoIntegersShouldNotBeAPrime() {
30 + for (int i = 0; i < 10; ++i) {
31 + int a = RANDOM.nextInt(Short.MAX_VALUE);
32 + int b = RANDOM.nextInt(Short.MAX_VALUE);
33 + int numberToCheck = a * b;
34 + testPrime(numberToCheck, false);
35 + }
36 + }
37 + 38 + private static void testPrime(int numberToCheck, boolean expected) {
21 21 boolean actual = Primes.isAPrime(numberToCheck);
22 − 23 − assertEquals(expected, actual);
40 + assertEquals(Integer.toString(numberToCheck), expected, actual);
24 24 }
25 25 }