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
Ad

create a program that takes an input and converts that input and removes all the spaces,numbers and capatal letters and then it counts how many charecters are left.

you will be given a string called s.

def remove(s):
module Codewars.GetClosestPoint where

type Point = (Float, Float)

dist :: Point -> Point -> Float
dist (x1, x2) (y1, y2)
  = sqrt (dx ^ 2 + dy ^ 2)
  where (dx, dy) = (y1 - x1, y2 - x2)

closestPoint :: Point -> [Point] -> Point
closestPoint point [p] = p
closestPoint point (p : ps)
  = closestBetweenTwo point p (dist point p) (closestPoint point ps)
  where
    closestBetweenTwo :: Point -> Point -> Float -> Point -> Point
    closestBetweenTwo p0 p1 initialDist p2
      | initialDist < dist point p2 = p1
      | otherwise                   = p2
      
closestPoint' :: Point -> [Point] -> Point
closestPoint' point [] = point
closestPoint' point (p : ps)
  = closestBetweenTwo point p (dist point p) ps
  where
    closestBetweenTwo :: Point -> Point -> Float -> [Point] -> Point
    closestBetweenTwo p0 p1 initialDist [] = p1
    closestBetweenTwo p0 p1 initialDist (p2 : ps)
      | initialDist < dis = closestBetweenTwo p0 p1 initialDist ps
      | otherwise         = closestBetweenTwo p0 p2 dis ps
      where dis = dist p0 p2

The given version

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)
  where
      closest :: Point -> Point -> Point -> Point
      closest point p1 p2
        | dist point p1 < dist point p2 = p1
        | otherwise                     = p2

The given version.

Helpers are in Preloaded and need never be changed.

Tests are in Tests and need never be changed.

Tests are performed against the original version, which is copied into Tests under a new name. This being the original version, it is tested against the fixed cases, and otherwise against itself. This starts making sense in forks, where closestPoint /= refClosestPoint.

module ClosestPoint (closestPoint) where

import Preloaded (Point,dist)

-- 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)
  where
      closest :: Point -> Point -> Point -> Point
      closest point p1 p2
        | dist point p1 < dist point p2 = p1
        | otherwise                     = p2
{-# OPTIONS_GHC -O1 #-}
module LongestPath (longestPath) where
{-
import Data.Vector.Unboxed as Vector (fromList,(!),(!?))
import Data.List (maximumBy,elemIndex)
import Data.Maybe (fromMaybe)
import Data.Monoid ((<>))
import Data.Function (on)
import Data.Ord (Down(Down))

memo :: (Enum a) => (a -> b) -> (a -> b)
memo fn = (map fn [ toEnum 0 .. ] !!) . fromEnum

longestPath :: String -> String
longestPath s = maximumBy order $ ("" :) $ zipWith ( \ i c -> if c == '\n' then "" else getLongestPath i ) [0..] s where
  width = fromMaybe (length s) $ elemIndex '\n' s
  order = (compare `on` length) <> (compare `on` Down)
  v = fromList s
  getLongestPath = memo $ \ i ->
    v ! i : (maximumBy order $ ("" :)
                             $ map getLongestPath
                             $ filter ( \ j -> Just (v ! i) < v !? j )
                             $ [ i-width-2, i-width-1, i-width
                               , i-1                 , i+1
                               , i+width  , i+width+1, i+width+2
                               ]
            )

 -}

import           Control.Monad
import           Data.Function   ((&))
import           Data.Ix         (inRange)
import           Data.List.Split (chunksOf)
import           Data.Maybe
import           Data.Vector     (Vector)
import qualified Data.Vector     as V


minimumOn :: (Ord b) => (a -> b) -> [a] -> a
minimumOn f [] = error "Data.List.Extra.minimumOn: empty list"
minimumOn f (x:xs) = g x (f x) xs
    where
        g v mv [] = v
        g v mv (x:xs) | mx < mv = g x mx xs
                      | otherwise = g v mv xs
            where mx = f x

longestPath :: String -> String
longestPath = solve . lines

maximumCell :: [(Int, [Char])] -> (Int, [Char])
maximumCell = minimumOn (\(n, s) -> (-n, s))

solve :: [[Char]] -> [Char]
solve input = knot & V.toList & V.concat & V.toList & maximumCell & snd
 where
  grid   = V.fromList $ V.fromList <$> input
  height = length input
  width  = length (head input)
  knot   = V.fromList $ do
    row <- [0 .. height - 1]
    pure $ V.fromList $ seqLenAt grid knot row <$> [0 .. width - 1]

around :: [(Int, Int)]
around = (,) <$> [-1 .. 1] <*> [-1 .. 1] & filter (/= (0, 0))

seqLenAt
  :: Vector (Vector Char)
  -> Vector (Vector (Int, [Char]))
  -> Int
  -> Int
  -> (Int, [Char])
seqLenAt grid knot row col = maximumCell candidates
 where
  hereCh     = (grid V.! row) V.! col
  candidates = (1, [hereCh]) : do
    (dx, dy) <- around
    let (ty, tx) = (row + dy, col + dx)
    thereCh <- maybeToList $ (V.!? ty) >=> (V.!? tx) $ grid
    guard $ hereCh < thereCh
    let (n, s) = (knot V.! ty) V.! tx
    pure (n + 1, hereCh : s)

You have to create an which abbreviation function. It will take string and return a string while taking the first and last char and replace the remaining with the number of chars.

For example:
internationalization => i18n
Localization => L10n
Deepak-Vishwa => D4k-V4a

function abbrev(str) {
  // TODO
  
}

Write a function that returns the value of a number divided by 2
(Positive)(Truncated)

div2(7) = 3
div2(10) = 5

unsigned long long div2(unsigned long long a){
  //Use binary operators...I-O
  return a >> 1;
}

take a number as input say (n) and add all the digit of this numnber until result is not equal to a single digit no.

EX. 1245358,
output=1+2+4+5+3+5+8=28, 28=2+8=10, 10=1+0=1
so, output=1

n=int(input())
                                                                                   


for i in range(n):
    add=add+n[i]
    if add>9:
        while add<10:
            for j in range(add):
                add+=add[j]
                print(add)
    else:
        print(add)
hanukaFailed Tests

BinaryGap

Fundamentals
Logic

A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.

For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binary representation 10100 and contains one binary gap of length 1. The number 15 has binary representation 1111 and has no binary gaps. The number 32 has binary representation 100000 and has no binary gaps.

Write a function:

that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap.

For example, given N = 1041 the function should return 5, because N has binary representation 10000010001 and so its longest binary gap is of length 5. Given N = 32 the function should return 0, because N has binary representation '100000' and thus no binary gaps.

function binaryGap($n) {
  
}
def abbrev(str):
    return str[0] + str(len(str[1::-1])) + str[-1]