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

Code returns the int that is different from all other ints in an array. Function takes odd size array that contains all the same ints except for 1

int stray(std::vector<int> numbers) {
    
    for(auto n = numbers.begin(); n != numbers.end(); ++n ){
        if (*n != numbers[0]) {
            if (*n != *(n + 1))
                return *n;
            else
                return numbers[0];
        }
    }
};

Sometimes one has a vector with pairs (key, value), where one wants to fold over all the values with the same key.
What is the best way to do that in Rust?

The example uses a vector, but perhaps it would be better with an iterator as argument, to make it more general?

fn reduce<TK, TV, TS, F>(v : Vec<(TK, TV)>,
                     s : TS,
                     f : F) -> Vec<(TK, TV)>
                     where F : Fn(TS, TV) -> TS {
    // Code
    vec![]
}

Array and looping are in old-love story . Tonight we gonna play the game by separae them . given integer array , we want to sort it without the use of any kind of arrays .

Hint ::
You can write it in one line - Code

def sortinggggggggggg (arr) :
  Soreteddddd = sorted (arr)
  return Soreteddddd
sortinggggggggggg ([2,0,25,3])

Kumite Experiment!

public class HelloWorld 
{

  public static int Execute()
  {
    System.out.println("My first Kumite");
    return 1;
  }
}

given we are anonymous
then should say "Hello World!"

given we are "McFly"
then should say "Hello McFly!"

function sayHello() {
}
ES2015
Babel
Objects
Data Types

Function 'pick' in the Underscore.js (http://underscorejs.org/#pick)

"Return a copy of the object, filtered to only have values for the whitelisted keys (or array of valid keys). Alternatively accepts a predicate indicating which keys to pick."

_.pick({name: 'moe', age: 50, userid: 'moe1'}, 'name', 'age');
// {name: 'moe', age: 50}

_.pick({name: 'moe', age: 50, userid: 'moe1'}, function(value, key, object) {
  return typeof value == 'number';
});
// {age: 50}
var _ = {};

_.pick = (target, ...keys) => {
  if (typeof keys[0] == 'function') {
    var predicate = keys[0];
    keys = Object.keys(target);
    
    return keys.reduce((obj, key) => {
      return predicate(target[key], key, target) ? (obj[key] = target[key], obj) : obj;
    }, {})
  }

  return keys.reduce((obj, key) => {
    return obj[key] = target[key], obj;
  }, {});
};

If it does not work, just say :).

template<typename T>
T add(T a, T b){
	return a-(-b);
}
bool Or(bool a, bool b){
	if(!a){
		if(!b){
			return false;
		}
	}
	return true;
}

bool Xor(bool a, bool b){
	return a != b;	
}

bool And(bool a, bool b){
	if(a){
		if(b){
			return true;
		}
	}
	return false;
}

Parses an expression.

def parse(expr): #The main parser
  ps = 0 #Number of open parentheses
  cval = 0 #Current value
  op = "+" #Current operation
  accum = "" #Accumulating value
  for i in range(len(expr)):
    c = expr[i]
    if c in ["+","-"] and not ps: #Operation not inside parens
      if op=="+": #Addition
        cval+=parse_fact(accum)
      else: #Subtraction
        cval-=parse_fact(accum)
      accum = "" #Reset the value
      op = c #New operation once that was calculated
    else:
      if c=="(": ps+=1 #Open paren
      if c==")": ps-=1 #Close paren
      accum+=c #Add a character to accumulating value
  if op=="+": #Do the operation one more time
    cval+=parse_fact(accum)
  else:
    cval-=parse_fact(accum)
  return cval
def parse_fact(term):
  ps = 0
  cval = 1
  op = "*"
  accum = ""
  for i in range(len(term)):
    c = term[i]
    if c in ["*","/"] and not ps:
      if op=="*":
        cval*=parse_val(accum)
      else:
        cval/=parse_val(accum)
      accum = ""
      op = c
    else:
      if c=="(": ps+=1
      if c==")": ps-=1
      accum+=c
  if op=="*":
    cval*=parse_val(accum)
  else:
    cval/=parse_val(accum)
  return cval
def parse_val(val):
  if val[0] == "(": #Parenthetical expression
    return parse(val[1:-1]) #Cut off parentheses and reevaluate
  else:
    return float(val) #Not parenthetical

Takes the square root of an int and returns a double.

double sqrt (int a,int accuracy=20) {
  double out = a;
  for(int i=0;i<accuracy;i++) {
    out = (out+a/out)/2;
  }
  return out;
}