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.
module Example (fib) where fibonacci :: [Integer] fibonacci = 0 : scanl (+) 1 fibonacci fib :: Int -> Integer fib = (!!) fibonacci
module Example (fib,fibonacci) wheretype RAList a = [ ( Int, Tree a ) ]data Tree a = Empty | Node { here :: a, left, right :: Tree a } deriving ()nil :: RAList anil = []cons :: a -> RAList a -> RAList acons x ( (size0,tree0) : (size1,tree1) : trees ) | size0 == size1 = ( 1 + size0 + size1, Node x tree0 tree1 ) : treescons x trees = (1,Node x Empty Empty) : treesfromListN :: Int -> [a] -> RAList afromListN n = foldr cons nil . take n(!) :: RAList a -> Int -> a( (size,tree) : trees ) ! n | n < size = index tree size n | otherwise = trees ! (n - size) whereindex tree size n | n == 0 = here tree| n+n < size = index (left tree) (size `div` 2) (n-1)| otherwise = index (right tree) (size `div` 2) (n-1 - size `div` 2)- module Example (fib) where
- fibonacci :: [Integer]
- fibonacci = 0 : scanl (+) 1 fibonacci
- fib :: Int -> Integer
fib = (!) (fromListN 200_002 fibonacci)- fib = (!!) fibonacci
module ExampleSpec (spec) where import Example (fib) import Test.Hspec import Data.Ratio ((%),numerator) spec :: Spec spec = do it "tests" $ do fib 0 `shouldBe` 0 fib 1 `shouldBe` 1 fib 2 `shouldBe` 1 fib 3 `shouldBe` 2 fib 4 `shouldBe` 3 fib 5 `shouldBe` 5 fib 6 `shouldBe` 8 fib 7 `shouldBe` 13 fib 8 `shouldBe` 21 it "fib 25 000" $ do fib 25_000 `shouldBe` refFib 25_000 it "fib 50 000" $ do fib 50_000 `shouldBe` refFib 50_000 it "fib 100 000" $ do fib 100_000 `shouldBe` refFib 100_000 it "fib 200 000" $ do fib 200_000 `shouldBe` refFib 200_000 it "fib 200 001" $ do fib 200_001 `shouldBe` refFib 200_001 it "fib 120 002" $ do fib 120_002 `shouldBe` refFib 120_002 data Sqrt5 a = Sqrt5 { real, int :: a } instance (Num a) => Num (Sqrt5 a) where Sqrt5 a b + Sqrt5 c d = Sqrt5 (a+c) (b+d) Sqrt5 a b - Sqrt5 c d = Sqrt5 (a-c) (b-d) Sqrt5 a b * Sqrt5 c d = Sqrt5 (a*d+b*c) (5*a*c+b*d) fromInteger = Sqrt5 0 . fromInteger abs = undefined signum = undefined instance (Fractional a) => Fractional (Sqrt5 a) where recip (Sqrt5 a b) = Sqrt5 (a / (5*a*a-b*b)) (- b / (5*a*a-b*b)) fromRational = Sqrt5 0 . fromRational phi,sqrt5 :: Sqrt5 Rational phi = Sqrt5 (1%2) (1%2) sqrt5 = Sqrt5 1 0 refFib :: Integer -> Integer refFib n = numerator . int $ (phi^^n - (-phi)^^(-n)) / sqrt5
- module ExampleSpec (spec) where
import Example (fib,fibonacci)- import Example (fib)
- import Test.Hspec
- import Data.Ratio ((%),numerator)
- spec :: Spec
- spec = do
- it "tests" $ do
- fib 0 `shouldBe` 0
- fib 1 `shouldBe` 1
- fib 2 `shouldBe` 1
- fib 3 `shouldBe` 2
- fib 4 `shouldBe` 3
- fib 5 `shouldBe` 5
- fib 6 `shouldBe` 8
- fib 7 `shouldBe` 13
- fib 8 `shouldBe` 21
- it "fib 25 000" $ do
- fib 25_000 `shouldBe` refFib 25_000
- it "fib 50 000" $ do
- fib 50_000 `shouldBe` refFib 50_000
- it "fib 100 000" $ do
- fib 100_000 `shouldBe` refFib 100_000
- it "fib 200 000" $ do
- fib 200_000 `shouldBe` refFib 200_000
- it "fib 200 001" $ do
- fib 200_001 `shouldBe` refFib 200_001
- it "fib 120 002" $ do
- fib 120_002 `shouldBe` refFib 120_002
- data Sqrt5 a = Sqrt5 { real, int :: a }
- instance (Num a) => Num (Sqrt5 a) where
- Sqrt5 a b + Sqrt5 c d = Sqrt5 (a+c) (b+d)
- Sqrt5 a b - Sqrt5 c d = Sqrt5 (a-c) (b-d)
- Sqrt5 a b * Sqrt5 c d = Sqrt5 (a*d+b*c) (5*a*c+b*d)
- fromInteger = Sqrt5 0 . fromInteger
- abs = undefined
- signum = undefined
- instance (Fractional a) => Fractional (Sqrt5 a) where
- recip (Sqrt5 a b) = Sqrt5 (a / (5*a*a-b*b)) (- b / (5*a*a-b*b))
- fromRational = Sqrt5 0 . fromRational
- phi,sqrt5 :: Sqrt5 Rational
- phi = Sqrt5 (1%2) (1%2)
- sqrt5 = Sqrt5 1 0
- refFib :: Integer -> Integer
- refFib n = numerator . int $ (phi^^n - (-phi)^^(-n)) / sqrt5
Racketfewvs.___Grzegorz___yesterday
additon
/** * Creates a box with optional boxes inside */ const box = (code, boxes) => ({ code, (boxes ? { boxes } : {}) }); /** * Returns a copy of a box with bomb */ function withBomb(box) { return { box, bomb: true }; } /** * Finds the bomb in a box */ function pathToBomb(box, path = []) { const newPath = [path, box.code]; if (box.bomb) return newPath; if (!Array.isArray(box.boxes)) return []; return traverseBoxes(box.boxes, newPath); } /** * Finds the bomb in an array of boxes */ function traverseBoxes(boxes, path = []) { return boxes.reduce( (result, box) => (result.length > 0 ? result : pathToBomb(box, path)), [] ); } /** * The main function */ function findTheBomb(boxes) { if (boxes.length === 0) throw new Error('Empty array'); return traverseBoxes(boxes).join(' > '); } // Example usage /* const myBoxes = [ box('A', [ box('B', [ withBomb(box('C')) ]) ]) ]; console.log(findTheBomb(myBoxes)); // "A > B > C" */
export interface Box {code: stringbomb?: booleanboxes?: Box[]}- /**
- * Creates a box with optional boxes inside
- */
export const box = (code: string, boxes?: Box[]): Box => ({ code, ...( boxes ? { boxes } : {} )});- const box = (code, boxes) => ({ code, ...(boxes ? { boxes } : {}) });
- /**
- * Returns a copy of a box with bomb
- */
export function withBomb(box: Box) {return { ...box, bomb: true }- function withBomb(box) {
- return { ...box, bomb: true };
- }
- /**
- * Finds the bomb in a box
- */
export function pathToBomb(box: Box, path: string[] = []): string[] {const newPath = [...path, box.code]if (box.bomb) return newPathif (!Array.isArray(box.boxes)) return []return traverseBoxes(box.boxes, newPath)}- function pathToBomb(box, path = []) {
- const newPath = [...path, box.code];
- if (box.bomb) return newPath;
- if (!Array.isArray(box.boxes)) return [];
- return traverseBoxes(box.boxes, newPath);
- }
- /**
- * Finds the bomb in an array of boxes
- */
export function traverseBoxes(boxes: Box[], path: string[] = []): string[] {return boxes.reduce((result: string[], box) => (result.length > 0 ? result : pathToBomb(box, path)), [])- function traverseBoxes(boxes, path = []) {
- return boxes.reduce(
- (result, box) => (result.length > 0 ? result : pathToBomb(box, path)),
- []
- );
- }
- /**
- * The main function
- */
export function findTheBomb(boxes: Box[]): string {if (boxes.length === 0) throw new Error('Empty array')return traverseBoxes(boxes).join(' > ')- function findTheBomb(boxes) {
- if (boxes.length === 0) throw new Error('Empty array');
- return traverseBoxes(boxes).join(' > ');
- }
- // Example usage
- /*
- const myBoxes = [
- box('A', [
- box('B', [
- withBomb(box('C'))
- ])
- ])
- ];
- console.log(findTheBomb(myBoxes)); // "A > B > C"
- */
Fundamentals
long long next_bigger_number(long long n) { int digits[20]; int num = 0; long long temp = n; // Convert number to digit array while(temp > 0) { digits[num++] = temp % 10; temp /= 10; } if (num <= 1) { return -1; } // Reverse digits in array for(int i = 0; i < num / 2; ++i) { int t = digits[i]; digits[i] = digits[num - 1 - i]; digits[num - 1 - i] = t; } // Find next permutation (bigger number) int i = num - 2; while(i >= 0 && digits[i] >= digits[i + 1]) { i--; } int j = num - 1; while(digits[j] <= digits[i]) { j--; } // Swap and pivot int t = digits[i]; digits[i] = digits[j]; digits[j] = t; // Reverse the suffix for (int l = i + 1, r = num - 1; l < r; ++l, --r) { t = digits[l]; digits[l] = digits[r]; digits[r] = t; } // Convert back to number long long result = 0; for (int k = 0; k < num; ++k) { if (result > (9223372036854775807 - digits[k]) / 10) { return -1; // overflow } result = result * 10 + digits[k]; } return result; }
long long next_bigger_number(long long n) {return 0; //insert code here- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- long long next_bigger_number(long long n)
- {
- int digits[20];
- int num = 0;
- long long temp = n;
- // Convert number to digit array
- while(temp > 0)
- {
- digits[num++] = temp % 10;
- temp /= 10;
- }
- if (num <= 1)
- {
- return -1;
- }
- // Reverse digits in array
- for(int i = 0; i < num / 2; ++i)
- {
- int t = digits[i];
- digits[i] = digits[num - 1 - i];
- digits[num - 1 - i] = t;
- }
- // Find next permutation (bigger number)
- int i = num - 2;
- while(i >= 0 && digits[i] >= digits[i + 1])
- {
- i--;
- }
- int j = num - 1;
- while(digits[j] <= digits[i])
- {
- j--;
- }
- // Swap and pivot
- int t = digits[i];
- digits[i] = digits[j];
- digits[j] = t;
- // Reverse the suffix
- for (int l = i + 1, r = num - 1; l < r; ++l, --r)
- {
- t = digits[l];
- digits[l] = digits[r];
- digits[r] = t;
- }
- // Convert back to number
- long long result = 0;
- for (int k = 0; k < num; ++k)
- {
- if (result > (9223372036854775807 - digits[k]) / 10)
- {
- return -1; // overflow
- }
- result = result * 10 + digits[k];
- }
- return result;
- }