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
add(X, Y, R) :- R is X + Y + 1.
add(X, Y, R) :- R is X + Y + 1.
Dates/Time
Data Types
Strings

You must display literally the difference between two dates textual

Exemple input howManyTimesBetween("1995-12-02 and 2010-01-05")
Will return "There are 14 year(s), 10 month(s), 8 day(s) between 1995-12-02 and 2010-01-05"

Constraints and permissions

If constraints are not respected, the function should return "Your question is strange"

  • The two dates can be inverted (the oldest can be at start or end), and will give the same gap between the twice dates
  • If there are no months/day/years gap. Don't display it in the sentence (exemple : howManyTimesBetween("2010-01-05 and 2010-01-10") will return "There are 5 day(s) between 1995-12-02 and 2010-01-05")
  • If the two date are the same, will return "Dates are equals"
  • The date format is Y-m-d (conforming to https://www.php.net/manual/fr/datetime.format.php). There is not hours or others
  • The sentence should always do "{date} and {date}"
  • The end of the response sentence will is the same than the input whatever the order of dates
function howManyTimesBetween(string $sentence): string
{
    $errorMessage = 'Your question is strange';
  
    $datesString = explode(' and ', $sentence);
  
    if (count($datesString) !== 2) {
      return $errorMessage;
    }
  
    $date1 = DateTime::createFromFormat('Y-m-d', $datesString[0]);
    $date2 = DateTime::createFromFormat('Y-m-d', $datesString[1]);
  
    if ($date1 === false or $date2 === false) {
        return $errorMessage;
    }
  
    $diffStrings = [];
  
    if ($date1 == $date2) {
        return 'Dates are equals';
    }
  
    $diff = $date1->diff($date2);
    
    if ($diff->y) {
        $diffStrings[] = $diff->y.' year(s)';
    }
    
    if ($diff->m) {
        $diffStrings[] = $diff->m.' month(s)';
    }
    
    if ($diff->d) {
        $diffStrings[] = $diff->d.' day(s)';
    }
  
    return 'There are '.implode(', ', $diffStrings).' between '.$sentence;
}
Lists
Data Structures
Numbers
Data Types
Functions
Control Flow
Basic Language Features
Fundamentals
Algorithms
Logic

Combination of List

Instructions

Below are Instructions for this Kumite.

Introduction

Given the two list or arrays, filter and combine the numbers into one list or arrays. There will only be numbers in the list.

Requirements

  • There will be no negative number in the list
  • The list must be ordered in ascending order.
  • There must be no repeating number in the list.
  • It must support an empty list.

Test Samples

Below are the test sample for this excercise


# Multiple list should be able to combine into one list
combine_list([1,2,3],[4,5,6])
> [1,2,3,4,5,6]
# Final list should be sorted
combine_list([3,2,1,5],[6,8,7])
> [1,2,3,5,6,7,8]
# There must be no repeating number in the list
combine_list([4,5,6],[7,7,8])
>[4,5,6,7,8]
# The will be no negative number in the list
combine_list([4,5,8],[99,0,11,665,-245])
> [0,4,5,8,11,99,665]
def combine_list(list1,list2):
    return list(set(list(filter(lambda c: (c > 0), list1 + list2))))

output "another value".

#include <iostream>
#include <string>
int voice(){
  std::string a,b;
  std::cin>>a>>b;
  std::cout<<"another value";
  return 0;
}

There is a tree.
We define "cut the branch" as deleting one of its non-leaf nodes and making its sons its equal.
A root can also be deleted to form 2 seperate trees.
An example:
1->2, 2->3, 2->4
after deleting 2:
1->3, 1->4
after deleting 1:
3, 4(two seperate trees)

Your job is to decide the maximal amouts of trees you get when there are not any branches left for you to cut.

The input will be like this:
vector1 1 2 2
| | |
/ / /
vector2 2 3 4

#include <vector>
using namespace std;

int CutTheBranch(vector<int> fir, vector<int> sec){
  int thing[20005];
  for(int i=0;i<20005;i++)thing[i]=0;
  int k=sec.size();
  for(int i=0;i<k;i++)thing[fir[i]]++;
  int cnt=0;
  for(int i=0;i<20005;i++)if(thing[i]!=0)cnt++;
  return cnt;
}

Get Max of two integers

section .text
global max ; declare max function
max:            ; int max(int a, int b)
  cmp rdi, rsi ; compare a ?= b
  jle _lower  ; jump to lower if a <= b
  jmp _greater ; jump to greater if a > b
  _lower:
    mov rax, rsi ; assgine rax to b
    jmp _end ; end program
  _greater:
    mov rax, rdi ; assgine rax to a
  _end:
  ret

Macro to get max of two integers
can be used as a new pseudo-command

; A macro with two parameters
; Implements actual int max(int a, int b)
%macro _max 2 
  cmp %2, %1 ; compare a ?= b
  jle _lower ; jump to lower if a <= b
  jmp _greater ; jump to greater if a > b
  
  _lower:
    mov rax, %1 ; assgine rax to b
    jmp _end ; end program
  _greater:
    mov rax, %2 ; assgine rax to a
  _end:
  ret
  
%endmacro

section .text
global max ; declaring int max(int a, int b)

max:            
  _max rdi, rsi ; using inner _max macro 
  ret

Iterating over two vectors at the same time till end of one of them

#include <vector>
#include <tuple>
#include <iostream>
template <class T, class U>
void iterateTwoVectors(std::vector<T> A, std::vector<U> B)
{

   for (auto [a,b] = std::tuple{A.begin(), B.begin()}; a != A.end() && b != B.end(); a++, b++) 
   { 
    std::cout << *a << ":" << *b << "\n";
   }
}

enumerating over vector, equivelent to python's enumerate(list)

#include <vector>
#include <tuple>
#include <iostream>

template <class T>
void enumerate(std::vector<T> A)
{
    for(auto [a,i]=std::tuple{A.begin(), 0}; a < A.end(); a++, i++)
   { 
    std::cout << i << ":" << *a << "\n";
   }
}