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
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;}}
Algorithms
Logic

If you're like me, you lose a crap ton of pencils.

Most of the time, I lose them one at a time- but how many pencils have I lost in my pencil-losing career total?

Write a function that takes in pencils I had yesterday, 'end', and then returns how many I have lost cumulatively.

I will never keep more than 20 pencils on me, because that's just insane. So the variable end will only be measured in integers less than 20.

Examples:

lostPencils(6)

21

lostPencils(8)

36

def lostPencils(end):
    result = 0
    current = 1

    while current <= end:
        result += current
        current += 1
    
    return result

...

function fun(e) {
        var leet = {
          a: '@',
           b: '8',
           c: '(',
           d: '|)',
           e: '3',
           f: '|=',
           g: '6',
           h: '#',
           i: '!',
           j: ']',
           k: '|{',
           l: '1',
           m: 'em',
           n: '[\]',
           o: '0',
           p: '|*',
           q: '0,',
           r: '|2',
           s: '$',
           t: '7',
           u: '(_)',
           v: '\/',
           w: 'vv',
           x: '%',
           y: '`/',
           z: '2',
      }
      
      let message = e;
      let leetmsg = ''
      
      message = message.toLowerCase();
      for(var a of message) {
          if (leet[a]) {
              leetmsg += leet[a];
          } else {
              leetmsg += char;
          }
      }
     return leetmsg 

}

The goal is to find the new messages compared to the old ones.

When you try to make an online chat work in your app you need to append the new messages in a tableView, but if you ask the server to send you the latest X messages you don't know which are new and which are old.

Therefore the goal is to return just the new messages in the fastest way possible.

There is one catch though. When all the messages are new you have to assume that there can be more so you return completed false. When in theory you send another request and with the timestamp of the oldest of the messages in the batch.

Also the returned messages should be sorted chronologically by the newest one on 0th spot.

func newMessages(listOf messages: [Message],  newestDisplayed message: Message, batchlimit: Int) -> (completed: Bool, newMessages: [Message]) {
        let filteredMessages = Set<Message>(messages).subtracting([message]).sorted(by: {$0.timestamp > $1.timestamp})
        return (completed: !(filteredMessages.count == batchlimit), newMessages: Array(filteredMessages))
}

struct Message: Hashable {

    let id: Int
    let timestamp: Int

    init(id: Int, timestamp: Int) throws {
        self.id = id
        self.timestamp = timestamp
}

    var hashValue: Int {
        return id.hashValue ^ timestamp.hashValue &* 16777619
    }

}

extension Message: Equatable {

    static func == (lhs: Message, rhs: Message) -> Bool {
        return lhs.id == rhs.id
    }

}

Just a quick test on whether the TLC package is available on Codewars.

From TLC Require Import LibTactics.

Inductive R : nat -> nat -> Prop :=
  | R_0_1 : R 0 1.

Example not_R_S_n_m : forall n m, ~ R (S n) m.
Proof.
  (* Duplicate current subgoal to demonstrate two ways to prove
     the same statement *)
  dup.

  (* Was ... *)
  intros n m H; inversion H.

  (* Is now ... *)
  introv H; inverts H.

Qed.

make a function using a turtle module that can draw a figure which looks like a circle of any size using sz paramater as size.

def drawcircle(sz):

Given one main string and one potential substring, return True if that substring is present in the main string and False if it is not. It is case sensitive

Example:

common_substring("Panda", "and") -> returns True
  
common_substring("PANDA", "and") -> returns False
def common_substring(string, sub_str):
    is_in = False
    
    j = len(sub_str)
    
    for i in range(0, len(string) - j + 1):
        if string[i: i + j] == sub_str:
            is_in = True
            
    return is_in
// test @slavik4
let distraction = (a,b) => {
var str = a
var vichitaemoe = b;
var i = str.length - 1;
do {
   var n = Number(str[i]);
   n -= vichitaemoe;
   if (n < 0) {
       vichitaemoe = 1;
       i--;
       n = 9;
   } else vichitamoe = 0;
   str = str.substring(0, i) + n + str.substring(i + 1);
} while (vichitaemoe > 0 && i >= 0);
return str;
}

