Thursday, February 21, 2008

2008 Scripting Games!! Beg. Event 1

For the first year I've decided to enter the MS Scripting Games. I only entered the Beginners/Intermediate level so I can get a feel for the events. Half of the "Advanced" Events are very tough even for some of the best scripters. I think next year I will be there and give it a shot.

I entered the Games for both VBScript and Powershell. So, to avoid duplicate post I'll just post my Powershell solutions.

   1:  $card1="Seven of spades"
   2:  $card2="Five of hearts"
   3:  $card3="Seven of diamonds"
   4:  $card4="Seven of clubs"
   5:  $card5="King of clubs"
   6:  
   7:  $valueOfCard1=$card1.substring(0,($card1.IndexOf(" ")))
   8:  $valueOfCard2=$card2.substring(0,($card2.IndexOf(" ")))
   9:  $valueOfCard3=$card3.substring(0,($card3.IndexOf(" ")))
  10:  $valueOfCard4=$card4.substring(0,($card4.IndexOf(" ")))
  11:  $valueOfCard5=$card5.substring(0,($card5.IndexOf(" ")))
  12:  
  13:  if ($valueOfCard1 -eq $valueOfCard2) { $pairs++;$result += "$card1 and $card2`n" }
  14:  if ($valueOfCard1 -eq $valueOfCard3) { $pairs++;$result += "$card1 and $card3`n" }
  15:  if ($valueOfCard1 -eq $valueOfCard4) { $pairs++;$result += "$card1 and $card4`n" }
  16:  if ($valueOfCard1 -eq $valueOfCard5) { $pairs++;$result += "$card1 and $card5`n" }
  17:  if ($valueOfCard2 -eq $valueOfCard3) { $pairs++;$result += "$card2 and $card3`n" }
  18:  if ($valueOfCard2 -eq $valueOfCard4) { $pairs++;$result += "$card2 and $card4`n" }
  19:  if ($valueOfCard2 -eq $valueOfCard5) { $pairs++;$result += "$card2 and $card5`n" }
  20:  if ($valueOfCard3 -eq $valueOfCard4) { $pairs++;$result += "$card3 and $card4`n" }
  21:  if ($valueOfCard3 -eq $valueOfCard5) { $pairs++;$result += "$card3 and $card5`n" }
  22:  if ($valueOfCard4 -eq $valueOfCard5) { $pairs++;$result += "$card4 and $card5`n" }
  23:  
  24:  "Pairs: $pairs"
  25:  $result

Now I know this can be condensed quite a bit with nested "For" statements this was the easiest way to get the results I needed and it's very easy to read.

No comments: