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.
import java. math. BigInteger; import java. util. stream. *; public class ArrayFactorial{ public static int factorial( int n, int k){ return IntStream.range( 2, n- k+ 1) . mapToObj( BigInteger:: valueOf) . reduce ( IntStream.range( k+ 1, n+ 1) . mapToObj( BigInteger:: valueOf) . reduce( BigInteger. ONE, ( a, b)-> a. multiply( b)) , ( a, b) -> a. divide( b)) . intValue( ); } }
import java.math.BigInteger;import java.util.stream.*;- import java. math. BigInteger;
- import java. util. stream. *;
- public class ArrayFactorial{
public static int factorial(int n, int k) {return IntStream.range(2, n - k + 1). mapToObj(BigInteger::valueOf)- public static int factorial( int n, int k){
- return IntStream.range( 2, n- k+ 1)
- . mapToObj( BigInteger:: valueOf)
- . reduce
( IntStream.range(2, k + 1). mapToObj(BigInteger::valueOf). reduce( IntStream.range(2, n + 1). mapToObj(BigInteger::valueOf). reduce(BigInteger.ONE, (a, b) -> a.multiply(b)), (a, b) -> a.divide(b)), (a, b) -> a.divide(b)). intValue();- ( IntStream.range( k+ 1, n+ 1)
- . mapToObj( BigInteger:: valueOf)
- . reduce( BigInteger. ONE, ( a, b)-> a. multiply( b))
- , ( a, b) -> a. divide( b))
- . intValue( );
- }
- }
I don't really understand the starting code, so I just deleted everything and started from an empty file.
function proxyDecoder(root, paths) { let graph = {}; for (let element of paths) { graph[element.to] = element.from; } while (graph[root] !== undefined) { root = graph[root]; } return root; }
function getRandomServer () {let countries = ["Afghanistan","Albania","Algeria","Andorra","Angola","AntiguaBarbuda","Argentina","Armenia","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bhutan","Bolivia","BosniaHerzegovina","Botswana","Brazil","Brunei","Bulgaria","BurkinaFaso","Burundi","CaboVerde","Cambodia","Cameroon","Canada","Chad","Chile","China","Colombia","Comoros","Congo","CostaRica","CoteD’Ivoire","Croatia","Cuba","Cyprus","Czech","Denmark","Djibouti","Dominica","Ecuador","Egypt","ElSalvador","Eritrea","Estonia","Ethiopia","Fiji","Finland","France","Gabon","Gambia","Georgia","Germany","Ghana","Greece","Grenada","Guatemala","Guinea","Guinea-Bissau","Guyana","Haiti","Honduras","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Israel","Italy","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","KoreaNorth","KoreaSouth","Kosovo","Kuwait","Kyrgyzstan","Laos","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macedonia","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Mauritania","Mauritius","Mexico","Micronesia","Monaco","Mongolia","Montenegro","Morocco","Mozambique","Namibia","Nauru","Nepal","Netherlands","NewZealand","Nicaragua","Niger","Nigeria","Norway","Oman","Pakistan","Palau","Panama","PapuaNewGuinea","Paraguay","Peru","Philippines","Poland","Portugal","Qatar","Romania","Russia","Rwanda","Samoa","SaudiArabia","Senegal","Serbia","Seychelles","SierraLeone","Singapore","Slovakia","Slovenia","Somalia","SouthAfrica","Spain","SriLanka","Sudan","Sudan","South","Suriname","Swaziland","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Togo","Tonga","Tunisia","Turkey","Turkmenistan","Tuvalu","Uganda","Ukraine","Emirates","UK","USA","Uruguay","Uzbekistan","Vanuatu","Vatican","Venezuela","Vietnam","Yemen","Zimbabwe"];let count = Math.floor(Math.random()*countries.length-1);let random2 = Math.floor(Math.random()*10000);return `${countries[count]}${random2}`;}function getServersArray (num) {let array = [];for (let i=0; i<num; i++){array.push(getRandomServer());- function proxyDecoder(root, paths) {
- let graph = {};
- for (let element of paths) {
- graph[element.to] = element.from;
- }
return array;}function getProxyArray () {let random = Math.floor(Math.random()*20);if (random<2) getProxyArray ();let serversArray = getServersArray(random);let array = [];for (let i=0; i<random-1; i++){array.push({from: serversArray[i], to: serversArray[i+1]});- while (graph[root] !== undefined) {
- root = graph[root];
- }
let endpoint = serversArray[serversArray.length-1];let finalArray = array.sort(()=>Math.random()*100); //need to change this sorting, it's badconsole.log(endpoint, finalArray) //instead this function should return the examplereturn finalArray;}getProxyArray ()- return root;
- }
// Since Node 10, we're using Mocha. // You can use `chai` for assertions. const chai = require("chai"); const assert = chai.assert; // Uncomment the following line to disable truncating failure messages for deep equals, do: // chai.config.truncateThreshold = 0; // Since Node 12, we no longer include assertions from our deprecated custom test framework by default. // Uncomment the following to use the old assertions: // const Test = require("@codewars/test-compat"); describe("Solution", function() { it("should test for something", function() { // Test.assertEquals(1 + 1, 2); assert.strictEqual(proxyDecoder('Vanuatu174', [{from: 'Tonga6120', to: 'SouthAfrica1124' }, { from: 'SouthAfrica1124', to: 'Paraguay8257' }, { from: 'Paraguay8257', to: 'Vanuatu174' }]), 'Tonga6120'); }); });
- // Since Node 10, we're using Mocha.
- // You can use `chai` for assertions.
- const chai = require("chai");
- const assert = chai.assert;
- // Uncomment the following line to disable truncating failure messages for deep equals, do:
- // chai.config.truncateThreshold = 0;
- // Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
- // Uncomment the following to use the old assertions:
- // const Test = require("@codewars/test-compat");
- describe("Solution", function() {
- it("should test for something", function() {
- // Test.assertEquals(1 + 1, 2);
- assert.strictEqual(proxyDecoder('Vanuatu174', [{from: 'Tonga6120', to: 'SouthAfrica1124' }, { from: 'SouthAfrica1124', to: 'Paraguay8257' }, { from: 'Paraguay8257', to: 'Vanuatu174' }]), 'Tonga6120');
- });
- });
First time using a lisp. Changed the implementation a little and added support for specifying compare function.
(ns quicksort.core) (defn quick-sort ([nums] (quick-sort nums <)) ([nums cmp] (quick-sort nums cmp nil)) ([nums cmp solved] (if (empty? nums) solved (if (= (count nums) 1) (cons (first nums) solved) (quick-sort (filter #(cmp % (first nums)) (rest nums)) cmp (cons (first nums) (quick-sort (filter #(not (cmp % (first nums))) (rest nums)) cmp solved)))))))
- (ns quicksort.core)
(defn quick-sort [nums](if (< (count nums) 2) nums(concat(quick-sort (filter #(< % (first nums)) nums))(filter #(= % (first nums)) nums)(quick-sort (filter #(> % (first nums)) nums)))))- (defn quick-sort
- ([nums] (quick-sort nums <))
- ([nums cmp] (quick-sort nums cmp nil))
- ([nums cmp solved]
- (if (empty? nums) solved
- (if (= (count nums) 1) (cons (first nums) solved)
- (quick-sort
- (filter #(cmp % (first nums)) (rest nums))
- cmp
- (cons
- (first nums)
- (quick-sort
- (filter #(not (cmp % (first nums))) (rest nums))
- cmp
- solved)))))))
(ns quicksort.test (:require [clojure.test :refer :all] [quicksort.core :refer [quick-sort]])) (deftest quick-sort-test (is (= (quick-sort '(2 3 1)) '(1 2 3))) (is (= (quick-sort '(9 -1 -2 10)) '(-2 -1 9 10))) (is (= (quick-sort '(1 2 666 233 0 8 34 -1)) '(-1 0 1 2 8 34 233 666))) (is (= (quick-sort '(1 2 666 233 0 8 34 -1) >) '(666 233 34 8 2 1 0 -1))))
- (ns quicksort.test
- (:require [clojure.test :refer :all]
- [quicksort.core :refer [quick-sort]]))
- (deftest quick-sort-test
- (is (= (quick-sort '(2 3 1)) '(1 2 3)))
- (is (= (quick-sort '(9 -1 -2 10)) '(-2 -1 9 10)))
(is (= (quick-sort '(1 2 666 233 0 8 34 -1)) '(-1 0 1 2 8 34 233 666))))- (is (= (quick-sort '(1 2 666 233 0 8 34 -1)) '(-1 0 1 2 8 34 233 666)))
- (is (= (quick-sort '(1 2 666 233 0 8 34 -1) >) '(666 233 34 8 2 1 0 -1))))
The sequel nobody asked for.
bool Or(bool a,bool b){return 2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b)) >>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b)));}bool And(bool a,bool b){ return 2>>(2>>a>>b>>(1>>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))>>(2>>b >>b>>(1>>b>>b)))))));}
bool Or(bool a,bool b){return(~-((~-(a)*~-(b)))*~-((~-(a)*~-(b))));}bool And(bool a,bool b){return(~-((~-(a)*~-(a)))*~-((~-(b)*~-(b))));}bool Xor(bool a,bool b){return(~-((~-((~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)*~-(b)))))*~-((~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)*~-(b)))))))*~-((~-((~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)*~-(b)))))*~-((~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)*~-(b))))))));}- bool Or(bool a,bool b){return 2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))
- >>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b)));}bool And(bool a,bool b){
- return 2>>(2>>a>>b>>(1>>a>>b))>>(2>>a>>b>>(1>>a>>b))>>(1>>(2>>a>>b>>(1>>a>>
- b))>>(2>>a>>b>>(1>>a>>b)));}bool Xor(bool a,bool b){return 2>>(2>>(2>>a>>b
- >>(1>>a>>b))>>(2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2>>a>>a
- >>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))))>>(1>>(2>>a>>b>>(1>>a>>b))>>(2>>(2>>a>>
- a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1
- >>b>>b))))))>>(2>>(2>>a>>b>>(1>>a>>b))>>(2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b
- >>(1>>b>>b))>>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))))>>(1>>(2>>a>>
- b>>(1>>a>>b))>>(2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2>>a>>a
- >>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))))))>>(1>>(2>>(2>>a>>b>>(1>>a>>b))>>(2>>(
- 2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b
- >>b>>(1>>b>>b))))>>(1>>(2>>a>>b>>(1>>a>>b))>>(2>>(2>>a>>a>>(1>>a>>a))>>(2>>
- b>>b>>(1>>b>>b))>>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))))))>>(2>>(
- 2>>a>>b>>(1>>a>>b))>>(2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2
- >>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))))>>(1>>(2>>a>>b>>(1>>a>>b))>>(2>>(
- 2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b
- >>b>>(1>>b>>b)))))));}
import sqlite3 def sort_arr(arr): cursor = sqlite3.connect(":memory:").cursor() cursor.execute("CREATE TABLE data (value INTEGER);") cursor.executemany( "INSERT INTO data VALUES (?)", map(lambda x: (x,), arr) ) cursor.execute( "SELECT value FROM data ORDER BY value;") solution = cursor.fetchall() cursor.execute("DROP TABLE data;") return [*map(lambda xs: xs[0], solution)]
import queue- import sqlite3
- def sort_arr(arr):
pq = queue.PriorityQueue(maxsize=len(arr))for x in arr:pq.put(x)return [pq.get() for _0 in range(len(arr))]- cursor = sqlite3.connect(":memory:").cursor()
- cursor.execute("CREATE TABLE data (value INTEGER);")
- cursor.executemany(
- "INSERT INTO data VALUES (?)",
- map(lambda x: (x,), arr)
- )
- cursor.execute( "SELECT value FROM data ORDER BY value;")
- solution = cursor.fetchall()
- cursor.execute("DROP TABLE data;")
- return [*map(lambda xs: xs[0], solution)]