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
Sorting
Algorithms
Logic

Create a function wich takes in a list of tuples which contain a name of a worker and their annualy salary and return a
tuple with the five workers with the highest salary in descending order. Unluckily for you, the salary of some workers is unknown and hence represented as "-". Those workers shouldn't be in your final tuple.

Examples:

Input: [("max", "20000"), ("jason", "40000"), ("christian", "70000"), ("carl", "50000")] => Output: ("christian", "carl", "jason", "max")

Input: [("worker0", "-"), ("stephy", "100000"), ("king", "10000")] => Output: ("stephy", "king")

Input: [("ironman", "20000"), ("batman", "15000"), ("kenobi", "150000"), ("mr. x", "40000"), ("spiderman", "75000"), ("ramsay", "115000")] =>
Output: ("kenobi", "ramsay", "spiderman", "mr. x", "ironman")

Happy coding :-)

def sort_by_salary(workers):
    filtered = list(filter(lambda x: x[1] != "-", workers))
    if not filtered:
        return tuple()
    new =  list(sorted(filtered, key=lambda x: int(x[1])))[::-1]
    return tuple(i[0] for i in new)[:5]

ax^2 + bx + c = 0
(Vietnamese)

//Usefull for grade 9 in VN
//I'm form VN :)
//Sorry I don't know much about English

//IamQuan :3

//Libraly
#include<iostream>
#include <math.h>
using namespace std;
//Code
//Ham Phu de goi an cho a b c
double GoiAn()
{
	double ABC{};
	std::cin >> ABC;
	return ABC;
}
//Code
int main()
{
	//Khai bao cho DK
	int A{};
	//Khai bao cho tinh toan
	double x1, x2;
//--------------------------------------------------
	// User nhap a b c
	cout << "Chuong trinh tinh phuong trinh bac 2 mot an\n";
	cout << "Vui long nhap cac he so a , b , c\n";
	cout << "---------------------------------------------" << endl;
	//Nhap he so a
	cout << "Nhap he so a: " ;
	double a{GoiAn()};

	//Dieu kien
	while (a == 0 && A < 1000)
	{
		cout << "Phuong trinh da chuyen ve \nphuong trinh bac nhat mot an" << endl;
		cout << "Ban co muon nhap lai ham so a ?\nNeu muon thi nhap lai.\na:" << endl;
		cin >> a;
		A++;
	}
	//Nhap he so b
	cout << "Nhap he so b: ";
	double b{ GoiAn() };

	//Nhap he so c
	cout << "Nhap he so c: ";
	double c{ GoiAn() };

	// Thong bao cho user
	cout << "Dang tinh delta va nghiem ......." << endl;
	
	//Khai bao Delta
	double delta{ (b * b) - 4 * a * c }; 
	 //Tinh delta
	if (delta < 0)
	{
		cout << "Delta = " << delta << "\n";
		cout << " => Phuong trinh vo nghiem " << endl;
	}
	else if (delta == 0)
	{
		cout << "Delta = " << delta << "\n";
		cout << " => Phuong trinh co nghiem kep " << endl;
	}
	else if (delta > 0)
	{
		cout << "Delta = " << delta << "\n";
		cout << " => Phuong trinh co 2 nghiem phan biet " << endl;
	}
	cout << "\n\n";

	//Tinh nghiem
	if (delta > 0)
	{
		x1 = (-b - sqrt(delta)) / (2 * a);
		x2 = (-b + sqrt(delta)) / (2 * a);

		cout << "Nghiem cua phuong trinh la: \n";
		cout << "x1 = " << x1 << endl;
		cout << "x2 = " << x2 << endl;
	}
	else if (delta == 0) {
		x1 = x2 = -b / (2 * a);
		cout << "Nghiem cua phuong trinh la: \n";
		cout << "x1 = x2 = " << x1 << endl;
	}
	else
	{
		cout << "Vi phuong trinh vo nghiem nen khong co nghiem" << endl;
	}
	system("pause");
	return 0;
}

Create a function called sort_names() which takes a string of names each separated by a space and returns them as a string with the names sorted and in title case. See below.

'Kate Amara Bob Justin' --> 'Amara Bob Justin Kate'
'kate amara bob justin' --> 'Amara Bob Justin Kate'
def sort_names(s):
    return ' '.join(sorted(s.title().split()))

Create a function to return True if the number is even and False if odd.

e.g. check_even(2) => True, check_even(9) => False

check_even = lambda x: x%2==0
Fundamentals
Puzzles
Games

Your task is to find the minimum SQUARE area in which you can place two identical rectangles. The sides of the rectangles should be parallel to the sides of the square.

  • You are given two identical rectangles with side lengths a and b with 1 <= a, b <= 100.
  • Find the square with minimum area that contains both given rectangles. Rectangles can be rotated (both or just one) and moved, but the sides of the rectangles should be parallel to the sides of the desired square.
