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;Enjoy!
"5"=5;"6"=6;"7"=3;"8"=7;
"9"=5;"0"=6;":"=0}
$max=0
for ($hour = 1; $hour -le 12; $hour++) {
for ($minute = 0;$minute -lt 60; $minute++) {
$time = "{0}:{1:0#}" -f $hour, $minute
$timeArray = $time.ToCharArray()
$sum=0
foreach ($char in $timeArray) {
$sum+= $hash[[string]$char]
}
if ($sum -gt $max) {
$max, $maxTime =$sum, $time
}
}
}
"{0}`t{1}"-f $max, $maxTime
2 comments:
Nice . . .
Now take it the next logical step. Turn this into a function that takes a time value as parameter and returns the light value.
Post a Comment