Vogel's approximation method: Difference between revisions
→{{header|Go}}: Added second example.
(→{{header|Yabasic}}: Fixed bug carried over from C translation.) |
(→{{header|Go}}: Added second example.) |
||
Line 489:
Total cost = 3100
</pre>
If the program is changed as follows to accomodate the second Ruby example:
<lang go>package main
import (
"fmt"
"math"
)
var supply = []int{461, 277, 356, 488, 393}
var demand = []int{278, 60, 461, 116, 1060}
var costs = make([][]int, nRows)
var nRows = len(supply)
var nCols = len(demand)
var rowDone = make([]bool, nRows)
var colDone = make([]bool, nCols)
var results = make([][]int, nRows)
func init() {
costs[0] = []int{46, 74, 9, 28, 99}
costs[1] = []int{12, 75, 6, 36, 48}
costs[2] = []int{35, 199, 4, 5, 71}
costs[3] = []int{61, 81, 44, 88, 9}
costs[4] = []int{85, 60, 14, 25, 79}
for i := 0; i < len(results); i++ {
results[i] = make([]int, nCols)
}
}
// etc
func main() {
// etc
fmt.Println(" A B C D E")
for i, result := range results {
fmt.Printf("%c", 'V'+i)
for _, item := range result {
fmt.Printf(" %3d", item)
}
fmt.Println()
}
fmt.Println("\nTotal cost =", totalCost)
}</lang>
then the output, which agrees with the C and Phix output but not with the Ruby output itself, is:
<pre>
A B C D E
V 0 0 461 0 0
W 277 0 0 0 0
X 1 0 0 0 355
Y 0 0 0 0 488
Z 0 60 0 116 217
Total cost = 60748
</pre>
|