The idea of the triangle_arbitrage file is derived from the UVa OJ 104. I have extended the problem by involving the bid ask spread  mechanism to simulate a more realistic situation.