Compare commits

...

2 Commits

Author SHA1 Message Date
0a7dd54597
add missing newline 2023-11-18 16:50:59 -08:00
67432448cf
very basic UI 2023-11-18 16:50:53 -08:00

43
main/main.go Normal file
View 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())
}