def minimal_square(a, b):
    return max(min(a, b)*2, max(a, b))**2

Given an integer array and an positive integer variable, find the maximum or largest product you get after multiplying it by the elements in the array.

Input: arr = {1,2,3};
num = 3;
Output: 6
Because, 3 * 2 = 6

class Kata1 {
  public static int maxPairProduct(int[] arr, int num) {
    //Never Gonna Give You Up, Never Gonna Let You Down, Never Gonna Run Around And Desert You!
    
  }
}
Strings
Data Types
split
Haskell Packages

Basics

Verlan is a type of argot in the french language and is common in slang and youth language.
It rests on a long french tradition of transposing syllables of individual words to create slang words.
The word itself is an example for verlan.

Task

In this example you will create a function that takes a word and makes a verlan word out of it.

e.g.

  • Maestro => Stromae
  • Verlan => Lanver
function maestroSplit(string) {
  let newWord = string.slice(parseInt(string.length / 2)) + string.slice(0, parseInt(string.length / 2));
  return newWord.toLowerCase().charAt(0).toUpperCase() + newWord.toLowerCase().slice(1);
}

Given the following numbers:

100 75 50 25 6 3

and the following operators:

(*) (-) (+) (/)

build an Expression, that yields 952 when it is evaluated (evaluate applies all the operators bottom - up)

Doubles are used for convenience, number is rounded and checked against an integer to mitigate floating point error that might accumulate.

module Example (solve, Expression(Value, Expr)) where

data Expression = Value Double | Expr Expression (Double -> Double -> Double) Expression

solve :: [Double] -> Expression
--solve = undefined


--- my brute-force solution
solve xs = head . filter validate . allExpressions os . allOrders $ xs
  where os = getPermutationsAtDepth (length xs - 1) ops

evaluate :: Expression -> Double
evaluate (Value x) = x
evaluate (Expr i o j) = (evaluate i) `o` (evaluate j)

validate :: Expression -> Bool
validate = (==952) . round . evaluate

-- ok because all the numbers are unique
removed :: Eq a => a -> [a] -> [a]
removed x = filter (/=x)

allOrders :: Eq a => [a] -> [[a]]
allOrders [x] = [[x]]
allOrders xs = concat [ [ x:ns | ns <- allOrders (removed x xs)] | x <- xs]


ops = [(*), (-), (+), (/)] :: [Op]
type Op = Double -> Double -> Double

data NodeTree a = Node a [NodeTree a] | Leaf a deriving (Show)

genTree :: a -> [a] -> Int -> NodeTree a
genTree root es 1     = Node root (map Leaf es)
genTree root es depth = Node root (map (\x -> genTree x es (depth-1)) es)

getPaths :: NodeTree a -> [[a]]
getPaths (Leaf x)    = [[x]]
getPaths (Node r xs) = concat [ [ r:t | t <- getPaths c] | c <- xs]

getPermutationsAtDepth :: Int -> [a] -> [[a]]
getPermutationsAtDepth 1     xs = [xs]
getPermutationsAtDepth depth xs = concat . map getPaths . map (\x -> genTree x xs d) $ xs where d = depth - 1

toExpression :: [Op] -> [Double] -> Expression
toExpression _  []             = error "should not be more operators than values!"
toExpression [] [e]            = Value e
toExpression (o:os) (e:es) = Expr (Value e) o (toExpression os es)

allExpressions :: [[Op]] -> [[Double]] -> [Expression]
allExpressions os es = [toExpression o e | o <- os, e <- es]

Write a function that will solve a 9x9 Sudoku puzzle. The function will take one argument consisting of the 2D puzzle array, with the value 0 representing an unknown square.

The Sudokus tested against your function will be "easy" (i.e. determinable; there will be no need to assume and test possibilities on unknowns) and can be solved with a brute-force approach.

For Sudoku rules, see the Wikipedia article.


const int sudoku[9][9] = {
  {0,0,0,0,0,0,6,0,0},
  {0,0,0,0,0,7,0,0,1},
  {2,0,8,0,0,0,0,4,0},
  {6,0,0,0,0,0,0,0,0},
  {0,5,1,4,0,9,0,0,0},
  {0,0,0,5,0,0,0,2,0},
  {0,0,4,0,0,0,0,5,0},
  {0,0,7,1,9,6,0,0,0},
  {0,8,0,0,0,0,3,0,0},
};

#include <stddef.h>
typedef int (*T)[9];
T solve (const T sudoku) {
   /* Write your code here */
  return NULL;
}

test

public class test{
public void testSomething(){
  
  

}
  }