Saturday, February 5, 2011

PowerShell doesn't cure insomnia

Had a bit of trouble sleeping last night, when I noticed that there was a perceptible difference in the amount of light the digital clock emanates.

It got me wondering what time displays the most light. Sure I could have manually figured it out, but isn't more exciting to write a script?

Here it is:
<#   Define a lookup table for the amount of light "bars" each number displays. #>           
$hash = @{"1"=2;"2"=5;"3"=5;"4"=4;     
for ($hour = 1; $hour -le 12; $hour++) {
for ($minute = 0;$minute -lt 60; $minute++) {
$time = "{0}:{1:0#}" -f $hour, $minute
$timeArray = $time.ToCharArray()
foreach ($char in $timeArray) {
$sum+= $hash[[string]$char]
if ($sum -gt $max) {
$max, $maxTime =$sum, $time
"{0}`t{1}"-f $max, $maxTime


brwilkinson said...

Nice . . .

Jeffery Hicks said...

Now take it the next logical step. Turn this into a function that takes a time value as parameter and returns the light value.