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
String.prototype.scan = function(regex) {
    if (!regex.global) throw "regex must have 'global' flag set";
    var r = []
    this.replace(regex, function() {
        r.push(Array.prototype.slice.call(arguments, 1, -2));
    });
    return r;
}

function reverseComplement(dna) {
  return /[^ATCG]/.test(dna) ? "Invalid sequence" :
  [...dna.replace(/./g,x=>x=="A"?"T":x=="T"?"A":x=="C"?"G":"C")].reverse().join("")
}

function getFrames(seq){
  var rev        = reverseComplement(seq)
  var seq_length = seq.length
  return { 
    "1" : seq,  "2": seq.substring(1,seq_length-1),  "3": seq.substring(2,seq_length-1),
    "-1": rev, "-2": rev.substring(1,seq_length-1), "-3": rev.substring(2,seq_length-1)
  }
}

function findOrfInFrame(seq,frame,min,len) {
  var orfs    = []
  var tri_nts = seq.match(/.{1,3}/g)
  var start   = ""
  var stop    = ""
  var orf_seq = ""

  var is_neg  = frame < 0
  var neg_offset = {"1" :  1, "2" :  3, "3" : 5}
  var offset     = neg_offset[Math.abs(frame).toString()]

  tri_nts.forEach( function(tri_nt,i){
    // The very end of the sequence
    if  (i == tri_nts.size - 1) {
      stop  = ((i*3)+frame+2)
      if (is_neg) {
        start = (len - parseInt(start) - offset)
        stop  = (len - parseInt(stop)  - offset)
      }
      if ((orf_seq.length + 3) >= min) {
        orfs.push([start.toString(),">#{stop}",orf_seq])
      }
    }
    // Start of an ORF
    if (orf_seq == "" && tri_nt == "ATG") {
      orf_seq  += tri_nt
      start = (i * 3) + frame
    // Not a stop codon
    } else if (codons[tri_nt] != "*" && orf_seq != ""){
      orf_seq  += tri_nt
    // Find a stop codon
    } else if (codons[tri_nt] == "*" && orf_seq != ""){
      if ((orf_seq.length + 3) >= min){
        stop  = ((i*3)+frame+2)
        if (is_neg) {
          start = (len - parseInt(start) - offset)
          stop  = (len - parseInt(stop)  - offset)
        }
        orfs.push([start.toString(),stop.toString(),orf_seq])
        start   = ""
        stop    = ""
        orf_seq = "" 
      }
    }
  });
  return orfs
}

function findOrfs(seq,min) {
  var frames    = getFrames(seq)
  var len       = seq.length
  var all_orfs  = {}
  var count     = 1
  var frames_l  = [1]//,2,3,-1,-2,-3]
  frames_l.forEach(function(frame){
    var is_neg = frame < 0 ? true : false
    var seq    = frames[frame.toString()]
    var orfs   = findOrfInFrame(seq,frame,min,len)
    orfs.forEach(function(orf){
      var orf_info = {
        'start' : orf[0],
        'stop'  : orf[1],
        'strand': frame > 0 ? "+" : "-",
        'seq'   : orf[2].match(/.{1,3}/g).map(codon=>codons[codon]).join(""),
        'bp'    : orf[2].length + 3,
        'aa'    : orf[2].length / 3,
        'frame' : frame,
      };
      all_orfs[`ORF${count}`] = orf_info
      count += 1
    });
  });
  console.log(all_orfs)
  return all_orfs
}

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.

There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.

How many circular primes are there below one million?

function countCirculars(n) {
  let count = 0;

  for (let i=3;i<=n; i+=2) {
    if (isPrime(i) && isCirclePrime(i))
      count++;
  }

  return count+1;
}

function isPrime(n) {
  for (let i=2; i<=Math.sqrt(n); i++) {
    if (n%i === 0)
      return false;
  }
  return true;
}

