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

[Please, leave a feedback when you complete it or this will always stay in beta and you will not earn language points].

Print all numbers up to 3rd parameter which are multiple of both 1st and 2nd paramater.

#!/bin/bash
for i in $(eval echo {1..$3});
do
if [ `expr $i % $1` -eq 0 -a `expr $i % $2` -eq 0 ]
then
echo $i
fi
done

Suzuki needs help lining up his students!

Today Suzuki will be interviewing his students to ensure they are progressing in their training. He decided to schedule the interviews based on the length of the students name in descending order. The students will line up and wait for their turn.

You will be given a string of student names. Sort them and return a list of names in descending order.

Here is an example input:

string = 'Tadashi Takahiro Takao Takashi Takayuki Takehiko Takeo Takeshi Takeshi'
Here is an example return from your function:

lst = ['Takehiko',
'Takayuki',
'Takahiro',
'Takeshi',
'Takeshi',
'Takashi',
'Tadashi',
'Takeo',
'Takao']
Names of equal length will be returned in reverse alphabetical order (Z->A) such that:

string = "xxa xxb xxc xxd xa xb xc xd"
Returns

['xxd', 'xxc', 'xxb', 'xxa', 'xd', 'xc', 'xb', 'xa']

using System;
using System.Linq;   

 public class Kata
    {
        public static string[] LiningUpHisStudents(string s)
        {
            var query = s.Split(' ').OrderByDescending(x => x.Length).ThenByDescending(x => x).ToArray();
            return query;
        }
    }

Given a start date and end date, find a list of dates with the format of month, day year, that is the same forward as it is backward. For example, the date October 2, 2001 is a palindrome because in MMDDYYYY format, this date is 10022001 and in YYYYDDMM format the date is 10022001. Your task is to find all the palindrome dates for any given start and end date.

The method that calculates this should take two Date types, one for the start date and one for the end date. The method should return a Set of Date types that is sorted chronologically and has no duplicates.

package com.mystuff.juststuff;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TreeSet;

public class Palindrome
{
	SimpleDateFormat sdf;
	
	public Palindrome()
	{
		this.sdf = new SimpleDateFormat("MMddyyyy");
		sdf.setLenient(false);
	}

	public TreeSet<Date> countDatePalindromes(Date startDate, Date endDate)
	{
		TreeSet<Date> palSet = new TreeSet<Date>();
		GregorianCalendar startCal = new GregorianCalendar();
		GregorianCalendar endCal = new GregorianCalendar();

		if (startDate.getTime() > endDate.getTime())
		{
			// end date is chronologically before start date. flip them.
//			System.out.println("end is before start. must flip. start: " + sdf.format(startDate.getTime()) + " end: " + sdf.format(endDate.getTime()));
			startCal.setTime(endDate);
			endCal.setTime(startDate);
		}
		else
		{
			// start date is chronologically prior to end date. just set the calendars as such.
			startCal.setTime(startDate);
			endCal.setTime(endDate);
		}

//		System.out.println("start should be before end. start: " + sdf.format(startCal.getTime()) + " end: " + sdf.format(endCal.getTime()));

		String regularDate = null;
		String palDate = null;
		while ( (startCal.before(endCal)) || (startCal.equals(endCal)) )
		{
			regularDate = sdf.format(startCal.getTime());
			palDate = palindromify(startCal.getTime());
			
			if (regularDate.equals(palDate))
			{
				// a date palindrome was found
//				System.out.println("Found one! regular: " + regularDate + " palindrome: " + palDate);
				palSet.add(startCal.getTime());
			}
			
			startCal.add(Calendar.DAY_OF_MONTH, 1);
		}
		
//		System.out.println("I found " + palSet.size() + " palindromes");
		
		return palSet;
	}
	
	private String palindromify(final Date arg)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("MMddyyyy");
		sdf.setLenient(false);
		StringBuffer palBuff = new StringBuffer(8);
		String pal = sdf.format(arg);
		
		for (int i = pal.length(); i >= 1; i--)
		{
			palBuff.append(pal.charAt(i - 1));
		}
		
