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.
This solution uses a simple hash for holding stringified args to quickly lookup the cache.
The assumption is that only one type of function signature is ever used.
describe("Solution", function(){ var called = 0; function sum(a, b) { called++; return a + b; } it("should add 1 + 2", function(){ Test.assertEquals(memoize(sum)(1,2), 3); }); it("should have been called once", function(){ Test.assertEquals(called, 1); }); it("should still have been called once due to cache", function(){ memoize(sum)(1,2) Test.assertEquals(called, 1); }); it("should still have been called twice if different param orders", function(){ memoize(sum)(2,1) Test.assertEquals(called, 2); }); });
- describe("Solution", function(){
- var called = 0;
- function sum(a, b) {
- called++;
- return a + b;
- }
- it("should add 1 + 2", function(){
- Test.assertEquals(memoize(sum)(1,2), 3);
- });
- it("should have been called once", function(){
- Test.assertEquals(called, 1);
- });
- it("should still have been called once due to cache", function(){
- memoize(sum)(1,2)
- Test.assertEquals(called, 1);
- });
- it("should still have been called twice if different param orders", function(){
- memoize(sum)(2,1)
- Test.assertEquals(called, 2);
- });
- });
using System.Numerics; public class basic { public static BigInteger pow(long down, ulong up) { BigInteger output = 1; BigInteger cumulativeDown = down; for(ulong bitChecker = 1; bitChecker > 0 && bitChecker <= up; bitChecker <<= 1) { if((bitChecker & up) != 0) { output *= cumulativeDown; } cumulativeDown *= cumulativeDown; } return output; } }
- using System.Numerics;
- public class basic
- {
public static BigInteger pow(long down, long up)=> up == 0 ? 1 : down * pow(down, up - 1);- public static BigInteger pow(long down, ulong up)
- {
- BigInteger output = 1;
- BigInteger cumulativeDown = down;
- for(ulong bitChecker = 1; bitChecker > 0 && bitChecker <= up; bitChecker <<= 1)
- {
- if((bitChecker & up) != 0)
- {
- output *= cumulativeDown;
- }
- cumulativeDown *= cumulativeDown;
- }
- return output;
- }
- }
import java.util.stream.*; class Solution { public static String largestNumber(final Integer[] nums) { return Stream.of(nums) .sorted((a,b)->(""+b+a).compareTo(""+a+b)) .collect(Collectors.reducing("",(x)->""+x,String::concat)); } }
- import java.util.stream.*;
- class Solution {
- public static String largestNumber(final Integer[] nums) {
- return Stream.of(nums)
- .sorted((a,b)->(""+b+a).compareTo(""+a+b))
.map(n->""+n).collect(Collectors.joining());- .collect(Collectors.reducing("",(x)->""+x,String::concat));
- }
- }
# What are all the ways to output a string in Ruby? def hello_ruby greet = "Hello Ruby!" print greet, "\n" puts greet print "#{greet}\n" puts "Hello Ruby!" $stdout.write greet + "\n" $stdout.puts greet $stdout.print greet, "\n" $stdout << greet + "\n" (greet+"\n").each_char {|c| print c} end
- # What are all the ways to output a string in Ruby?
- def hello_ruby
- greet = "Hello Ruby!"
- print greet, "\n"
- puts greet
- print "#{greet}\n"
puts "#{greet}"- puts "Hello Ruby!"
- $stdout.write greet + "\n"
- $stdout.puts greet
- $stdout.print greet, "\n"
- $stdout << greet + "\n"
- (greet+"\n").each_char {|c| print c}
- end
def fib(x): fib = [1,1] for x in range(x-1): fib.append(fib[-2]+fib[-1]) return fib[-1]
def _fib(n):k = n.bit_length()-1x0, x1 = 1, 0y0, y1 = 0, 1for i in range(k, -1, -1):y2 = y0*y0y0, y1 = 2*y0*y1+y2, y2+y1*y1if (n>>i)&1:xy = x0*y0y0, y1 = x0*y1+x1*y0+xy, xy+x1*y1return y0def fib(n):return _fib(n+1)- def fib(x):
- fib = [1,1]
- for x in range(x-1):
- fib.append(fib[-2]+fib[-1])
- return fib[-1]
test.assert_equals(1, fib(0)) test.assert_equals(1, fib(1)) test.assert_equals(2, fib(2)) test.assert_equals(3, fib(3)) test.assert_equals(5, fib(4)) test.assert_equals(8, fib(5)) a = 0 b = 1 for i in range(1000): test.assert_equals(b, fib(i)) tmp = a a = b b = tmp + b
- test.assert_equals(1, fib(0))
- test.assert_equals(1, fib(1))
- test.assert_equals(2, fib(2))
- test.assert_equals(3, fib(3))
- test.assert_equals(5, fib(4))
- test.assert_equals(8, fib(5))
- a = 0
- b = 1
- for i in range(1000):
- test.assert_equals(b, fib(i))
- tmp = a
- a = b