function isCirclePrime(n) {
  let strN = n.toString();
  for (let i = 1; i<strN.length; i++) {
    strN = shiftString(strN);
    if (!isPrime(parseInt(strN)))
      return false
  }
  return true;
}

function shiftString(str) {
  return str.substring(1) + str.substring(0,1);
}

Return the names of everyone to greet with "Hello".

SELECT name FROM greetings
WHERE greeting='Hello';

That's my first kumite... don't really know what all this is about...

using System;
using System.Linq;

public class Kata
{
      public static int DuplicateCount(string str)
      {
            var orderedLowercase = str.ToLower().OrderBy(c => c);
            var countDuplicates = 0;
            var countOccurrenciesCurrentCharacter = 1;
            char? previousElement = null;
            var firstElement = true;

            foreach(var currentElement in orderedLowercase)
            {
                if (firstElement)
                {
                    firstElement = false;
                }
                else
                {
                    if (currentElement == previousElement.Value)
                    {
                        countOccurrenciesCurrentCharacter ++;

                        if (countOccurrenciesCurrentCharacter == 2)
                        {
                            countDuplicates ++;
                        }
                    }
                    else
                    {
                        countOccurrenciesCurrentCharacter = 1;
                    }
                }
                previousElement = currentElement;
            }
            return countDuplicates;
      }

}
const convert = (num) => {
  return parseFloat(num.toFixed(2));
};

There can only be one bulbul!

def sayHello(say):
    l = ["bulbul", "8===D"]
    return l

Could be done better?

package main

import "fmt"

func swap(dataset []int, a, b int) {
  var x int = dataset[a]
  dataset[a] = dataset[b]
  dataset[b] = x
}

func bubble_sort(dataset []int, amout_of_integers int){
  for i := 0; i <= amout_of_integers; i++ {
    for j := amout_of_integers; j >= i + 1; j-- {
      if dataset[j] < dataset[j-1] {
        swap(dataset, j, j - 1)
      }
    }
  }
}


func main(){

  dataset := []int{5, 2, 4, 6, 1, 3};

  fmt.Println(dataset)

  bubble_sort(dataset, 5);

  fmt.Println(dataset)
}

Provide a positive integer (0 < n).

Returns an array of all factors of n.

If there are no factors, returns an empty array.

Based on user boo1ean's solution here: https://www.codewars.com/kata/reviews/55aa0d71c1eba8a65a000132/groups/5787db6eba5c4b1c8c0016ae

function getFactors (n) {
  if (n < 1 || ! Number.isInteger(n)) return [];
  
  let divisors = [];
  
  // Only iterates up to n/2, since no divisor will be greater than that
  for (let i = 1; i <= n / 2; ++i) {
    if (n % i) continue;
    else divisors.push(i);
  }
  
  // Push the original number n to array
  return divisors.concat([n]);
}

A little help for claculate the distances between two points in a plane(2D case) and in the space (3D case)

from math import sqrt

def distance2D(pA, pB):
    if pA == pB: return 0
    xA, yA = tuple(pA); xB, yB = tuple(pB)
    return sqrt((xA - xB)**2 + (yA - yB)**2)
    
def distance3D(pA, pB):
    if pA == pB: return 0
    xA, yA, zA = tuple(pA); xB, yB, zB = tuple(pB)
    return sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)

A little help for claculate the distances between two points in a plane(2D cases) and in the space (3D cases)

def distance2D(pA, pB)
    return 0 if pA == pB
    xA = pA[0]; yA = pA[1]; xB= pB[0]; yB = pB[1]
    return Math.sqrt((xA - xB)**2 + (yA - yB)**2)
end
    
def distance3D(pA, pB)
    return 0 if pA == pB
    xA = pA[0]; yA = pA[1]; zA = pA[2]; xB= pB[0]; yB = pB[1]; zB = pB[2]
    return Math.sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)
end  

def range (min, max)
    rand * (max-min) + min
end