Friday, September 29, 2017

Prepping For A Programming Contest

So on November 1st my AP students and I will be venturing to Kansas State University for their HSPC, which of course is High School Programming Contest. They have been putting this on since 1999, and my 12 AP kiddos are really looking forward to it, even though sometimes the practice on problems from the archives spooks some of them, especially the more novice kids. We are working up a problem solving workflow collectively so the ones who get more nervous have a guide to follow on steps. Oh, and they will be in four person teams, but only one computer per team. Still have to find out what the guidelines are on allowing resource materials and such.

Anyways, here is a recent practice problem. All three teams were able to pseudocode or flowchart the general algorithm OK, but only one was able to put it to code within the time limit. I work alone to try and solve the problems myself while they work, and I find the challenge of it quite fun.

2 Beginning — Probability
Below are the probabilities for desired outcomes for each six different football games:

Game number 0 1 2 3 4 5
Probability 0.5 0.4 0.6 0.75 0.3 0.83

Some combination of these outcomes must occur in order for a certain team to make the playoffs. Write a program that takes as input a nonnegative integer n giving the number of relevant games, then n different game numbers. It then outputs the probability that all n of these games have the desired outcome, assuming the above probabilities and that the games are independent. In order to compute this probability, you will need to multiply together all of the probabilities for the selected games (if no games are selected, the probability is 1). You may assume that 0 _ n _ 6 and that the n game numbers are all valid and distinct.

My team that solved it within the time limit created this. Aside from naming things a bit more descriptively, I thought they developed a pretty effective solution.

prob = [.5,.4,.6,.75,.3,.83]

def probcalc():
  gamenum = int(input("How many games?"))
  probag = 1
 
  if gamenum <= 0:
    print(1)
  else: 
    for i in range(gamenum):
      probag *= prob[int(input("Game Number:"))]
    print(probag)

probcalc()

1 comment:

  1. How many teams can you bring? Are they leveled (A team B team?)?

    In general I like it when the kids have to work in teams. The only downside is that to do their best they have to practice as a unit and if you have LOTS of kids it could mean directing your energies to the few rather than the many.

    ReplyDelete