Scripting Games – December 2015

So here is my submitted entry to the December 2015 Scripting Games Puzzle hosted at PowerShell.org to which comments have been posted on the Wrap Up containing the official answer(s).

The challenges presented in this puzzle are described below and to which I detail my approach to solving each one.

Split $list into a collection of entries, as you typed them, and sort the results by length. As a bonus, see if you can sort the length without the number.

Firstly, I split the collection of entries and store the output as a variable. In order to sort the number by length the variable is retrieved and the objects are sorted by property length. For sorting the objects without the number, the retrieved variable replaces any numbers in the objects.

Turn each line into a custom object with a properties for Count and Item

For each object in the list of items an action is performed to create a custom object for a count and item property value. In order to retrieve property values, a regular expression is used to replace all numbers to retrieve the item property value and then to replace all alphabetic characters for the item property value.

Using your custom objects, what is the total number of all bird-related items?

Here I perform a keyword match which contains all the bird-related items agaisnt the custom object and the calculate the sum of the property value count to retrieve the total number.

What is the total count of all items?

As previously, I have used regular expression to remove all alphabetic characters from each item in the collection. I then join the returned values with the ‘+’ character and pass the string as the command parameter value for the Invoke-Expression cmdlet to perform the calculation.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s