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

We shall see.

#import <Foundation/Foundation.h>

// Nope - the bug has not been fixed yet :(
void test_function() {
  [PreloadedTest printTestMessage];
}

Since I have to work on an Android project which doesn't use Gradle as a build tool, so I always have to find the aar library and extract the classes.jar file from it. Doing it manually was very boring. So I decided to write my own Python (because it's interpreted) script to do this task. The code I have written works very well, but it can be improved by making it cross-platform, efficient, etc.

So let's start to improve it.

Gist: https://gist.github.com/pavi2410/b1ba0ae03e4b459846c72453204394a6

Note that you have to run this script on your PC, unfortunately.

import zipfile, os

cd = os.getcwd()
for file in os.listdir(cd):
	if file.endswith(".aar"):
		print("Got aar: " + file)
		with zipfile.ZipFile(cd + "\\" + file) as aar:
			aar.extract("classes.jar", cd)
			print("Extracted aar")
		os.rename("classes.jar", os.path.splitext(file)[0] + ".jar")

Write a function that:

  • returns "Fizz" for multiples of 3
  • returns "Buzz" for multiples of 5
  • returns "FizzBuzz" for multiples of both 3 and 5

Any other number should return the number as string.

export function fizzBuzz(input: number): string {
    const output: string = `${input % 3 === 0 ? "Fizz" : ""}${input % 5 === 0 ? "Buzz" : ""}`;
    return output.length > 0 ? output : input.toString(10);
}
Testing
Frameworks

Please go to same kumite on the preview site to run these tests correctly :)

Example Task

Compute the sum of two integers.

Constraints

-10**9 <= a, b <= 10**9

Example Solutions

  1. add: Correct solution
  2. add1: Incorrect solution
  3. add2: Solution that timeouts
  4. add3: Solution that cheats

You can uncomment each line at the bottom of Code section to see how the tests combat the invalid solutions in different ways.

Example Test Fixture

  1. @Test.describe(name)
  2. @Test.it(name)
  3. @Test.timeout(sec)
  4. Test.assert_equals and Test.assert_not_equals are non-blocking by default
  5. Test.assert_not_equals can now prevent cheating with magic methods

For more complete list of features and guide on how to write a test fixture, consult this page on GitHub Wiki.

# Correct solution
def add(a, b): return a + b

# Incorrect solution
def add1(a, b): return a | b

# Solution that timeouts
def add2(a, b):
    while a: a, b = a-1, b+1
    return b

# Solution that cheats
def add3(a, b):
    class X(object):
        def __eq__(self, other): return True
        def __ne__(self, other): return True
        def __gt__(self, other): return True
        def __lt__(self, other): return True
        def __ge__(self, other): return True
        def __le__(self, other): return True
    return X()
    
#add = add1
#add = add2
#add = add3
main = print (maxBound :: Int)

C has a weak type system that can be easily violated. The sole purpose of the type system is to inform the program how to view/interpret a certain memory block/space. It doesn't take much effort to convince C to view a particular memory space in a completely different manner than previously intended which could lead to interesting behavior ;)

Addendum: Following a bit of additional experimentation, it would appear that it is also possible to reassign value(s) under a pointer that views the given memory space in a completely unintended manner. However, I suspect this may be bordering on undefined behavior which means it may not work properly on all operating systems :p

// See the test cases for the real fun ;)

You have been asked to work out the area of number of rectangles.

The input to your function is a array of longs. If the arrays length is odd you should return void. Otherwise you should use adjacent pairs of longs to calculate the area.

For example if the input is {4,4,5,5,6,6,7,7} you should return {16, 25, 36, 49}.

public class Area {

  public static long[] workOutArea(long[] values){
  
  }

}
def blend(c1, c2):
    if c1 == c2: return c1
    colors = c1 + c2
    if colors == "RB" or colors == "BR": return "G"
    if colors == "RG" or colors == "GR": return "B"
    if colors == "GB" or colors == "BG": return "R"



def triangle(row):
    if len(row) == 1: return row
    row = list(row)
    for j in range(len(row)-1,0,-1):
        for i in range(j):
            row[i] = blend(row[i], row[i+1])
    return row[0]
Testing
Frameworks

This Kumite is a showcase for further possible improvements of Python testing framework cw-2.py, which has been going through major changes. You can see already implemented features here (on Preview site).

Proposal

Improved expect_error(), idea by Blind4Basics

As-is:

  • Test if the function throws an error. It doesn't matter which exception it exactly throws.

To-be:

  • Test if the function throws an error, which is an instance of the given Exception class.
# BaseException >> Exception
def f1(): raise Exception()

# BaseException >> Exception >> ArithmeticError >> ZeroDivisionError
def f2(): return 1 // 0

# BaseException >> Exception >> LookupError >> KeyError
def f3(): return {}[1]

def f0(): pass

[1, 1, 2] ==> 2
[17, 17, 3, 17, 17, 17, 17] ==> 3

Subtle arr.reduce(:^) solutions dose not works on [x,y,y,y] fromat. Take a look at the Test Cases.

The key to problem was found, size of the array must be odd: Y^Y n times give 0, and 0^X gives X

# Find stray number
def find_stray(n)
  n.reduce(:^)
end