		return palBuff.toString();
	}

}

Help Suzuki purchase his Tofu!

Suzuki has sent a lay steward to market who will purchase some items not produced in the monastary gardens for the monks. The stewart has with him a large box full of change from donations earlier in the day mixed in with some personal items. You will be given a string of items representing the box.

Sort through the items in the box finding the coins and putting aside anything else.

You will be given a data structure similar to the one below.

box = "mon mon mon mon mon apple mon mon mon mon mon mon mon monme mon mon monme mon mon mon mon cloth monme mon mon mon mon mon mon mon mon cloth mon mon monme mon mon mon mon monme mon mon mon mon mon mon mon mon mon mon mon mon mon";

Return the following in your solution.

[count of mon coins in box, count of monme coins in box,sum of all coins value in box, minimum number of coins needed for Tofu]

100 ≤ cost ≤ 1000

cost = 124

returns

[45, 5, 345, 6]
The coins have the following values:

monme = 60

mon = 1

Determine the minimum number of coins to pay for tofu. You must pay with exact change and if you do not have the correct change return “leaving the market”.

NOTE !!!!! for c# solution Just return -> int[] {0};

If the cost of tofu is higher than your total amount of money also return “leaving the market”

using System;
using System.Linq;  

public class Kata
    {
        public static int[] PurchaseTofu(int cost, string box)
        {
              var monCount = box.Split(' ').Count(x => x == "mon");
            Console.WriteLine(monCount);
            var monmeCount = box.Split(' ').Count(x => x == "monme");
            var TotalValue = monCount + (monmeCount * 60);
            int NumberOfMonmeUsed = 0;
            int NumberOfMonUsed = 0;
            int NeverChangeCost = cost;

            var monCounter = monCount;
            var monmeCounter = monmeCount;

            while(cost >= 60 && monmeCounter > 0)
            {
                NumberOfMonmeUsed = NumberOfMonmeUsed + 1;
                cost = cost - 60;
                monmeCounter--;
            }

            while (cost >= 1 && monCounter > 0)
            {
                NumberOfMonUsed = NumberOfMonUsed + 1;
                cost = cost - 1;
                monCounter--;
            }

            var TotalCoinsUsed = NumberOfMonmeUsed + NumberOfMonUsed;

            var test = (NumberOfMonmeUsed * 60) + NumberOfMonUsed;

            if (test != NeverChangeCost)
            {
                Console.WriteLine("Leaving the market");
                return new int[] {0};
            }

            Console.WriteLine($"[{monCount}, {monmeCount}, {TotalValue}, {TotalCoinsUsed}]");
            return new int[] { monCount, monmeCount, TotalValue, TotalCoinsUsed };
        }
    }

Caesar-cipher (obfuscated, golfed)

sub c{map{chr($_[0]+ord)}split'',$_[1]}

Try to return the File Extension from the provided arguement.

#!/bin/bash
file1=$1; echo ${file1##*.}

Make a Function that returns a comma separated list in the order of

"DirectoryName, Filename, FileExtension"

#!/bin/bash
filename=$1
echo "$(dirname $filename), $(basename ${filename%.*}), ${filename##*.}"

Find the number that only odd times form an array.

For example:

findOnlyOddTimesNumber([1,1,1,2,3,4,2,4,2,1,3]); // 2 
const findOnlyOddTimesNumber = arr => arr.reduce((p,c) => p^c);

findOnlyOddTimesNumber([1,1,1,2,3,4,2,4,2,1,3]);

This is how you prevent the user from importing certain modules in your kata.

import sys
sys.modules['module name'] = None

Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.

For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 × 53 = 49714.

What is the total of all the name scores in the file?

function nameScores(names) {
  var t1 = console.time("names");;
  names.sort();
  var sum = 0;
  var index = 1;
  for (var name = 0; name < names.length; name++) {
    var nameSum = 0;
    for (var character = 0; character < names[name].length; character++) {
      nameSum += (names[name][character].charCodeAt(0) - 64);
    }
    sum += (nameSum * index);
    index++;
  }
  var t2 = console.timeEnd('names');
  return sum;
}