News for hackers. Stuff that matters.
Re:Coin Puzzle: Predict the Other's Coin by kator on Sunday December 30, 2012 @08:54AM (#4985686)
Play with different strategies:

  import random
 
  # Modify strategy here
  def turn():
      toss = random.randint(0, 1)
      guess = random.randint(0, 1)
      # Uncomment to make A/B win
      # guess = toss
      return toss, guess

  random.seed()

  score_ab, score_c = 0, 0

  for i in range(1, 1001):
      score_ab -= 1
      score_c  += 1
      toss_a, guess_a = turn()
      toss_b, guess_b = turn()

      if toss_a == guess_b and toss_b == guess_a:
        score_ab += 3
        score_c  -= 3

      print i, 'ab:', score_ab, 'c:', score_c

  if score_ab > score_c:
      print "Players A, B win"
  else:
      print "Player C wins"

There are no comments on this comment yet.