HiperLogic

Virtualization, High Performance Computing, Healthcare IT, Enterprise Computing

Powershell Rock-Paper-Scissors

You are currently browsing articles tagged Powershell Rock-Paper-Scissors.

There is an interesting webpage at the NY Times that allows you to play rock-paper-scissors against a computer that uses 200,000 past rounds against humans in an attempt to defeat you.

A truly random game would be the best offense, since the computer is programmed to reply with a non-random throw based on what a human would do. I thought this would be a fun way to show how you can use PowerShell to create a simple script to create a randomized set of throws to play:

$hand = "rock", "paper", "scissors"
$rand = New-Object system.random
#Just keep repeating this line to get the next throw
$hand[$rand.next(0,3)]

The result after 41 rounds was a PowerShell Win!

Result of PowerShell vs Rock-Paper-Scissors

Result of PowerShell vs Rock-Paper-Scissors

Tags:

© 2006-2010 HiperLogic, LLC.  |  Serving the Ann Arbor, Southeast Michigan, and Ohio region  |  (888)-268-3930  |