Skip to content

Commit

Permalink
add variable for num_bidders
Browse files Browse the repository at this point in the history
  • Loading branch information
oceans404 committed Oct 10, 2024
1 parent 07844f0 commit ac52a6b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/auction_can_tie.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ def nada_main():
auctioneer = Party(name="auctioneer")

# Create a list of 5 bidders participating in the auction, 'bidder_0' to 'bidder_4'
bidders = [Party(name=f"bidder_{i}") for i in range(5)]
num_bidders = 5
bidders = [Party(name=f"bidder_{i}") for i in range(num_bidders)]

# Collect bids from each bidder, where each bid is a SecretInteger input unique to the respective bidder
bids = [SecretInteger(Input(name=f"bid_{i}", party=bidders[i])) for i in range(5)]
bids = [SecretInteger(Input(name=f"bid_{i}", party=bidders[i])) for i in range(num_bidders)]

# Determine the highest bid among all the bidders
# Start by initializing the highest bid to the first bidder's bid
highest_bid = bids[0]
# Iterate through the remaining bids to update the highest bid if a higher one is found
for i in range(1, 5):
for i in range(1, num_bidders):
is_higher = bids[i] > highest_bid
highest_bid = is_higher.if_else(bids[i], highest_bid)

# Create a list of outputs for each bidder, indicating if their bid matches the highest bid
# Each output is a flag (1 if the bid matches the highest bid, 0 otherwise), visible to the auctioneer
placed_highest_bid = [
Output((bids[i] == highest_bid).if_else(Integer(1), Integer(0)), f"bidder_{i}_placed_highest_bid", auctioneer)
for i in range(5)
for i in range(num_bidders)
]

# Return the highest bid and a list of flags indicating which bidders placed the highest bid
Expand Down

0 comments on commit ac52a6b

Please sign in to comment.