Begin a new Kumite
Search
About
  • Filter by Language:
  • 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.

Code
Diff
  • returnhundred=Ϡ=>
    `                                                                                                   
    `
    .
    length
  • 1-function returnhundred() {
    2-return 10 ** 2;
    3-}
    1+returnhundred=Ϡ=>
    2+`
    3+`
    4+.
    5+length
Abstraction
IO
Mathematics
Algorithms
Numbers

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();
    }
}
Binary
Strings
Encryption
Algorithms
Cryptography
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

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)

What if we couldn't use a standard function because the order of parameters wasn't the same?

Code
Diff
  • from operator import contains
    common_substring = lambda a, b: contains(b, a)
  • 1-from operator import contains as common_substring
    1+from operator import contains
    2+common_substring = lambda a, b: contains(b, a)
\ First Forth Kumite
: hw ." Hello World!" ;
hw cr
Code
Diff
  • public class BiggerNum{
    
      public static int compare(int a, int b) {
        return a>b ? a : b;
      }
    
    }
  • 11 public class BiggerNum{
    22
    33 public static int compare(int a, int b) {
    4- return (a>b) ? a : b;
    4+ return a>b ? a : b;
    55 }
    66
    77 }
Code
Diff
  • \ Test Framework (ttester + extension)
    decimal
    s" test/ttester.fs" included
    
    : #ms ( dmicroseconds -- len c-addr ) <# # # # [char] . hold #s #> ;
    
    : describe#{ ( len c-addr -- ) cr ." <DESCRIBE::>" type cr utime ;
    : it#{ ( len c-addr -- ) cr ." <IT::>" type cr utime ;
    : }# ( -- ) utime cr ." <COMPLETEDIN::>" 2swap d- #ms type ."  ms" cr ;
    
    create EXPECTED-RESULTS 32 cells allot
    variable RESULTS
    variable DIFFERENCES
    
    : <{ T{ ;
    : }>
      depth ACTUAL-DEPTH @ = if
        depth START-DEPTH @ > if
          depth START-DEPTH @ - dup RESULTS ! 0 do
            dup EXPECTED-RESULTS i cells + !
            ACTUAL-RESULTS i cells + @ <> DIFFERENCES +!
          loop
    
          DIFFERENCES @ if
            cr ." <FAILED::>expected: "
            RESULTS @ 0 do EXPECTED-RESULTS i cells + @ . loop
            ." <:LF:>  actual: "
            RESULTS @ 0 do ACTUAL-RESULTS i cells + @ . loop
            cr
    
          else
            cr ." <PASSED::>Test Passed" cr
          then
        then
      else
        cr ." <FAILED::>Wrong number of results. Expected:<:LF:>" ACTUAL-DEPTH @ . ." <:LF:>got:<:LF:>" depth . cr
      then
    F} ;
    
    \ Solution
    : solution ( a b -- a*b ) * ;
    
    \ Tests
    s" Basic Tests" describe#{
      s" zeros" it#{
        <{ 0 0 solution -> 0 }>
        <{ 0 1 solution -> 0 }>
        <{ 1 0 solution -> 0 }>
      }#
    
      s" non-zeros" it#{
        \ intentionally broken tests
        \ <{ 1 1 solution -> 2 }>
        \ <{ 3 5 solution -> 8 }>
        <{ 1 1 solution -> 1 }>
      }#
    }#
  • 4747 <{ 0 1 solution -> 0 }>
    4848 <{ 1 0 solution -> 0 }>
    4949 }#
    5050
    5151 s" non-zeros" it#{
    5252 \ intentionally broken tests
    53- <{ 1 1 solution -> 2 }>
    54- <{ 3 5 solution -> 8 }>
    53+ \ <{ 1 1 solution -> 2 }>
    54+ \ <{ 3 5 solution -> 8 }>
    55+ <{ 1 1 solution -> 1 }>
    5555 }#
    5656 }#