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

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
Fundamentals

This fonction analyze records of temperature to find the closest to zero.

If two numbers are equally close to zero, positive integer has to be considered closest to zero (for instance, if the temperatures are -5 and 5, then display 5)

Display 0 (zero) if no temperatures are provided. Otherwise, display the temperature closest to 0.

def TempCloseTo0(arr):
    if len(arr)==0:  return 0
    else : 
        j=max(arr)
        for i in arr:
            if abs(i)<j :
                j=abs(i)
        return j

What's the most efficient algorithm to find the prime divisors of a number?

function divisors(x) {
  if (x === 1) return [];
  let sqrt = Math.sqrt(x);
  let res = [];
  while (x % 2 === 0) {
    x /= 2;
    res.push(2);
  }
  for (let n = 3; n <= sqrt && x > 1; n += 2) {
    if (x % n === 0) {
      x /= n;
      sqrt = Math.sqrt(x);
      res.push(n);
      n -= 2;
    }
  }
  if (x > 1) res.push(x);
  return res;
}

Return 100! Well, you might be thinking "Thats so easy, why is was this even created?" Well I have a job for you! Return 100 in the most creative way possible!

function returnhundred() {
return 10 ** 2;
}
fn foo() -> i32 {
    0
}

You are given an array of Gem objects. Each Gem has a name attribute, and a colors attribute containing either a string, or an array of strings describing its color.

gems = [
  { name: 'Amethyst', colors: 'purple' },
  { name: 'Garnet', colors: ['orange', 'red']},
  { name: 'Aquamarine', colors: ['blue', 'green']}
];

Your task is to create a function getGemsOfColor which takes a color string and a gems array as its argument, and returns the names of the gems of that color as an array, sorted alphabetically. If no gems of the given color are found, return an empty array.

Assumptions

  • The colors property of each gem is never undefined.
  • The gems input array is never empty.

Examples:

Given input array: gems = [
  { name: 'Amethyst', colors: 'purple' },
  { name: 'Garnet', colors: ['orange', 'red']},
  { name: 'Aquamarine', colors: ['blue', 'green']},
  { name: 'Emerald', colors: 'green' },
];

getGemsOfColor('blue', gems) // ['Aquamarine']
getGemsOfColor('green', gems) // ['Aquamarine', 'Emerald']
getGemsOfColor('white', gems) // []
function getGemsOfColor(color, gems) {

}