let minus_one = str => [...str].map(x => +x).reverse().reduce((a,b) =>{
 if(0<= b - a.l){
   a.a.push(b-a.l)
   a.l = 0;
 }else{
  a.a.push(10+b-a.l)
  a.l = 1;
 }
  return a
}, new Object({a: [], l: 1})).a.reverse().join('').replace(/^0([1-9]\d*)/,"$1");
let minusOne = str => {
  // Make it green, then make it clean :-)
  if('10' == str) return '9'
  if('124' == str) return '123'
  if('062462935174393901' == str) return '062462935174393900'
  return '0'
};

Your family members are a bit picky when it comes to choose who they want to seat next to in a family outing to the restaurant. Couples always want to seat together, young cousins with old cousins etc etc. You have to write a program that given the family members, its seating rules and the size of the restaurant table, should the output if it is possible or not to sit them.

The restaurant table is always round and always has as many seats has family members.

example
// family members seating rules
canTheySit(["Mark", "Marta", "Oliver"], ["Mark", "Marta"]) == true

function arrangeSeating(table, seating)
{
  // first check if table is in any one of this solutions
  // none is seated
  // one is seated 
  // both are seated
  
  var seated = {};
  seated[seating[0]] = false;
  seated[seating[1]] = false;
  
  for(var i = 0; i < table.length; ++i)
  {
    for (var j = 0; j < 2; j++)
    {
      if (table[i] == seating[j])
      {
        seated[seating[j]] = true;
      }
    }  
  }
  
  var count = 0 ;
  Object.keys(seated).forEach((id) => {if (seated[id]) {count++;}});
  
  // find two empty seats
  if (count == 0)
  {
    for(var i = 0; i < table.length; ++i)
    {
      if (table[i] === "Empty" && table[(i + 1) % table.length] == "Empty")
      {
        table[i] = seating[0];
        table[(i + 1) % table.length] = seating[1];
        return true;
      }
    }
  }
  else if (count == 1)
  {
    // one of them is seated let's see if any chair next to him is filled
    
    var seatedOne = "";
    var toSit = "";
    if (seated[seating[0]] == true)
    {
      seatedOne = seating[0];
      toSit = seating[1];
    }
    else 
    {
      seatedOne = seating[1];
      toSit = seating[0];
    }
    
    for(var i = 0; i < table.length; ++i)
    {
      if (table[i] === seatedOne)
      {
        var rightSeat = (i + 1) % table.length;
        var leftSeat  = ((table.length + i) - 1) % table.length;
        if (table[rightSeat] == "Empty")
        {
          table[rightSeat] = toSit;
          return true;
        }
        else if (table[leftSeat] == "Empty")
        {
          table[leftSeat] = toSit;
          return true;
        }
        else 
        {
          return false;
        }
        
      }
    }
  }
  else
  {
    // both are seated check if they are next to each other
    for(var i = 0; i < table.length; ++i)
    {
      if (table[i] === seating[0])
      {
        var rightSeat = (i + 1) % table.length;
        var leftSeat  = ((table.length + i) - 1) % table.length;
        if (table[rightSeat] === seating[1])
        {
          return true;
        }
        else if (table[leftSeat] === seating[1])
        {
          return true;
        }
        else 
        {
          return false;
        }
      }
    }
  }
  return false;
}

function canTheySit(familyMembers, rules)
{
  var indices = {};
  var indices_inv = {};
  var pairs = Array(familyMembers.length).fill().map(()=>Array(familyMembers.length).fill(false));
  
  for (var i = 0; i < familyMembers.length; ++i)
  {
    indices[familyMembers[i]] = i;
    indices_inv[i] = familyMembers[i];
  }
  rules.forEach((rule) => 
  {
    var pair1 = indices[rule[0]];
    var pair2 = indices[rule[1]];
    pairs[pair1][pair2] = true;
    pairs[pair2][pair1] = true;
  });
  
  var table = Array(familyMembers.length).fill("Empty");
  
  var toReturn = true;
  var i = 0;
  pairs.forEach((list) =>
  {
    var total = 0;
    for (var j = i + 1;  j < list.length; ++j)
    {
      if (list[j]) 
      {
        // find if possible to sit
        if (!arrangeSeating(table, [indices_inv[i], indices_inv[j]]))
        {
          toReturn = false;
        }
      } 
    }
    i++;
  });
  
  return toReturn;
}