Random Algorithm Popcorn hacks
Popcorn Hack 1
What is a random algorithm?
A random algorithm is a set of steps that uses random choices.
It can give different results each time, even with the same input.
Why use random algorithms?
- They can be used in games to change what happens each time.
- They can be used in simulations to act like real life.
- They help with security by making passwords or data harder to guess.
- They make things fair when picking people or items.
- They can help solve hard problems by trying different answers quickly.
What kind of question might the College Board ask?
The College Board might ask what a random algorithm does, why it is used, or what its result could be.
Popcorn Hack 2
import random
# Step 1: Define a list of activities
activities = ['Watch a TV Show', 'Read somethingk', 'Talk to a friend', 'Try cooking', 'Watch a movie', 'Go to sleep', 'Go to the gym', 'Write something', 'Bike', 'Listen to music', 'Play a video game','Do homework']
random_activity = random.choice(activities)
# Step 3: Display the chosen activity
print(f"Today’s random activity: {random_activity}")
Today’s random activity: Go to sleep
Popcorn hack 3
import random
# Step 1: Define the list of hosts and activities
hosts = ['Rayhaan','Gyutae','Derek']
activities = ['music', 'food', 'decorations', 'games', 'movies']
# Step 2: Randomly shuffle the list of activities
random.shuffle(activities)
# Step 3: Loop through each host and assign them a random activity
for i in range(len(hosts)):
print(f"{hosts[i]} will be monitoring {activities[i]}!")
Rayhaan will be monitoring games!
Gyutae will be monitoring decorations!
Derek will be monitoring music!
Simulation Games Popcorn Hacks
Popcorn Hack 1
import random
def spin_number():
return random.randint(1, 10)
spinner_result = spin_number()
print("Spinner landed on:", spinner_result)
Spinner landed on: 1
Popcorn Hack 2
import random
def play_rock_paper_scissors():
choices = ['rock', 'paper', 'scissors']
computer_choice = random.choice(choices)
user_choice = input("Enter your choice (rock, paper, or scissors): ")
if user_choice not in choices:
print("Invalid choice. Please try again.")
return
print("Computer chose:", computer_choice)
print("You chose:", user_choice)
if user_choice == computer_choice:
print("It's a tie!")
elif (user_choice == 'rock' and computer_choice == 'scissors') or (user_choice == 'paper' and computer_choice == 'rock') or (user_choice == 'scissors' and computer_choice == 'paper'):
print("You win!")
else:
print("You lose!")
play_rock_paper_scissors()
Computer chose: rock
You chose: paper
You win!
MC Questions
Question 1
C: 3 1 2 because 3 cannot be printed
Question 2
D: RANDOM, open parenthesis 1 comma 100, close parenthesis, is less than or equal to 75; this makes the output have a 75% chance
Question 3
C: Removing as many details from the model as possible so that calculations can be performed quickly; won’t be accurate
Question 4
D: The number of predators does not change from day to day; The predators don’t change after the start
Homework Hacks
Homework Hack 1
import random
students = ['Aadi', 'Rayhaan', 'Gyutae', 'Derek', 'Adi', 'Ansh', 'Playboy Carti', 'Mihir', 'Joe','Alex','Ben','Anish', 'Jacob', 'Mr.Mortenson', 'John']
teams = ['Team El Primo', 'Team Poco ', 'Team Shelly']
team_assignments = {team: [] for team in teams}
for student in students:
team = random.choice(teams)
team_assignments[team].append(student)
for team, members in team_assignments.items():
print(team + ": " + ", ".join(members))
Team El Primo: Rayhaan, Gyutae, Ansh, Playboy Carti, Ben, Anish, Jacob, Mr.Mortenson
Team Poco : Adi, Joe, Alex, John
Team Shelly: Aadi, Derek, Mihir
Homework Hack 2
import random
weather = ['Sunny', 'Cloudy', 'Rainy']
forecast = []
for i in range(7):
forecast.append(random.choice(weather))
for i, day in enumerate(forecast, 1):
print("Day " + str(i) + ": " + day)
Day 1: Sunny
Day 2: Sunny
Day 3: Cloudy
Day 4: Rainy
Day 5: Rainy
Day 6: Cloudy
Day 7: Rainy
Homework Hack 3
import random
customers = 5
service_times = [random.randint(1, 5) for _ in range(customers)]
total_time = sum(service_times)
for i, time in enumerate(service_times, 1):
print("Customer " + str(i) + ": " + str(time) + " minutes")
print("Total time: " + str(total_time) + " minutes")
Customer 1: 4 minutes
Customer 2: 2 minutes
Customer 3: 2 minutes
Customer 4: 1 minutes
Customer 5: 5 minutes
Total time: 14 minutes