Begin a new Kumite
Search
About
  • Filter by Language:
  • 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.

Lists
Data Structures
Fundamentals
Arrays
Code
Diff
  • D = {1:'yes', 2:'no'}
    l = [1, 2, 3, 4, 5]
    a = [D.get(v, 'idle') for v in l]
    print(a)
  • 1+
    D = {1:'yes', 2:'no'}
    
    11
    l = [1, 2, 3, 4, 5]
    
    2
    a = ['idle' if v not in (1, 2) else 'yneos'[v-1::2] for v in l]
    
    3+
    a = [D.get(v, 'idle') for v in l]
    
    33
    print(a)
    

Recent Moves:

You have acess to remote data using a function named getData, but you have to pay royalties each time you call it.

You know the data doesn't change in time, but depends on the arguments you're passing to getData

getData('some', 'args') // returns some data
getData('some', 'other') // returns another data

write a function multiMemoize that tankes a function, here getData, as an argument and returns an extended version of this function.

The extended version only calls the original function once for given arguments, then returns memoized result if called with the same arguments, like this :

let memoized = multiMemoize(getData)

let res1 = memoized('hello', 'world') 
// getData is called

let res2 = memoized('hello', 'world')
// getData is NOT called

res1 === res2 // true

let other1 = memoized('fizz', 'buzz')
// getData is called

let res3 = memoized('hello', 'world')
// getData is NOT called

res3 === res1 // true

// getData was called only 2 times

Constraints

  • The multiMemoizeFunction should extend any function whatever the number of arguments

  • the extended version should accept any arguments, strings, integer, objects... beware that random tests use random characters

  • it should work properly with promises (you have preloaded function getDataAsync to test that):

let asyncMemoized = multiMemoize(getDataAsync)

asyncMemoized(5)
  .then(data => console.log(data))
  .catch(err => console.log(err))

asyncMemoized(5)
  .then(data => console.log(data))
  .catch(err => console.log(err))
// gives the same result (immediately)
// WITHOUT calling getDataAsync

helpers

  • you have function getData to fetch the data synchonously

  • you have function getDataAsync to fetch it in a promise that resolves in ~1 second

  • you can call getRequestCount to follow how many times you called each function :

getRequestCount() === {
  sync: 5,
  async: 2,
  total: 7
}
// or
getRequestCount().sync === 5

  • if you want to deal with multiple datasources, you can create another one using the class DataSource which exposes methods getData, getDataSync & getRequestCount :
let dataSource2 = new DataSource()

dataSource2.getDataAsync()
dataSource2.getDataAsync()

dataSource2.getRequestCount().async === 2

``
function multiMemoize (func) {
  let cache = new Map()
  
  function run (...args) {
    let key = JSON.stringify(args)
    let cached = cache.get(key)
    if (cached !== undefined) {
      return cached
    } else {
      let value = func(...args)
      cache.set(key, value)
      return value
    }
  }
  return run
}
/*
let memoized = multiMemoize(getData)

let res1 = memoized('hello', 'world') 
// getData is called

let res2 = memoized('hello', 'world')
// getData is NOT called

res1 === res2 // true

let other1 = memoized('fizz', 'buzz')
// getData is called

let res3 = memoized('hello', 'world')
// getData is NOT called

res3 === res1 // true

console.log(getRequestCount())
*/
Code
Diff
  • module HelloHaskell where
    
    main :: IO ()
    main = print "Hello Haskell!"
  • 11
    module HelloHaskell where
    
    22
    33
    main :: IO ()
    
    4
    main = putStrLn "Hello Haskell!"
    
    4+
    main = print "Hello Haskell!"
    
Code
Diff
  • # finally fixed
    echo "WAFFLES" $1
  • 11
    # finally fixed
    
    2
    echo $1
    
    2+
    echo "WAFFLES" $1
    
Code
Diff
  • SELECT *
    FROM greetings
    WHERE id <= 10
  • 1
    SELECT name 
    
    1+
    SELECT *
    
    22
    FROM greetings
    
    3
    LIMIT 10;
    
    3+
    WHERE id <= 10
    
global double_multiplication
section .text
double_multiplication:
xor        edx,edx
mov        eax,edi
mul        esi
ret
Variables
Basic Language Features
Fundamentals
Conditional Statements
Control Flow
Loops
Arrays

Numpy but with half length array without Even numbers and array turned to boolean, and bitshifting >>1 instead of integer division //2 (not that it seems to make any real difference). All tests execute about 600-700ms quicker than the previous full array.

Added 300,000,000 test:
all tests pass within the 12000ms time limit.

Added 400,000,000 test:
Hash out 300M test before running.

Added 650,000,000 test:
Hash out all other tests prior to running!!!
Test may complete within the time limit if you are lucky!

solved the n = prime issue I was having added a test to make sure that if n is prime it's actually included.

Code
Diff
  • import numpy as np
    def get_primes(n):  
        bpr = np.ones((n+1)//2,dtype=bool) #length (n+1)//2 array of boolean True values
        bpr[0] = False 
        v = 1 + int(n**0.5) #limit
        for i in range(3, v, 2):
            if bpr[i>>1]: # >>1 equivalent to //2
                bpr[(i*i)>>1::i] = False #"broadcasts" value into slice
        return [2] + list( 2* np.nonzero(bpr)[0] +1) #values from bool indices,modify,listify
  • 11
    import numpy as np
    
    2
    def get_primes(n):    
    
    3
        bpr = np.ones(n)
    
    4
        bpr[:2] = bpr[4::2] = 0
    
    5
        v = 1 + int(n**0.5)
    
    2+
    def get_primes(n):  
    
    3+
        bpr = np.ones((n+1)//2,dtype=bool) #length (n+1)//2 array of boolean True values
    
    4+
        bpr[0] = False 
    
    5+
        v = 1 + int(n**0.5) #limit
    
    66
        for i in range(3, v, 2):
    
    7
            if bpr[i]:
    
    8
                bpr[i*i::i+i] = 0 
    
    9
        return list(np.nonzero(bpr)[0])
    
    7+
            if bpr[i>>1]: # >>1 equivalent to //2
    
    8+
                bpr[(i*i)>>1::i] = False #"broadcasts" value into slice
    
    9+
        return [2] + list( 2* np.nonzero(bpr)[0] +1) #values from bool indices,modify,listify
    
Fundamentals
Code
Diff
  • using System;
    
    public class Kata
        {
            public  static int Opposite(int number) => (~number ^ number) * number;
        }
  • 11
    using System;
    
    22
    33
    public class Kata
    
    44
        {
    
    5
            public  static int Opposite(int number) => ~number + 1;
    
    5+
            public  static int Opposite(int number) => (~number ^ number) * number;
    
    66
        }