#!/usr/bin/perl
($number)=@ARGV; #read in from command line number of simulations
for ($i=1;$i<=$number+1;$i++) {

    $done=0; 
    $first=1;
    $lost=0;
    $won=0;
    while($done==0) { #keep going until I have a result    
	$a=int(rand()*6+1); # random number between 1 and 6 for die 1
	$b=int(rand()*6+1); # random number betwen 1 and 6 for die 2

	if ($first) { #first roll?  See if I have won or lost
	    if (($a+$b)==2 || ($a+$b)==3 || ($a+$b)==12) { #lost
		$lost=1;
		$done=1;
	    }
	    elsif (($a+$b)==7 || ($a+$b)==11) { # # winner!
		$won=1;                        
		$done=1;
	    }
	    else { # need to roll a second time
		$total=$a+$b;
		$first=0;
	    }
	}
	else { #this is roll N, where N!=1
	    if (($a+$b)==$total) { # does my die sum to my first roll?
		$won=1;
		$done=1;
	    }
	    if (($a+$b)==7) { #did I lose?
		$lost=1;
		$done=1;
	    }
	}
    }

    if ($lost==1) {
	$sumlost+=1;
    }
    if ($won==1) {
	$sumwon+=1;
    }

    $a=((log($i)/log(10.)));
    if (($a-int($a))<0.000001) { # print out in log spacing 
	printf("%d %f\n",$i,$sumwon/($sumlost+$sumwon));
    }
}


	

	   
	   
	   
