Compare commits
2 Commits
f151a9ad76
...
0a7dd54597
Author | SHA1 | Date | |
---|---|---|---|
0a7dd54597 | |||
67432448cf |
43
main/main.go
Normal file
43
main/main.go
Normal file
@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"git.chromaticdragon.app/kistaro/auctionsim/auctionsim"
|
||||
)
|
||||
|
||||
func main() {
|
||||
num := 1000
|
||||
if len(os.Args) > 1 {
|
||||
n, err := strconv.ParseInt(os.Args[1], 0, 64)
|
||||
if err != nil {
|
||||
log.Fatalf("can't parse %q as a number of bidders: %v", os.Args[1], err)
|
||||
}
|
||||
num = n
|
||||
}
|
||||
if num <= 1 {
|
||||
log.Fatalf("can't run an auction with %d bidders", num)
|
||||
}
|
||||
|
||||
price, bidder := auctionsim.RunAuction(
|
||||
auctionsim.CappedBidderGenerator{
|
||||
G: auctionsim.NormalestBidderGenerator(),
|
||||
Lim: num,
|
||||
},
|
||||
)
|
||||
|
||||
delta := bidder.Value - price
|
||||
valueStr := "gaining nothing"
|
||||
if delta > 0 {
|
||||
valueStr = fmt.Sprintf("gaining ¤%f", delta)
|
||||
}
|
||||
if delta < 0 {
|
||||
valueStr = fmt.Sprintf("losing ¤%f", -delta)
|
||||
}
|
||||
|
||||
fmt.Printf("The auction winner paid ¤%f, %s.\n", price, valueStr)
|
||||
fmt.Printf("The item was worth ¤%f to them.\n", bidder.Value)
|
||||
fmt.Printf("They would have paid up to ¤%f for it.\n", bidder.BidCeiling())
|
||||
}
|
Loading…
Reference in New Issue
Block a user