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

My first performance tester for functions, it was inspired because of the lack of this function in http://pythontutor.com/

from time import time

def helper(func,*arg):
    start = time()
    func(*arg)
    total = round(time()-start,5)*100
    return total

def testPerformance(arg,*funcs):
    """
    First parameter is a tuple with all the arguments for each function
    Each function should take the same amount of parameters in the 
    same order
    The output is a dict with function:timeFromMinimum pair
    """
    times = []
    for func in funcs:
        times.append(helper(func,*arg))
    minimum = min(times)
    sustractivetimes = [i - minimum for i in times]
    result = {i:j for i,j in zip(funcs ,sustractivetimes)}
    return result

def lambdaproach(x):
    minimum = min(x)
    return list(map(lambda x: x - minimum, x))
    
def listcomp1(x):
    minimum = min(x)
    return [i - minimum for i in x]
    
def listcomp2(x):
    minimum = min(x)
    return [sustract(i,minimum) for i in x]
    
def sustract(x,y):
    return x - y

nums = ([i for i in range(5,10)],)
testPerformance(nums,lambdaproach,listcomp1,listcomp2)

I made a function that reverses the words in a string:

def shuffle(st):
    st = st.split(' ')
    for x in range(0, len(st)):
        st[x] = list(st[x])
        st[x].reverse()
        st[x] = ''.join(st[x])
    st = ' '.join(st)
    return st

Here's the code that I'm using to list all files in a given directory. The question is, is there any other way to do this?

import glob
print(glob.glob('directorypath'))# Replace 'directorypath' with path to directory

from the rowanblush solution
using Ordering monoid instance we can change the bias on EQ for all higher order accepting (a -> a -> Ordering)

module LeftBias where

import Data.Monoid

leftBias g = g  . (fmap . fmap) (`mappend` GT)
Saka7Failed Tests

Hello Kotlin

Fundamentals

Hello world in Kotlin.

fun main(args: Array<String>) {
    println("Hello from Kotlin")
}
Saka7Failed Tests

Data classes

In Kotlin data classes is classes which do nothing but only hold data.

The compiler automatically derives the following members from all properties declared in the primary constructor:

  • equals()/hashCode() pair,
  • toString() of the form "User(name=John, age=42)",
  • componentN() functions corresponding to the properties in their order of declaration,
  • copy() function (see below).
data class User(val id: Long, var email: String, var name: String)

fun main(args: Array<String>) {
    var user = User(1, "random@email.com", "randomName")
    
    // toString
    println(user)
    
    // equals
    println(user.equals(User(1, "random@email.com", "randomName")))
    
    // ComponentN
    println("user name is ${user.component3()}")
    
    // copy
    var newUser = user.copy(name="newName")
    println(newUser)
}
Arrays
Data Types

Write a program that removes the element at the nth index in the provided array, and returns the new array.

If the number provided is not an index in the array, return the original array.

For Example:

remove([1, 2, 3], 2) => [1, 2]

remove(["dog", "cat", "bat", "parrot", "monkey"], 4) => ["dog", "cat", "bat", "parrot"]

function remove (arr, n) {
  if (n < 0 || n >= arr.length) return arr;
  arr.splice(n, 1);
  return arr;
}

Finds top 7 most frequent words in the book.

(ns most-frequent-words.core)

(defn most-frequent-words[number-of-words, book-url]
  "Finds top 7 most frequent words in the book"
  (->> 
    (slurp book-url)
    (re-seq #"\w+")
    (frequencies)
    (sort-by val >)
    (take number-of-words)))
Polymer({
    is: "pedal-assist",
    properties:{
      ppc:{
        type:Number,
        value:30,
      },
      gap:{
        type:Number,
        computed:"getGap(lPedel,rPedel)",
      },
      cycle:{
        type:Number,
        value:.5,
      },
    },
    left: function(undefined){
      this.lPedel = performance.now()

    },
    right: function(undefined){
      this.rPedel = performance.now()
    },
    getGap: function(lPedel,rPedel){
      var newGap = Math.sqrt((lPedel - rPedel) * (lPedel - rPedel))

      var r1 = this.gapOld / this.gap
      var r2 = this.gap / newGap
      console.log(r1,r2,newGap)
      if (r1 < 1.2 && r1 > .8 && r2 < 1.2 && r2 > .8) {
       this.runMotor(this.cycle,this.ppc,this.gap)
      }
      this.gapOld = this.gap
      return newGap
    },
    runMotor: function(cycle,ppc,time){
      var n= Math.floor(ppc*cycle)
      for (var i=1;i<n;i++) {
        setTimeout(function(that){
          if (that.black == 0) {
            that.set("black", 12)
            that.yellow = 0
            that.red = -12
          } else if (that.yellow == 0) {
            that.black = -12 
            that.yellow = 12
            that.red = 0
          } else if (that.red == 0) {
            that.black = 0 
            that.yellow = -12
            that.red = 12
          } 
        }, (time*cycle)*(i/n),this)

          console.log((time*cycle)*(i/n))
      }
      setTimeout(function(that){
        that.black = 0 
        that.yellow = 0
        that.red = 0
      }, (time*cycle)+10,this)
    },
  })
public class Primes {
  public static boolean isAPrime(int number) {
    return true;
  }
}