This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def bellman_ford(graph, source): | |
| # Step 1: Prepare the distance and predecessor for each node | |
| distance, predecessor = dict(), dict() | |
| for node in graph: | |
| distance[node], predecessor[node] = float('inf'), None | |
| distance[source] = 0 | |
| # Step 2: Relax the edges | |
| for _ in range(len(graph) - 1): | |
| for node in graph: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Tuple, List | |
| from math import log | |
| rates = [ | |
| [1, 0.23, 0.25, 16.43, 18.21, 4.94], | |
| [4.34, 1, 1.11, 71.40, 79.09, 21.44], | |
| [3.93, 0.90, 1, 64.52, 71.48, 19.37], | |
| [0.061, 0.014, 0.015, 1, 1.11, 0.30], | |
| [0.055, 0.013, 0.014, 0.90, 1, 0.27], | |
| [0.20, 0.047, 0.052, 3.33, 3.69, 1], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*USAGE: | |
| npm install ws lodash async moment crc-32 | |
| mkdir logs | |
| node bfx_test_book.js BTCUSD | |
| */ | |
| const WS = require('ws') | |
| const _ = require('lodash') | |
| const async = require('async') | |
| const fs = require('fs') |