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

Suppose you have a software, that will distribute invoices to different billing service providers.

You have a user interface, where you can set the ratio in which the bills are to be distributed to the providers. Back in the software, all bills run in a shuffle function. This function is called with the config from the user interface, that contains the providers and the ratio in which the providers should be chosen.

The Function is generic, so you can send any type you want in the function. This is a very easy way to implement a dynamic load distribution.

If you call the function 1000 times or more, the distribution is very close by your configuration.

using System;
using System.Collections.Generic;
using System.Linq;

namespace Solution
{
    public class ObjectShuffler
    {
       private Random rnd = new Random();

        public T Shuffle<T>(Dictionary<T, int> parameterDict)
        {
            //Remove wrong configuration.
            parameterDict = (from i in parameterDict
                             where i.Value > 0
                             select i).ToDictionary(x => x.Key, x => x.Value);

            //Error Handling
            if (parameterDict.Count == 0)
            {
                throw new Exception("Can't shuffle an empty list."); 
            }

            //Do Work
            var sumItemsValue = (from x in parameterDict select x.Value).Sum();
            var randNr = this.rnd.Next(1, sumItemsValue + 1);
            var stepSum = 0;

            foreach (var item in parameterDict)
            {
                stepSum = stepSum + item.Value;
                if (randNr <= stepSum)
                {
                    return item.Key;
                }
            }
            // This can't happen.
            throw new Exception("Run to far.");
        }
    }
}

I've done a 7kyu kata. The task was to return the same table, but with one column changed.

Say they want to to upper one column, but other columns should remain the same.
In that kata there were only 4 columns.
And all top soulutions was like this:
SELECT column1, column2, column3, UPPER(column4)

But i came with an idea and soulution for the case when there are say 10 columns.

Instead of making a big selecet statement we can do like this:

SELECT *, UPPER(column5) as column5
FROM test_table

just trying how this works

public func holabro(){
  a=1
  return ""
}
public class ThirdAngle {
    public static int otherAngle(int angle1, int angle2) {
       
        return 180-(angle1+angle2);
    }
}
char* Hi (void)
{char* ans;
asprintf(&ans, "Hello World.");
return ans;}
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.