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
kazkFailed Tests

Forth Testing

Experiments to add test support for Forth (Codewars/codewars-runner-cli#625).

The test framework part was originally contributed by @nomennescio.

\ Test Framework (ttester + extension)
decimal
s" test/ttester.fs" included

: #ms ( dmicroseconds -- len c-addr ) <# # # # [char] . hold #s #> ;

: describe#{ ( len c-addr -- ) cr ." <DESCRIBE::>" type cr utime ;
: it#{ ( len c-addr -- ) cr ." <IT::>" type cr utime ;
: }# ( -- ) utime cr ." <COMPLETEDIN::>" 2swap d- #ms type ."  ms" cr ;

create EXPECTED-RESULTS 32 cells allot
variable RESULTS
variable DIFFERENCES

: <{ T{ ;
: }>
  depth ACTUAL-DEPTH @ = if
    depth START-DEPTH @ > if
      depth START-DEPTH @ - dup RESULTS ! 0 do
        dup EXPECTED-RESULTS i cells + !
        ACTUAL-RESULTS i cells + @ <> DIFFERENCES +!
      loop

      DIFFERENCES @ if
        cr ." <FAILED::>expected: "
        RESULTS @ 0 do EXPECTED-RESULTS i cells + @ . loop
        ." <:LF:>  actual: "
        RESULTS @ 0 do ACTUAL-RESULTS i cells + @ . loop
        cr

      else
        cr ." <PASSED::>Test Passed" cr
      then
    then
  else
    cr ." <FAILED::>Wrong number of results. Expected:<:LF:>" ACTUAL-DEPTH @ . ." <:LF:>got:<:LF:>" depth . cr
  then
F} ;

\ Solution
: solution ( a b -- a*b ) * ;

\ Tests
s" Basic Tests" describe#{
  s" zeros" it#{
    <{ 0 0 solution -> 0 }>
    <{ 0 1 solution -> 0 }>
    <{ 1 0 solution -> 0 }>
  }#

  s" non-zeros" it#{
    \ intentionally broken tests
    <{ 1 1 solution -> 2 }>
    <{ 3 5 solution -> 8 }>
  }#
}#

Generate Sequence

fun tribonacci(signature: DoubleArray, n: Int) = generateSequence(Triple(signature[0], signature[1], signature[2])) {
        Triple(it.second, it.third, it.first + it.second + it.third) }
        .map { it.first }
        .take(n)
        .toList()
        .toDoubleArray()
        
        
        
fun main() {
    val array = doubleArrayOf(1.0,1.0,1.0)
    tribonacci(array, 10)
}

Complete the method wich accepts value, and return a String like following example:

  • If the value is positive, you display the result like this example:

    • The value is 3, the result will be: "1-22-333"
    • The value is 5, the result will be: "1-22-333-4444-55555"
  • If the value is negative, you display the result like this example:

    • The value is -3, the result will be: "1+22+333"
    • The value is -5, the result will be: "1+22+333+4444+55555"
class Solution {
  public static String numberOfNumbers(int value) {
    StringBuilder finalWord = new StringBuilder();
		int j = 0;
		String sign = value < 0 ? "+" : "-";

		if (value == 0) return "";
		
		if (value < 0) value *=-1;

		for (int i = 1; i <= value; ++i) {
			j = i;
			while (j > 0) {
				finalWord.append(i);
				--j;
			}
			finalWord.append(sign);
		}

		return finalWord.deleteCharAt(finalWord.length() - 1).toString();
  }
}

Minimal example for Idris testing with specdris.

module Example

%access export
%default total

add : Nat -> Nat -> Nat
add a b = a + b
#include <iostream>

typedef int (*Function)();

static Function Do;

static int EraseAll() {
  std::cout << "Safe!\n";
  return 1;
}

void NeverCalled() {
  Do = EraseAll;
}

int test() {
  return Do();
}

Expected result - compilation error.

module Example

%access export
%default partial

add : Int -> Int -> Int
add 3 5 = 8

We know that a matrix is a set of complex or real number arranged according to a rectangular array,but wo only dscuss real number here.When wo do some operations on a matrix, wo ofent need to get the dterminant value of the matrix, and we need a function to calculate the determinant value of the matrix.
The definitions of matrices and related terms are not well explained here. The specific contents are shown in linear algebra. Here, only a few concepts are briefly described.

1, Algebraic cofactor matrix:
In the n order determinant, the elements int the R row and the C column of an element are deleted, and the n - 1 order determinant composed of the remaining elements which do not change the original order is called the cofactor of the element Ecof[R,C].And it is called algebraic cofactor Eacof[R,C] if the resulting cofactor is multiplied by the R + C power of -1.

For example:

Matrix A =

         |1  9  3|              
         |4  8  6|            
         |7  8  5|

Cofactor Ecof[1,2] of A =

                     |4  6|  
                     |7  5|              

Algebraic cofactor Eacof[1,2] of A =

                               (-1)^(r+c) * Ecof[1,2] = -1 * |4  6|
                                                             |7  5|

2, The determinant of value of a matrix:
The determinant of an n * n matrix is equal to the sum of the product of the element of any row(or column) and the corresponding algebraic cofactor. In particular, for a matrix of order 2 * 2, its deterimant is the product of the two values of the left diagonal(the value of the upper left corner and the value of the lower right corner) minus the product of the two values of the right diagonal (the value of the lower left corner and the value of the upper right corner).

For example:

Matrix A =

         |1  9  3| 
         |4  8  6|
         |7  8  5|

Determinant(A) =

                Eacof[1,1] + Eacof[2,1] + Eacof[3,1]

Here, there will be a Matrix class, your purpose is to achieve the
determinant value of the matrix.
Note:There's already a function that return a matrix of cofactors(note that is a not an algebraic cofactor)

//We have Matrix Matrix::GetCofactorMatrix() to return cofactor matrix
//double & Matrix::GetElement(int _Row, int _Col) to return _Row and _Col of double element of matrix


double Matrix::GetValueOfDeterminant()
{
    if((2 == MaxRow) && (2 == MaxCol))
    {
        return GetElement(1,1) * GetElement(2,2) - GetElement(1,2) * GetElement(2,1);
    }
    else
    {
        double ResultValue = 0;
        for(int c = 1; c <= MaxCol; c++)
        {
            int PowOfNegativeOne = std::pow(-1, c);
            ResultValue += GetCofactorMatrix(1,c).GetValueOfDeterminant() * GetElement(1,c) * PowOfNegativeOne;
        }
        return ResultValue;  
    }
    
}
public class Adder {
    public static int add(int a, int b) {
        return a + b + 1;
    }
}

It seems possible to subvert the totality checker by using assert_total on a partial function to convince Idris that it is total. This would place Idris theorem-proving Kata in jeopardy.

module TotalitySubversion

%access export
%default total

partial
add' : Int -> Int -> Int
add' 3 5 = 8

add : Int -> Int -> Int
add = assert_total add'

Just confirming that Idris does not enforce totality by default.

module PartialFunction

%access export

-- Partial function (implicit)
add : Int -> Int -> Int
add 3 5 = 8