Home > Uncategorized > Powershell: 99 bottles of beer

Powershell: 99 bottles of beer

Trying out code golf challenge of 99 bottles of beer in Powershell.

$a=" bottles of beer";$b=" on the wall";$c=$a.remove(7,1)
99..2|%{"$_$a$b, $_$a.`nTake one down and pass it around, $($_-1)$a$b.`n"}
"1$c$b, 1$c.`nGo to the store and buy some more, 99$a$b."

192 characters (or 190 if written on one line using semi colon as delimiter). Still far from the best Perl script that only requires 151 characters (impressive).

I added a char count command to the Powershell ISE by adding the following lines to the ISE profile:

$addonsmenu = $psISE.CurrentPowerShellTab.AddOnsMenu
$addonsmenu.Submenus.Add("Count chars", { $psISE.CurrentFile.Editor.Text.Length }, "Ctrl+Alt+L") | Out-Null

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: