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
Abstraction
Logic
IO
Mathematics
Algorithms
Numbers
Data Types

WIP

As a cashier, you must process a sum of money between £1 and £1000 and give back the lowest number of notes and coins available for the amount specified.

Rules

The availables notes are: £50, £20, £10, £5
The available coins are: £2, £1

Output

The method produceChange() will take an int as a parameter, and will return a string describing the given change.

Ex. 1)

produceChange(40)

Should return:

For £40 - change was 2 notes and 0 coins: 2x £20 note

Ex. 2)

produceChange(430)

Should return:

For £430 - change was 10 notes and 3 coins: 8 x £50 note, 1x £20 note, 1X £10 note

Numbers are always formatted correctly so checks for correct input are not required. Assume that the range is inclusively between 1 and 1000.

String output must also be sensibly readable for edge-case scenarios, e.g. "1 coin" is returned instead of "1 coins."

public class Cashier {


    private int fiftyNotes = 0;
    private int twentyNotes = 0;
    private int tenNotes = 0;
    private int fiveNotes = 0;

    private int cash = 0;

    private int twoPoundsCoins = 0;
    private int onePoundCoins = 0;

    private int totalNotes = 0;
    private int totalCoins = 0;

    public Cashier() {
    }


    public String produceChange(int cash) {

        this.cash = cash;

        while ((cash) > 49) {
            cash -= 50;
            fiftyNotes++;
            totalNotes++;
        }
        while ((cash) > 19) {
            cash -= 20;
            twentyNotes++;
            totalNotes++;
        }
        while ((cash) > 9) {
            cash -= 10;
            tenNotes++;
            totalNotes++;
        }
        while ((cash) > 4) {
            cash -= 5;
            fiveNotes++;
            totalNotes++;
        }
        while ((cash) > 1) {
            cash -= 2;
            twoPoundsCoins++;
            totalCoins++;
        }
        onePoundCoins = cash;
        totalCoins += onePoundCoins;

        return this.toString();

    }

    private void clear() {
        fiftyNotes = 0;
        twentyNotes = 0;
        tenNotes = 0;
        fiveNotes = 0;

        twoPoundsCoins = 0;
        onePoundCoins = 0;
        fiftyPence = 0;
        twentyPence = 0;
        tenPence = 0;
        fivePence = 0;
        twoPence = 0;
        onePence = 0;

        totalNotes = 0;
        totalCoins = 0;

    }

    public String toString() {

        StringBuilder sb = new StringBuilder("");

        if (fiftyNotes > 0) {
            sb.append(fiftyNotes + "x £50 note");
        }
        if (twentyNotes > 0) {
            sb.append((sb.length() > 0 ? ", " : "") + twentyNotes + "x £20 note");
        }
        if (tenNotes > 0) {
            sb.append((sb.length() > 0 ? ", " : "") + tenNotes + "x £10 note");
        }
        if (fiveNotes > 0) {
            sb.append((sb.length() > 0 ? ", " : "") + fiveNotes + "x £5 note");
        }
        if (twoPoundsCoins > 0) {
            sb.append((sb.length() > 0 ? ", " : "") + twoPoundsCoins + "x £2 coin");
        }
        if (onePoundCoins > 0) {
            sb.append((sb.length() > 0 ? ", " : "") + onePoundCoins + "x £1 coin");
        }


        String out =  "For £" + cash + " - change was "  + totalNotes  + (totalNotes == 1 ? " note and " : " notes and ")
                + totalCoins + (totalCoins == 1 ? " coin: " : " coins: ");

        clear();
        return out + sb.toString();
    }
}
Arrays
Data Types
Algorithms
Logic
Data

Find positive and negative integer pair in the array.

There is only one pair in the array.

Think about the performance.

[1,2,3,-2,4,5,6] -> [-2, 2]

[1,5,7,8,-2,3,-7] -> [-7, 7]
function pairs(arr){
  let sorted = arr.sort();
  let length = arr.length;

  for (let i = 0; i < length; i++) {
    if (sorted.includes(arr[i] * -1)) {
      return [sorted[i], sorted[i] * -1];
    }
  }
}
\ First Forth Kumite
: hw ." Hello World!" ;
hw cr

calculate the variance of the given vector

not sure how to get the unit tests working. or make it less obvious to the user

c(52,73,55,26,72,45,80,62,NA,7,NA,87,54,46,85,37,94)
Binary
Strings
Data Types
Encryption
Algorithms
Cryptography
Logic
Security

This is a string to binary and vice versa converter in python. The idea is that when the user enters a string into the function, a binary number for each character is returned.

e.g. hi --> 01101000 01101001

and 01101000 01101001 --> hi

Possible further applications could include something like containing code in a string and then executing it or just some fun encryption stuff.

def binary_converter(string):
    result = ""
    if string[0] != '0':
        for character in string:
            result += str(bin(ord(character))[2:].zfill(8)) 
            # So characters can be told apart
            result += " " if character != string[len(string) - 1] else ""
    else:
        # This does the opposite, converting 
        # the output of the above into the original input.
        store = [] # setting up list
        # Sorting numbers into individual items in the list
        for character in string:
            if character != ' ': 
                result += character  
            else: 
                store.append(result)
                result = ""
        store.append(result)
        result = ""
        
        # getting results, aka the orginal string
        for item in store:
            result += chr(int(item, 2))
    
    print(result) # for debugging
    return result

To celebrate the 50 year anniversary of the moon landing I've written some code to output my profile picture to the console!

Can you output your profile picture to the console?

function profilePicture() {
  distance = (x1, y1, x2, y2) => Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
  random = t => t[~~(Math.random() * t.length)];
  var width = 56, height = 32;
  var ratio = height / width;
  var grid = [...Array(height)].map(a => []);
  for (var x = 0; x < width; x++) {
    for (var y = 0; y < height; y++) {
      var isIncluded =
        distance(width * 0.5 * ratio, height * 0.50, (x+.5) * ratio, y + .5) < height * 0.47 &&
        distance(width * 0.6 * ratio, height * 0.45, (x+.5) * ratio, y + .5) >= height * 0.41;
      grid[y].push(isIncluded ? random("£@$%€0&#¥") : ' ');
    }
  }
  return grid.map(a => a.join``).join`\n`;
}

Check if word entred is a palindrome or not !

A palindrome is a word, phrase, number or sequence of words that reads the same backwards as forwards.

Exemples : WOW, 12321, Anna, ...

Programme return true or false.

using System;

class Palindrome
{
  public static bool Check(string word){
    for(int i = 0; i < word.Length; i++)
    {
        word = word.ToUpper();
        if(i >= word.Length /2)
        {
            break;
        }
        if(word[i] != word[word.Length - 1 - i])
        {
            return false;
        }
    }
    return true;
  }
}

Obtain previous number

object Previous {
  def previous(num: Int): Int =
    num-1
}

input two objects:
classroom={x:x1,y:y1};
teacher={x:x2,y:y2};
give another float d,
that is how long you shouts.
return 'fuck dude!'if the teachercannothear.
return 'shut up!'ifhe can hear out.
return 'sit well!'if he is in the classroom.
(i cannot say english so well.)

//
def function():
    answer=a*b
    return answer