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

Help the wicked witch!!
Given a binary tree, return the id of the branch containing a poisoned apple.
Each node has the following structure:
Node: {
id: int
poisoned: true/false
left: Node
right: Node
}

If no poisoned apple on the tree return -1.

const findPoisoned = (node) => {
  // Help evil prevail !
  return node == null || node == undefined ? -1
    : node.poisoned ? node.id 
    : Math.max(findPoisoned(node.left),findPoisoned(node.right));
}

A novel function to generate console formatted tables.

head = ["***", "Numbler =>", 40, 'another', "last"]
body = [
    [ 1 , "B", "C", 2, 3],
    ["D", "E", "F", 4, 5]
]

t = table(body, head=head)

Change the input sentence so switchout changes into word.
ex.: I am smart,smart,dumb = I am dumb

def switchout(sentence,switchout,word):
    return sentence.replace(switchout,word)

Linear search with while loop:

  • Instead of
    • Every Iteration
  1. check if i is smaller than length of array, if not increament i
  2. check if arr[i] equals to x
  • Do
    • Once
  1. check if last item is equal to x, if yes return index
  2. if not, replace last array item with x, saving the last item in another variable
  3. if i is smaller than length of array, return i
  4. else return nil
    - Every Iteration
  5. check if arr[i] equals to x, if not increament i
def Linear_search(arr,x)
  i=0
  last_idx=arr.size-1
  if arr[last_idx] == x 
    return last_idx
  else 
    last = arr[last_idx]
    arr[last_idx]=x
  end
  while arr[i]!=x
    i+=1
  end
  i < last_idx ? i : nil
end
flop,(<%>) :: (Functor f) -> f (a -> b) -> a -> f b

Specialises to flip for (->) r;
otherwise useful for take <$> choose (0,length xs) <%> xsand similar binary function constructs with functors / applicatives / monads.

Known elsewhere as Control.Lens.(??) and Relude.Functor.Fmap.flap

module FlipFlop (flop,(<%>)) where

infixl 4 `flop`,<%>

flop,(<%>) :: (Functor f) => f (a -> b) -> a -> f b
flop fab a = fmap ($ a) fab
(<%>) = flop

{-# Specialise  flop :: (a -> b -> c) -> b -> a -> c #-}
{-# Specialise (<%>) :: (a -> b -> c) -> b -> a -> c #-}
Arrays
Data Types
Control Flow
Basic Language Features
Fundamentals

Palindrome:

A palindrome is a word that when reversed reads the same. An example is "evil rats star live."

Valid palindromes should output 'TRUE' while invalid ones should output 'FALSE'.

function palindrome (x) {
  let s = x.split('').reverse().join('')
  return x == s ? "TRUE" : "FALSE"
}
Fundamentals

You are asking to write a function, which takes N lists as input, such so len(l1) >= len(l2) >= .. len(lN) and interleave them into a single list. If you get a single list in input, then just return original list as is.

Example:
You have ['a1','a1','a3'], ['b1','b2'],['c1'] to interleave. Finually, you should get ['a1','b1','c1','a2','b2','c1'].

def interleave(*argv):
    lists = len(argv)
    if 1 == lists:
        return argv[0]
    else:
        o = [x for t in zip(*argv) for x in t]
        for i in reversed(range(0, lists - 1)):
            l = len(argv[i + 1])
            lists = []
            for _list in argv[:i+1]:
                lists.append(_list[l:])
            o += [x for t in zip(*lists) for x in t]
        return o

Just seeing if I can get the canvas element to work.

The best way to see the canvasses is to hit Fork, then Run, then look at the test logs.

More information about these images:
https://en.wikipedia.org/wiki/Maurer_rose

function maurerRose(n, d, length) {
  length /= 2
  var locations = []
  for (var i = 0; i <= 360; i++) {
    var k = i * d * Math.PI / 180
    var r = Math.sin(n * k) * length
    var a = r * Math.cos(k) + length
    var b = r * Math.sin(k) + length
    locations.push([Math.round(a), Math.round(b)]) 
  }
  return locations
}

I have tried the Kata below, but the execution is too slow, what can I do to make this script faster?

"Implement the function unique_in_order which takes as argument a sequence and returns a list of items without any elements with the same value next to each other and preserving the original order of elements.

For example:

unique_in_order('AAAABBBCCDAABBB') == ['A', 'B', 'C', 'D', 'A', 'B']

unique_in_order('ABBCcAD') == ['A', 'B', 'C', 'c', 'A', 'D']

unique_in_order([1,2,2,3,3]) == [1,2,3]

def unique_in_order(iterable):
    iterable = list(iterable)
    while 1==1:
        for x in range(len(iterable)):
            if iterable[x]==iterable[x-1]:
                del iterable[x]
                break
            if x==len(iterable)-1:
                return iterable

You are given two arrays of integers, sorted in ascending order. Your task is to write a function that merges the two arrays, and output a merged array that is also sorted. But there's the catch! The Array.prototype.sort() function is not available!

For example, given the following two arrays:

[0, 3, 6, 13, 45]
[-1, 45, 330, 553]

Your function should return:

[-1, 0, 3, 6, 13, 45, 45, 330, 553]

Note that there may be duplicates. It's fine to leave them in there.

function mergeArrays(arrA, arrB) {
  const output = [];
  const arrAClone = [...arrA];
  const arrBClone = [...arrB];
  let nextSmallestA = arrAClone.shift();
  let nextSmallestB = arrBClone.shift();
  while (nextSmallestA !== undefined || nextSmallestB !== undefined) {
      if (nextSmallestA === undefined || nextSmallestB < nextSmallestA) {
        output.push(nextSmallestB);
        nextSmallestB = arrBClone.shift();
      } else {
        output.push(nextSmallestA);
        nextSmallestA = arrAClone.shift();
      }
  }
  return output;
}