rem Programming Contest Problem rem Write a program to count the longest streak of consecutive rem heasds and tails flips in a series of coin tosses rem set up variables numberofflips = 10 maxheadsrun = 0 maxtailsrun = 0 currentrun = 1 currentside = 0 currentflip = 1 input "Enter number of coin flips: " numberofflips rem "handle first flip as special case" currentside = int(ran(2)) rem print "Flip number: ", currentflip if newside = 0 then print "Heads" else print "Tails" endif rem we are now up to flip two currentflip = 2 rem loop for rest of flips 20 if currentflip > numberofflips then goto 50 else newside = int(ran(2)) rem print "Flip number: ", currentflip if newside = 1 then print "Heads" else print "Tails" endif if newside = currentside then currentrun = currentrun + 1 else currentside = newside if currentside = 0 then if currentrun >= maxheadsrun then maxheadsrun = currentrun endif else if currentrun >= maxtailsrun then maxtailsrun = currentrun endif endif currentrun = 1 endif currentflip = currentflip + 1 endif goto 20 50 rem show results print "Longest run of heads: ", maxheadsrun print "Longest run of tails: ", maxtailsrun