I'VE GOT THE BYTE ON MY SIDE

57005 or alive

A mini milestone

Nov 7, 2012 blog data

“I’ve got the byte on my side” reached 2,000 total views today!  Huzzah!

The Bailey-Borwein-Plouffe algorithm in C# and F#

Nov 3, 2012 C# F# math

Earlier this year I wrote about calculating the first \(n\) digits of \(\pi\) using a Machin-style formula.  This type of formula is very efficient for generating all of the first \(n\) digits, but what if we really only want the \(n\) th digit by itself?  The most naive approach would be to calculate all of the digits, then simply pick the last one.  But is there is a faster way?  What does the code look like?

Using enums in Powershell

Jul 9, 2012 powershell

Enums are a very useful way to encode “options” in .NET programming. They offer a mechanism to represent a fixed set of known values, named in a developer-friendly way. Enums are used frequently in .NET programming, and in many places throughout the core system SDK.

Many folks don’t realize it, but Powershell provides very powerful built-in support for dealing with enums.

3-player war

Jun 10, 2012 math

A friend encountered the following event recently when playing a game of 3-player war: Three distinct cards were played (their exact value isn’t important), then on the next hand the same 3 cards were played again, and by the same players (different suits, obviously). What are the chances of this happening?

How to capture or redirect Write-Host output in powershell

Apr 26, 2012 powershell

Write-Host, unlike most cmdlets, does not return anything to the pipeline.  It merely prints your object or message to the console.  That makes it the go-to cmdlet for the ever-so-common task of tracing out status messages.  Indeed, its defining feature is that it won’t screw up the return values from functions or scripts, since it emits nothing extra to the pipeline.  Unintentionally emitting trace messages (or just stuff in general) to the pipeline is a classic powershell n00b bug, so having such a cmdlet to do the task properly is key.

But what if you actually WANT to process those Write-Host messages?  e.g. redirect them to a file, filter them, parse them, etc?  Then you are out of luck, since the whole point of the cmdlet is to only print stuff, not return it to the pipeline.