now with more details!

This commit is contained in:
Kistaro Windrider 2023-11-18 17:27:50 -08:00
parent d08ee55795
commit 117a5e9f2b
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

View File

@ -4,10 +4,21 @@ 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 {
@ -21,23 +32,54 @@ func main() {
log.Fatalf("can't run an auction with %d bidders", num)
}
price, bidder := auctionsim.RunAuction(
price, allBidders := auctionsim.RunAuctionVerbosely(
&auctionsim.CappedBidderGenerator{
G: auctionsim.NormalestBidderGenerator(),
Lim: num,
},
)
bidder := allBidders[len(allBidders)-1]
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 auction winner paid ¤%f. They have %s.\n", price, deltaStr(bidder.Value-price))
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())
fmt.Println()
i := len(allBidders) - 2
for i >= 0 && allBidders[i].Value < price {
i--
}
if i < 0 {
fmt.Printf("The item was not worth that to anybody.\n")
} else {
rube := allBidders[i]
fmt.Printf("The highest bidder who would have made a profit at that price stopped bidding at ¤%f.\n", rube.BidCeiling())
fmt.Printf("They should have kept bidding until ¤%f.\n", rube.Value)
if rankDelta := len(allBidders) - i - 1; rankDelta == 1 {
fmt.Println("They were outbid by 1 bidder.")
} else {
fmt.Printf("They were outbid by %d bidders.\n", rankDelta)
}
fmt.Printf("If they had paid the amount of the winning bid, they would have %s.\n", deltaStr(rube.Value-price))
}
fmt.Println()
maxValue := math.Inf(-1)
maxIdx := -1
for i, b := range allBidders {
if b.Value > maxValue {
maxValue = b.Value
maxIdx = i
}
}
if maxIdx == -1 {
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", len(allBidders)-maxIdx-1)
rube := allBidders[maxIdx]
fmt.Printf("The item was worth at most ¤%f to them. Their maximum bid was ¤%f.\n", rube.Value, rube.BidCeiling())
fmt.Printf("If they had paid the winning bid, they would have %s.\n", deltaStr(rube.Value-price))
}
}