Created
          July 31, 2011 21:57 
        
      - 
      
- 
        Save TimToady/1117259 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | my $pairs = 5; | |
| my $size = $pairs + 1; | |
| my @x; | |
| @x[0] = 1 xx $size; | |
| for 1 ..^ $size -> $row { | |
| for reverse 0 .. ($size - $row - 1) -> $col { | |
| @x[$row][$col] = (@x[$row][$col+1]//0) + @x[$row-1][$col]; | |
| } | |
| } | |
| .say for @x; | |
| my %hash; | |
| for ^1000 { | |
| my $r = $size-1; | |
| my $c = 0; | |
| my $string = ''; | |
| loop { | |
| if not defined @x[$r][$c+1] { | |
| if $r == 0 { | |
| last; | |
| } | |
| else { | |
| $r -= 1; | |
| $string ~= '['; | |
| } | |
| } | |
| elsif $r == 0 { | |
| $c += 1; | |
| $string ~= ']'; | |
| } | |
| elsif (@x[$r-1][$c] + @x[$r][$c+1]) * rand < @x[$r-1][$c] { | |
| $r -= 1; | |
| $string ~= '['; | |
| } | |
| else { | |
| $c += 1; | |
| $string ~= ']'; | |
| } | |
| } | |
| %hash{$string}++; | |
| } | |
| for %hash.pairs.sort(*.key) { | |
| say .key, ' ', .value; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment