﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Sean Smith  / Monty Hall Paradox / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 19 Jun 2013 21:00:14 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Monty Hall Paradox</title><link>http://www.sqlservercentral.com/Forums/Topic781385-1371-1.aspx</link><description>Very cool alternative. Thanks for sharing! :)</description><pubDate>Wed, 09 Sep 2009 16:07:36 GMT</pubDate><dc:creator>Sean Smith-776614</dc:creator></item><item><title>RE: Monty Hall Paradox</title><link>http://www.sqlservercentral.com/Forums/Topic781385-1371-1.aspx</link><description>That is an interesting puzzle. Here is another solution using a CTE instead of a loop.[code]-- Setupset nocount on-- Create a table to store the results.create table Doors(		ID int	,	ChosenDoor int	,	WinningDoor int	,	WinLose as case when ChosenDoor = WinningDoor then 0 else 1 end -- Win = 1,  Lose = 0);-- Use a CTE to generate 10,000 "contestants" and their chosen/winning doors.-- If the chosen door equals the winning door the contestant will switch when given the-- option and lose. Otherwise they will switch to the winning door and win.with Digits(i)as (select i   from (select 1 union select 2 union select 3 union select 4 union select 5 union		select 6 union select 7 union select 8 union select 9 union select 0) AS X(i))insert into Doors(ID, ChosenDoor, WinningDoor)select (D3.i * 1000 + D2.i * 100 + D1.i * 10 + D0.i) AS seq	,	abs(cast(cast(newid() as varbinary) as int)) % 3 + 1 ChosenDoor	,	abs(cast(cast(newid() as varbinary) as int)) % 3 + 1 WinningDoor    from Digits as D0, Digits as D1, Digits as D2, Digits as D3-- Select the total number of winners (1) and losers (0).select	WinLose	,	count(*) Totalfrom Doorsgroup by WinLose-- Clean-updrop table Doorsset nocount off[/code]</description><pubDate>Wed, 09 Sep 2009 15:53:35 GMT</pubDate><dc:creator>Jason Whitney</dc:creator></item><item><title>RE: Monty Hall Paradox</title><link>http://www.sqlservercentral.com/Forums/Topic781385-1371-1.aspx</link><description>(removed)</description><pubDate>Wed, 09 Sep 2009 13:05:20 GMT</pubDate><dc:creator>TPalmeri</dc:creator></item><item><title>Monty Hall Paradox</title><link>http://www.sqlservercentral.com/Forums/Topic781385-1371-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/Monty/68012/"&gt;Monty Hall Paradox&lt;/A&gt;[/B]</description><pubDate>Wed, 02 Sep 2009 06:45:09 GMT</pubDate><dc:creator>Sean Smith-776614</dc:creator></item></channel></rss>