package main import ( "fmt" "git.chromaticdragon.app/kistaro/auctionsim/auctionsim" "log" "math" "os" "strconv" ) func deltaStr(delta float64) string { if delta > 0 { return fmt.Sprintf("gained ¤%f", delta) } if delta < 0 { return fmt.Sprintf("lost ¤%f", -delta) } return "broken even" } func main() { num := int64(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) } result := auctionSim.Summarize(auctionsim.RunAuctionVerbosely( &auctionsim.CappedBidderGenerator{ G: auctionsim.NormalestBidderGenerator(), Lim: num, }, )) fmt.Printf("The auction winner paid ¤%f. They have %s.\n", summary.Price, deltaStr(summary.WinnerProfit)) fmt.Printf("The item was worth ¤%f to them.\n", summary.WinnerValue) fmt.Printf("They would have paid up to ¤%f for it.\n", summary.WinnerMaxBid) fmt.Println() if summary.LosersWithRegrets < 1 { fmt.Println("The item was not worth that to anybody.") } else { fmt.Printf("The item was worth that to %d bidders, who stopped bidding too soon.\n", summary.LosersWithRegrets) } fmt.Println() if summary.HighestValueRank > summary.Bidders { fmt.Println("Wow! It was infinitely beyond worthless to everybody.") } else { fmt.Printf("The bidder who would have gotten the most value was outbid by %d bidders.\n", summary.HighestValueRank-1) fmt.Printf("The item was worth at most ¤%f to them. Their maximum bid was ¤%f.\n", summary.HighestValue, summary.HighestValuatorBid) fmt.Printf("If they had paid the winning bid, they would have %s.\n", deltaStr(summary.MissedProfit)) fmt.Printf("They valued it ¤%f more than the winning bidder.\n", summary.ValueDelta) } }