Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

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.

Ad

Note that dist is called twice per comparison, and there are length ps - 1 comparisons

Code
Diff
  • {-# Language ViewPatterns #-}
    
    module ClosestPoint (closestPoint) where
    
    import Debug.Trace
    
    import Preloaded (Point,dist)
    import Data.List (minimumBy)
    
    -- extracts from a list of points the closest to a given point
    closestPoint :: Point -> [Point] -> Point
    closestPoint _ [] = undefined
    closestPoint point (traceShowId . trace "<hr>" -> ps) = minimumBy (\x y -> compare (dist point x) (dist point y)) ps
    • {-# Language ViewPatterns #-}
    • module ClosestPoint (closestPoint) where
    • import Debug.Trace
    • import Preloaded (Point,dist)
    • import Data.List (minimumBy)
    • -- extracts from a list of points the closest to a given point
    • closestPoint :: Point -> [Point] -> Point
    • closestPoint _ [] = undefined
    • closestPoint point ps = minimumBy (\x y -> compare (dist point x) (dist point y)) ps
    • closestPoint point (traceShowId . trace "<hr>" -> ps) = minimumBy (\x y -> compare (dist point x) (dist point y)) ps
Code
Diff
  • module Closest (closestPoint) where
    
    type Point = (Float, Float)
    
    -- calculates the ditance between two points
    dist :: Point -> Point -> Float
    dist (x1, x2) (y1, y2)
      = sqrt (dx * dx + dy * dy)
      where (dx, dy) = (y1 - x1, y2 - x2)
    
    closestPoint :: Point -> [Point] -> Point
    closestPoint point [] = point
    closestPoint point (p : ps) = closest point (dist point p) p ps
      where
          closest :: Point ->  Float -> Point -> [Point] -> Point
          closest p0 initialDist p1 [] = p1
          closest p0 initialDist p1 (p2 : ps)
            | initialDist < dis = closest p0 initialDist p1 ps
            | otherwise         = closest p0 dis p2 ps
            where 
                dis = dist p0 p2
    • module Closest (closestPoint) where
    • type Point = (Float, Float)
    • -- calculates the ditance between two points
    • dist :: Point -> Point -> Float
    • dist (x1, x2) (y1, y2)
    • = sqrt (dx * dx + dy * dy)
    • where (dx, dy) = (y1 - x1, y2 - x2)
    • --- extracts from a list of points the closest to a given point
    • closestPoint :: Point -> [Point] -> Point
    • closestPoint point [p] = p
    • closestPoint point (p : ps)
    • = closest point p (closestPoint point ps)
    • closestPoint point [] = point
    • closestPoint point (p : ps) = closest point (dist point p) p ps
    • where
    • closest :: Point -> Point -> Point -> Point
    • closest point p1 p2
    • | dist point p1 < dist point p2 = p1
    • | otherwise = p2
    • closest :: Point -> Float -> Point -> [Point] -> Point
    • closest p0 initialDist p1 [] = p1
    • closest p0 initialDist p1 (p2 : ps)
    • | initialDist < dis = closest p0 initialDist p1 ps
    • | otherwise = closest p0 dis p2 ps
    • where
    • dis = dist p0 p2
  • Improve performance
  • Refactor tests
  • Refactor method signature
  • Add documentation
Code
Diff
  • using System.Linq;
    
    public static class Palindrome
    {
      public static bool IsPalindrome(this string word)
      {
        // Normalize the input
        var upper = word.ToUpperInvariant();
        
        // For every chatacter in the first half..
        for (var i = 0; i < upper.Length / 2; ++i)
          // if the char doesn't match the one in the second half..
          if (upper[i] != upper[upper.Length - i - 1])
            // the word is not a palindrome
            return false;
    
        // The word is not a palindrome
        return true;
      }
    }
    • using System.Linq;
    • class Palindrome
    • public static class Palindrome
    • {
    • public static bool Check(string word) {
    • public static bool IsPalindrome(this string word)
    • {
    • // Normalize the input
    • var upper = word.ToUpperInvariant();
    • return upper.SequenceEqual(upper.Reverse());
    • // For every chatacter in the first half..
    • for (var i = 0; i < upper.Length / 2; ++i)
    • // if the char doesn't match the one in the second half..
    • if (upper[i] != upper[upper.Length - i - 1])
    • // the word is not a palindrome
    • return false;
    • // The word is not a palindrome
    • return true;
    • }
    • }

CAPITAL_LETTERS = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z')
NUMBERS = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
SPACE = (' ')

def remove(ಠ‿ಠ):
for category in (CAPITAL_LETTERS, NUMBERS, SPACE):
for item in category:
while item in ಠ‿ಠ:
ಠ‿ಠ = remove(ಠ‿ಠ.replace(item, ''))
return ಠ‿ಠ

Code
Diff
  • import string
    def remove(string):
        arr = list(string)
        test = ""
        for i in range (len(arr)):
            if arr[i].isupper() == True or arr[i] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] or arr[i] == " ":
                arr[i] = "`"
            else:
                continue
        for i in arr:
            test += i
    
        return(test.replace("`", ""))
    
        
    • CAPITAL_LETTERS = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
    • 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z')
    • NUMBERS = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
    • SPACE = (' ')
    • import string
    • def remove(string):
    • arr = list(string)
    • test = ""
    • for i in range (len(arr)):
    • if arr[i].isupper() == True or arr[i] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] or arr[i] == " ":
    • arr[i] = "`"
    • else:
    • continue
    • for i in arr:
    • test += i
    • def remove(ಠ‿ಠ):
    • for category in (CAPITAL_LETTERS, NUMBERS, SPACE):
    • for item in category:
    • while item in ಠ‿ಠ:
    • ಠ‿ಠ = remove(ಠ‿ಠ.replace(item, ''))
    • return ಠ‿ಠ
    • return(test.replace("`", ""))
Code
Diff
  • var add1 = 0;
    var add2 = 0;
    
    var minus1 = 0;
    var minus2 = 0;
    
    var times1 = 0;
    var times2 = 0;
    
    var exponet1 = 0;
    var exponet2 = 0;
    
    var divide1 = 0;  //Division with decimal
    var divide2 = 0;
    
    var divide3 = 0; //Division with remainder
    var divide4 = 0;
    
    var y = 15;
    console.log( add1  + add2 +" (Addition)");
    var y = 35;
    console.log( minus1 - minus2 +" (Subtraction)" ); 
    var y = 55;
    console.log( times1 * times2  +" (Multilplication)" ); 
    var y = 75;
    console.log( divide1 / divide2 +" (Division with decimal)" ); 
    var y = 95;
    console.log( Math.floor (divide3 / divide4) + " R" + divide3 % divide4 +" (Division with remainder)"); 
    var y = 115;
    console.log( Math.pow(exponet2, exponet1) + " (Exponent) ");
    
    
    • // The operation with the number "1" goes first
    • var add1 = 0
    • var add2 = 0
    • var add1 = 0;
    • var add2 = 0;
    • var minus1 = 0
    • var minus2 = 0
    • var minus1 = 0;
    • var minus2 = 0;
    • var divide1 = 0
    • var divide2 = 0
    • var times1 = 0;
    • var times2 = 0;
    • var times1 = 0
    • var times2 = 0
    • //change the numbers in the varibles above
    • var exponet1 = 0;
    • var exponet2 = 0;
    • var divide1 = 0; //Division with decimal
    • var divide2 = 0;
    • var divide3 = 0; //Division with remainder
    • var divide4 = 0;
    • var y = 15;
    • console.log( add1 + add2 +" (Addition)");
    • var y = 35;
    • console.log( minus1 - minus2 +" (Subtraction)" );
    • var y = 55;
    • console.log( times1 * times2 +" (Multilplication)" );
    • var y = 75;
    • console.log( divide1 / divide2 +" (Division with decimal)" );
    • var y = 95;
    • console.log( Math.floor (divide3 / divide4) + " R" + divide3 % divide4 +" (Division with remainder)");
    • var y = 115;
    • console.log( Math.pow(exponet2, exponet1) + " (Exponent) ");
    • console.log("Addition" , add1 + add2) //Addition
    • console.log("Subtraction", minus1-minus2) //Subtraction
    • console.log("Division" , divide1/divide2) //Division
    • console.log("Multiplication" , times1*times2) //Multiplication
Code
Diff
  • def prod(numbers):
        return numbers[0] * (prod(numbers[1:]) or 1) if len(numbers) else 0
    • def prod(numbers):
    • if not len(numbers):
    • return 0
    • return numbers[0] * (prod(numbers[1:]) or 1)
    • return numbers[0] * (prod(numbers[1:]) or 1) if len(numbers) else 0