Skip to content

Instantly share code, notes, and snippets.

@rapidrapids
Created August 9, 2012 13:02
Show Gist options
  • Save rapidrapids/3304008 to your computer and use it in GitHub Desktop.
Save rapidrapids/3304008 to your computer and use it in GitHub Desktop.
Deal or no Deal
using System;
using System.Collections.Generic;
using System.Linq;
namespace DonD
{
class Program
{
static void Main(string[] args)
{
string[] boxes = new[] { "1p", "10p", "50p", "£1", "£5", "£10", "£50", "£100", "£250", "£500", "£750", "£1,000", "£3,000", "£5,000", "£10,000", "£15,000", "£20,000", "£35,000", "£50,000", "£75,000", "£100,000", "£250,000" };
string targetBox = "£250,000";
int sets = 3;
int tries = 10000;
var rand = new Random();
for (var s = 0; s < sets; s++)
{
int rtl = 0;
int random = 0;
for (var i = 0; i < tries; i++)
{
List<string> randomBoxes = new List<string>(boxes.OrderBy(x => rand.Next()));
// Going right-to-left
if (randomBoxes.Last() == targetBox)
rtl++;
// Picking at random
while (randomBoxes.Count > 1)
{
var index = rand.Next(0, randomBoxes.Count);
randomBoxes.RemoveAt(index);
}
if (randomBoxes.ElementAt(0) == targetBox)
random++;
}
Console.WriteLine(string.Format("After {2} tries: RTL = {0}, Random = {1}", rtl, random, tries));
}
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment