chiark / gitweb /
Initial import.
[rocl] / elite-prices
CommitLineData
1304202a 1#! /usr/bin/tclsh
2
3package require "elite" "1.0.0"
4
5# --- An optimal trading pair ---
6
7set lezaer "1598f98a6581"
8set esmaonbe "7997d18a0d89"
9
10set np [expr {[llength $products]/2}]
11puts -nonewline stderr "\[[string repeat { } $np]\] "
12puts -nonewline stderr "\[[string repeat { } 32]\]"
13puts -nonewline stderr "\r\[[string repeat { } $np]\] \["
14flush stderr
15foreach {a s} [list l $lezaer e $esmaonbe] {
16 for {set f 0} {$f < 256} {incr f} {
17 elite-market m $s $f
18 foreach {t p} $products { destructure [list ${a}($f:$t) .] $m($t) }
19 if {($f & 15) == 15} { puts -nonewline stderr "."; flush stderr }
20 }
21}
22foreach {t p} $products {
23 set tot($t) 0
24 set min($t) 100000
25 set max($t) -100000
26}
27set i 0
28foreach {t p} $products {
29 incr i
30 puts -nonewline stderr "\r\[[string repeat . $i]"
31 puts -nonewline stderr "[string repeat { } [expr {$np - $i}]]\] "
32 puts -nonewline stderr "\[[string repeat { } 32]\]"
33 puts -nonewline stderr "\r\[[string repeat . $i]"
34 puts -nonewline stderr "[string repeat { } [expr {$np - $i}]]\] \["
35 set ll {}
36 set ee {}
37 for {set f 0} {$f < 256} {incr f} {
38 lappend ll $l($f:$t)
39 lappend ee $e($f:$t)
40 }
41 set j 0
42 foreach pl $ll {
43 foreach pe $ee {
44 set pr [expr {$pl - $pe}]
45 if {$pr < $min($t)} { set min($t) $pr }
46 if {$pr > $max($t)} { set max($t) $pr }
47 incr tot($t) $pr
48 }
49 incr j
50 if {($j & 7) == 0} { puts -nonewline stderr "."; flush stderr }
51 }
52}
53puts stderr ""
54
55foreach {t p} $products {
56 puts [format "%-15s %5d %4d %4d" $t \
57 $min($t) [expr {$tot($t)/65536}] $max($t)]
58}