The Ultimate Currency Converter

Moderator: Trade Moderators

Post Reply
Njall
Posts: 1
Joined: Thu Jul 18, 2013 7:18 pm

The Ultimate Currency Converter

Post 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).

User avatar
Populus
Posts: 2223
Joined: Tue Jul 14, 2009 8:01 am
Location: Sweden

Re: The Ultimate Currency Converter

Post by Populus »

Very impressive, good job!
ImageImageImage
[cA]

Hicha
UOSA Donor!!
UOSA Donor!!
Posts: 2264
Joined: Tue May 05, 2009 10:03 am
Location: out selling permits

Re: The Ultimate Currency Converter

Post by Hicha »

Excellent job on this, I don't think people appreciate how pain in the ass a sort algorithm can be.
Image
"I consider most of you NPC's that inhabit the single player game that I am here to enjoy." - MatronDeWinter

Post Reply

Return to “Traders Discussion”