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
var foo* = 0
;

Find a way to make the positive number negative!

function neg(number) {
return -(number);
}
ReturnMasterFailed Tests

E

e

e
f=_=>{_.sort();return _[0]!=_[1]?_[0]:_[_.length-1]==_[_.length-2]?'Error':_[_.length-1]};

Consider a syntax named with-break,

(with-break
  (define x 1)
  (break 2)
  x)

within its scope,you can use function break to jump out.
This example returns 2 because break stops the current computation.
You may approach this by using functions like call/cc,call/ec,shift,reset.

#lang racket
(require racket/control)
(provide with-break break)
(define break-parameter (make-parameter (λ (val)
                                          (error "you can't use break without with-break"))))
(define break
  (λ (val)
    ((break-parameter) val)))
(define-syntax-rule (with-break bodies ...)
  (call/ec (λ (exit)
             (parameterize ([break-parameter exit])
               bodies ...)
              )))
let foo x = 0

Using your programming language of choice from the drop-down, write a function that takes a string and returns the count of instances of the letter "a" in the string.

The comparison should be case-insensitive, i.e. both "a" and "A" should count.

For example, "abcABC" should return 2.

function count(string) {

}
Algorithms
Logic
Mathematics
Numbers

An algorithm best suited for the calculation of very large fibonnaci numbers, but works very well for simply populating a list or dictionary with these values.

The algorithm here uses a dictionary (which has O(1) access time) to hold values used by further calls. The implementation has a logarithmic time using an identity that allows us to calculate fib(2n) efficently from fib(n)

Uses the binary and operator because it is much faster in calculating if a number is odd or even.

If you wish to work with fibonnaci numbers past around the 4 millionth, I sincerely suggest you use a different language, as python has a hard time storing values much larger than this.

If you wish to use this with fibonnaci numbers that are modulo'd by some constant (as I used this for in problem 422 of project euler) then you may use it up to and beyond the 1st quadrillionth fibbonacci quiet easily

F = {0: 0, 1: 1, 2: 1}

def fib(n):
    """
    Return the nth Fibonacci number in O(log(n)) time
    """

    if n in F:
        return F[n]

    f1 = fib(n // 2 + 1)
    f2 = fib((n - 1) // 2)
    F[n] = (f1 * f1 + f2 * f2 if n & 1 else f1 * f1 - f2 * f2)
    return F[n]

This function takes an integer as a Parameter and returns a list of factors for that number in ascending order. It uses a set and an optimized loop for preventing repeated values.

As far as I can tell, it works as well with large numbers. For some reason the code does not run on this platform.

def Factorize(num):
    """Factorizes an Integer"""
    
    # set because values are unique
    factset = set()
    try:
        num = int(num)
    except:
        raise Exception("Please Enter an Integer")
    
    if num <= 0:
        raise Exception("Entered Number must be grater than 0")
        
    for i in range(1, int(num/2-1)):
        result = num/i
        
        if num % i == 0:
            factset.add(i)
            factset.add(int(result))
        
    return sorted(list(factset))
    
num = 10246

# f-strings for formatting in a more pythonic way
print(f"Input = {num}")
print("Factors: ", end="")

# completely pointless, for aesthetics :)
print(f"{', '.join([str(i) for i in Factorize(num)])}")

# Output should be: 1, 2, 47, 94, 109, 218, 5123, 10246