Page 1 of 1

The Ultimate Currency Converter

Posted: Fri Aug 02, 2013 9:52 am
by Njall
From here:
Elk Eater wrote:I've been considering putting together an application that takes three inputs:

1) Buyer's cash on hand

2) Seller's cash on hand

3) Total cash to be traded

Which would then output a solution of deeds from the buyer + deeds (change) from the seller to come as close as possible to a net change in cash to be traded.

A simple (and unlikely) example would be Buyer 1 owes buyer two 8,300 gp. They each have 300k in their banks. After filling in 1) 300k, 2) 300k and 3) 8,300, the application would instruct the buyer to get a large brick deed, and the seller a patio deed, and trade.
1. Go to http://ideone.com/clone/rpKfLF
2. Enter [cash to be traded] [payer's cash on hand] [receiver's cash on hand] into input field.
3. Press Submit.
4. Scroll down to the bottom of the page.
5. PROFIT!!!

Examples:

Code: Select all

input:
20k 200k 200k
output:
Alice wants to pay 20000 to Bob.
Alice pays
    Patio
Bob pays
    3 Small + 1400 gp

Code: Select all

input:
20,000 500,000 400,000
output:
Alice wants to pay 20000 to Bob.
Alice pays
    2 L-Shape
Bob pays
    Large Brick + 5 Small + 1300 gp

Code: Select all

input:
20'000 600'000 600'000
output:
Alice wants to pay 20000 to Bob.
Alice pays
    3 Patio
Bob pays
    10 Small + 400 gp

Code: Select all

input:
20k 1m 2kk
output:
Alice wants to pay 20000 to Bob.
Alice pays
    2 L-Shape + 3 Patio + Small
Bob pays
    6 Large Brick
You can see the more reserves you have, the less gps you need to transfer.

It can be also used with one input, like Wil's tables:

Code: Select all

input:
300k
output:
Alice wants to pay 300000 to Bob.
Alice pays
    Patio + Large Brick + 2700 gp

Code: Select all

input:
10M
output:
Alice wants to pay 10000000 to Bob.
Alice pays
    6 Castle + 4 Keep + 5 L-Shape + Patio + 2 Small
The script minimizes amount of insecure gp transfer first, then the total number of deeds traded. It understands k, kk, m, b notation and digit group separators. You can press 'upload with new input' --> 'ideone it' to speed up process a little. If you are hitting 5 seconds time limit you are probably too rich. :) Register at ideone.com to increase the limit or just run the script locally.

More random examples:

Code: Select all

input:
12345 500k 500k
output:
Alice wants to pay 12345 to Bob.
Alice pays
    L-Shape + Patio
Bob pays
    2 Large Brick + Small + 55 gp

Code: Select all

input:
7300 300k 300K
output:
Alice wants to pay 7300 to Bob.
Alice pays
    Patio
Bob pays
    Large Brick + 1000 gp
Please post suggestions and bug reports (if any).

Re: The Ultimate Currency Converter

Posted: Fri Aug 02, 2013 11:40 am
by Populus
Very impressive, good job!

Re: The Ultimate Currency Converter

Posted: Fri Aug 02, 2013 10:25 pm
by Hicha
Excellent job on this, I don't think people appreciate how pain in the ass a sort algorithm can be.