## Currency exchange rate

STDIN contains the exchange rate of 1 USD against other currencies. STDOUT should contain a cross-table relationships each currency for each. The columns should be sorted the same way as in the original list, table cells should be separated by two spaces.

IN

1 USD 0.82 EUR 1.23 AUD 0.99 CHF 1.32 SGD 52.03 RUB

OUT

\ USD EUR AUD CHF SGD RUB USD 1 0.82 1.23 0.99 1.32 52.03 EUR 1.22 1 1.50 1.21 1.61 63.45 AUD 0.81 0.67 1 0.80 1.07 42.30 CHF 1.01 0.83 1.24 1 1.33 52.56 SGD 0.76 0.62 0.93 0.75 1 39.42 RUB 0.02 0.02 0.02 0.02 0.03 1

IN

1 USD 0.82 EUR

OUT

\ USD EUR USD 1 0.82 EUR 1.22 1

IN

1 USD

OUT

\ USD USD 1

Getting the rounding correct is difficult in this task. I'm often out by 0.01

Mon Dec 29 04:16:06 2014

Yes, can you explain why EUR/RUB is 62.96? I would calculate 52.03/0.82, so it would be 63.45... when do I have to round?

Mon Dec 29 14:15:27 2014

PFischbeck, the method of conversion used has introduced a rounding error.

For example EUR to RUB: 1 USD is 0.82 EUR is 52.03 RUB so the calculation is:

( 1 / 0.82 ) * 52.03

( 1 / 0.82 ) = 1.2195......

This value was truncated to get 1.21 (when perhaps it should be rounded to make 1.22) So the calculation with the largest error (the test result) is: 1.21 * 52.03 = 62.9563 The calculation to the nearest hundredth is: 1.22 * 52.03 = 63.4766 The calculation that gives you your 63.45 is more like: 1.219512 * 52.03 = 63.4512...

Or simplifying the maths, multiplying by the reciprocal of 0.82 is as good as dividing by 0.82: 52.03 / 0.82 = 63.4512....

I'd say the test results are a little harsh.

Mon Dec 29 14:56:29 2014

Sorry, spacing was bad on previous comment:

PFischbeck, the method of conversion used has introduced a rounding error.

For example EUR to RUB: 1 USD is 0.82 EUR is 52.03 RUB so the calculation is:

( 1 / 0.82 ) * 52.03

( 1 / 0.82 ) = 1.2195......

This value was truncated to get 1.21 (when perhaps it should be rounded to make 1.22)

So the calculation with the largest error (the test result) is:

1.21 * 52.03 = 62.9563

The calculation to the nearest hundredth is:

1.22 * 52.03 = 63.4766

The calculation that gives you your 63.45 is more like:

1.219512 * 52.03 = 63.4512...

Or simplifying the maths, multiplying by the reciprocal of 0.82 is as good as dividing by 0.82:

52.03 / 0.82 = 63.4512....

I'd say the test results are a little harsh.

Mon Dec 29 14:58:26 2014

Sorry for mistake. I've corrected the tests, now all is well (I hope).

Mon Dec 29 16:03:33 2014

There is a typo in the first test case: it should be "SGD", not "SDG".

Mon Dec 29 17:26:59 2014

Agreed, I have a solution but it won't be accepted. SDG is incorrect in test one.

Mon Dec 29 19:50:26 2014

Sorry :( Fixed again

Mon Dec 29 20:05:10 2014

Leave a comment

Parsed as Markdown