diff --git a/main/main.go b/main/main.go new file mode 100644 index 0000000..fafda71 --- /dev/null +++ b/main/main.go @@ -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()) +} \ No newline at end of file