Add to Technorati Favorites
Welcome to ThePowerShellGuy.com Sign in | Join | Help

Scripting Games 2008 Beginners Windows PowerShell Event 10

And to end the series with solutions, Beginners event 10,

this was a nice one, I started out with a straight loop but to handle 2 or 3 strikes in a row I considered that it might be easier to look back and forwards in the array.

a Pro was that this would make scores per frame / round possible, a Con was that I needed to check for Strikes or spares ( "X" or "\" ) in the lookups also.

 

$arrFrames = 2,5,7,"/",8,1,"X",9,"/",5,3,7,0,4,5,"X",2,0

$score = $i = 0 
$arrFrames |% { 
  if ($_ -is [int]) { 
    $score += $_ 
  } Else { 
    switch ($_) { 
    '/' { 
           $score += (10 - $arrFrames[$i-1]) + (($arrFrames[$i+1]) -replace 'X','10') 
        } 
    'X' { 
           $o1 = ($arrFrames[$i+1]) -replace 'X','10' 
           $o2 = (($arrFrames[$i+2]) -replace 'X','10') -replace '/' , (10 - $o1) 
           $score += 10 + $o1 + $o2 
        } 
    } 
  } 
  $i++ 
};$score 

From IRC chats I think that Jaykul did workout the "loop" for this so it might be nice to compare the solutions when he has his one posted.

b.t.w. you will find "only" 26 solutions in this series as the Sudden death included 2 Quizzes, and the beginner a debug question, and one where I had nothing to add to the given solution.

I hope you enjoyed the games and comparing all different solutions posted, till next year @ the 2009 Games !

 

Enjoy,

Greetings /\/\o\/\/

Published Monday, March 03, 2008 3:04 PM by MoW

Comments

No Comments
Anonymous comments are disabled