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
#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

Desing an algorithm that accepts a positive integer and reverses the order of its digits.

public class Algorithms {
  public static int reverseInt(int n) {
    int reversed = 0;
    
    while(n != 0){
      reversed = reversed * 10 + (n % 10);
      n /= 10;
    }
    
    return reversed;
  }
}

Cоздать функцию, которая может принимать в качестве аргумента любое неотрицательное целое число и возвращать его с цифрами в порядке убывания. По существу, измените порядок цифр, чтобы создать максимально возможное число.

function descendingOrder(n){
  n = n.toString();
  let arr = n.split('');
  let N = arr.length;
  
  if (n.length === 1) {
    return parseInt(n, 10);
  }
  
  for (let i = 0; i < N; i++) {
    
    for (let j = 0; j < N-i-1; j++) {
       if (arr[j] < arr[j+1]) {
        let k = arr[j];
        arr[j] = arr[j+1];
        arr[j+1] = k;
      }
    }
  }
 
 	n = arr.join('');
  n = parseInt(n, 10);
  return n;
}

Обязаны, учитывая строку, заменить каждую букву на ее позицию в алфавите.

Если что-то в тексте не является письмом, проигнорируйте его и не возвращайте.

"а" = 1, "Б" = 2 и т. д.

function alphabetPosition(text) {
  let obj = {
  	"a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7,
    "h": 8, "i": 9, "j": 10, "k": 11, "l":12, "m": 13, "n": 14, "o": 15, "p": 16, "q": 17, "r": 18, "s": 19, "t": 20,
    "u": 21, "v": 22, "w": 23, "x": 24, "y": 25, "z": 26
  }
  let arr = [];
  let str = '';
  
  text = text.replace(/[^a-zA-Z]+/g, '');
  for (let key in obj) {
  	for (let i = 0; i < text.length; i++) {
    	if(text[i].toLowerCase() == key.toLowerCase() && text[i] !== '') {
      	arr[i] = obj[key];
      }
    }
  }
  
  str = arr.join(' ');
  return str;
}
#include <stdio.h>

struct _Node{
  int value;
  struct _Node *left;
  struct _Node *right;
};

typedef struct _Node Node;

int InitTree( Node* tree, int value )
{
  if( tree == NULL ) {
      return -1;
  }
  tree->value = value;
  tree->left = NULL;
  tree->right = NULL;
}

int InsertTree(Node *tree, Node *new_node )
{
  if( new_node->value > tree->value ) {
    if( tree->right == NULL ) {
        tree->right = new_node;
    } else {
        InsertTree( tree->right, new_node );
    } 
  } else {
    if( tree->left == NULL ) {
        tree->left = new_node;
    } else {
        InsertTree( tree->left, new_node );
    }
  }
}

void OrderTraverse( Node* tree )
{
  if( tree != NULL ) {
      printf("%d ", tree->value);
      OrderTraverse( tree->left );
      OrderTraverse( tree->right );
  }
}

int main()
{
  Node *tree = NULL;
  tree = (Node*)malloc(sizeof(Node));
  InitTree(tree, 4);
  int i = 0;
  int array[10] = {4,1,6,9,7,8,3,2,5};
  
  for( i = 0; i < 9; i++ ) {
      Node *node = NULL;
      node = (Node*)malloc(sizeof(Node));
      if( NULL == node ) {
        continue;
      }
      InitTree(node,array[i]);
      InsertTree(tree,node);
  }
  
  OrderTraverse(tree);
  printf("succeed!\n");
  return 0;
}