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
Fundamentals
Mathematics
Algorithms
Logic
Numbers
Strings
Data Types

Ques 7: Input type String. Output type number. Print out the maximum even number which can be generated by making combinations of numbers present in the given string. Each number can be used only once ie. No Redundancy.

Example1:
Input String = Infytq@218412
Intermediate step (List of numbers //redundancy removed) = [2,1,8,4]
Output Number = 8412

Example2
Input String = someString&337
Intermediate step (List of numbers //redundancy removed) = [3,7]
Output Number = -1

def maximum_even_no(string):
    list1=[]
    list2=[]
   
    for i in string:
        if(i.isdigit()):
            list1.append(i)
    list1=list(dict.fromkeys(list1))
    list2=sorted(list1,reverse=True)
    if(int(list2[-1])%2==0 or int(list2[-1])==0):
        return int("".join(list2))
    list3=range(len(list2))
    list3=sorted(list3,reverse=True)
    for j in list3:
        if(int(list2[j])%2==0):
            temp=list2.pop(j)
            list2.append(temp)
            break
    result="".join(list2)
    if(int(result)%2==0):
        return int(result)
    else:
        return -1

Takes a string of an even length, splits it in two and intertwines those to generate the output string.
e.g intertwine('135246') --> '123456'
intertwine('11223344') --> '13132424'

def intertwine(text):
    return ''.join([val+'' for pair in zip(text[:len(text)//2], text[len(text)//2:]) for val in pair])

Swing list sorting:
Examples:

special_sort(list) -> list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] # input
[0, 9, 1, 8, 2, 7, 3, 6, 4, 5] # output
def special_sort(list):
    r = []
    l = len(list)
    for i in range(l // 2 + 1):
    	if i == 0 or (i == l // 2 and not l % 2):
    		r.append(list[i])
    	else: r.extend([list[-i], list[i]])
    return r

Sebastian and Patricia want to know if the sum digits of their years is greater than the sum digits of their mother's years?

Example: (27,3,1)

  1. Mother = 27
  2. Sebastian = 3
  3. Patricia = 1

Calculate: (2+7) < (3+1) => false

public class AgeSumDigits
{
  public static boolean SumOfDigits(int[] ages) {   
  int m = ages[0];
  int s = ages[1];
  int p = ages[2];
  // Coding with passion ;)    
  return (calcSum(m) < calcSum(s)+calcSum(p)) ? true : false;
      
  } 
  
  static int calcSum(int age){
    int sum = 0;
    while(age>0){
      sum += age % 10;
      age /= 10;
    }
    return sum;
  }
}

You have received 2 names.

Verify if the sum of letters of the 1 name is the same as sum of the letters of the 2 name. If the name or surname is null output NULL.

For example:

  1. "Anna" and "Nana"
    "Anna" = 65+110+110+97 = 382
    "Nana" = 78+97+110+97 = 382
    Result: "Anna" and "Nana" => "TRUE"

  2. "Sebastian" and "Patricia" => "FALSE"

  3. "John" and null => "NULL"

class Kata{
  
  public static String verifySum(String nameOne, String nameTwo) {
        int[] sumOfNames = new int[]{0, 0};
        
        if (nameOne == null || nameTwo == null) {
            return "NULL";
        }
        
        for (int i = 0; i < nameOne.length(); i++){
            sumOfNames[0] += nameOne.charAt(i);
        }
        
        for (int i = 0; i < nameTwo.length(); i++){
            sumOfNames[1] += nameTwo.charAt(i);
        }
        
        return sumOfNames[0] == sumOfNames[1] ? "TRUE" : "FALSE";
    }
}
#include <stdlib.h>
#include <string.h>

char *my_strdup_1(const char *str) {
  const size_t len = strlen(str);
  char *const res = malloc(len); // <- BUG
  memcpy(res, str, len);
  return res;
}

char *my_strdup_2(const char *str) {
  const size_t len = strlen(str);
  char *const res = malloc(len); // <- BUG
  memcpy(res, str, len + 1);
  return res;
}
const interwine = str => 
   [...str]
      .reduce((r,_,i,s) => 
         i%2 ? 
         [...r,s[(s.length+i-1)/2]] :
         [...r,s[i/2]], [])
      .join('')

not sure what this is...

function compute() {
  return 1;
}

As my debute kata met no enthusiasm from community (and my own solution was claimed inefficient), I'll go with my second attempt on concise and fast array chunking contest:

The task is fairly simple - slice arbitrary array into chunks of size m (without dropping the remainder of length less than m).

Big arrays are thrown in.

Less than 100 chars should be consumed for your code.

No libraries allowed.

const splitArr = (a,s) => a.reduceRight((r,_,__,f) => [...r, f.splice(0, s)],[]);
Advanced Language Features
Fundamentals
Theorem Proving

In Coq, every recursive definition has to provably terminate on all possible inputs; otherwise, the logical consistency of Coq would be undermined. However, it is possible to define well-founded recursive functions which fail to pass Coq's built-in termination checker since it only does a very simple check to ensure that the Fixpoint being defined is structurally recursive:

Fail Fixpoint interleave {A} (l1 l2 : list A) : list A :=
  match l1 with
  | [] => l2
  | x :: xs => x :: interleave l2 xs
  end.
(* => The command has indeed failed with message:
      Cannot guess decreasing argument of fix. *)

One way to define non-structurally-recursive functions which provably terminate in Coq is to use the Function feature. To use the Function feature, one has to first Require Import Recdef before defining the Function and specifying a measure that decreases on every recursive call, followed by a proof that the measure indeed decreases as required ending with Defined instead of the usual Qed. However, in our particular case, even Function fails us since it requires the measure to refer to exactly one argument in the function:

Require Import Recdef.

Fail Function interleave {A} (l1 l2 : list A) {measure length (l1 ++ l2)} : list A :=
  match l1 with
  | [] => l2
  | x :: xs => x :: interleave l2 xs
  end.
(* => The command has indeed failed with message:
      Recursive argument must be specified *)

In this case, we need to use Program Fixpoint instead which is very similar to Function except that the decreasing measure can refer to more than one argument. To use Program Fixpoint, one has to first import Coq.Program.Wf:

From Coq Require Import Program.Wf.

Program Fixpoint interleave {A} (l1 l2 : list A) {measure (length (l1 ++ l2))} : list A :=
  match l1 with
  | [] => l2
  | x :: xs => x :: interleave l2 xs
  end.

However, if we try to use the Program Fixpoint at this stage, Coq will complain that it is not found in the current environment:

Fail Compute (interleave [1;2;3] [4;5;6]).
(* => The command has indeed failed with message:
      The reference interleave was not found
      in the current environment. *)

This is because we haven't proven to Coq that it terminates yet. To do that, we have to focus each proof obligation generated by Program Fixpoint (1 in this particular example) using Next Obligation followed its proof. It is OK to end the proofs with Qed when using Program Fixpoint:

Next Obligation.
  simpl.
  repeat rewrite app_length.
  omega.
Qed.

Now we can compute with it:

Compute (interleave [1;2;3] [4;5;6]).
(* => = [1; 4; 2; 5; 3; 6]
      : list nat *)
From Coq Require Import Lists.List omega.Omega.
Import ListNotations.

Fail Fixpoint interleave {A} (l1 l2 : list A) : list A :=
  match l1 with
  | [] => l2
  | x :: xs => x :: interleave l2 xs
  end.

Require Import Recdef.

Fail Function interleave {A} (l1 l2 : list A) {measure length (l1 ++ l2)} : list A :=
  match l1 with
  | [] => l2
  | x :: xs => x :: interleave l2 xs
  end.

From Coq Require Import Program.Wf.

Program Fixpoint interleave {A} (l1 l2 : list A) {measure (length (l1 ++ l2))} : list A :=
  match l1 with
  | [] => l2
  | x :: xs => x :: interleave l2 xs
  end.

Fail Compute (interleave [1;2;3] [4;5;6]).

Next Obligation.
  simpl.
  repeat rewrite app_length.
  omega.
Qed.

Compute (interleave [1;2;3] [4;5;6]).

Example test_interleave1:
  interleave [1;2;3] [4;5;6] = [1;4;2;5;3;6].
Proof. reflexivity. Qed.
Example test_interleave2:
  interleave [1] [4;5;6] = [1;4;5;6].
Proof. reflexivity. Qed.
Example test_interleave3:
  interleave [1;2;3] [4] = [1;4;2;3].
Proof. reflexivity. Qed.
Example test_interleave4:
  interleave [] [20;30] = [20;30].
Proof. reflexivity. Qed.