Monday, February 25, 2008

My semi Tower of Power

 

My colleague came back from the States today, He brought the bottom two with him.

top

Put Some Muscle in Your Management

 

I've just received my Windows IT Pro Magazine current issue. PowerShell is featured in the cover story with PowerShell 101, Lesson 1 and Alex Angelopoulos shares his views on Windows PowerShell in PowerShell Empowerment.

2008 Scripting Games - Advanced Event 4

Event 4: Image is Everything

 

function print-calendar($dte){
  
  $month,$year = $dte.split("/")
  $dtfi = new-object system.globalization.datetimeformatinfo
  $AbbreviatedDayNames=$dtfi.AbbreviatedDayNames | foreach {" {0}" -f $_}

  $header= "$($dtfi.MonthNames[$month-1]) $year"
  write-host $header
  
  write-host ([string]::join("",$AbbreviatedDayNames))
  $daysInMonth=[datetime]::DaysInMonth($year,$month)

  $dayOfWeek =(new-object datetime $year,$month,1).dayOfWeek.value__
  $today=(get-date).day
  
  for ($i = 0; $i -lt $dayOfWeek; $i++){write-host (" "*4) -nonew}
  for ($i = 1; $i -le $daysInMonth; $i++)
  {
    if($today -eq $i){write-host ("{0,4}" -f $i) -nonew}
    else {write-host ("{0,4}" -f $i) -nonew}

      if ($dayOfWeek -eq 6) {write-host}
      $dayOfWeek = ($dayOfWeek + 1) % 7
  }
  if ($dayOfWeek -ne 0) {write-host}
}

print-calendar 2/2008
 
February 2008
 Sun Mon Tue Wed Thu Fri Sat
                       1   2
   3   4   5   6   7   8   9
  10  11  12  13  14  15  16
  17  18  19  20  21  22  23
  24  25  26  27  28  29
 
 
 
 
 
 

2008 Scripting Games - Advanced Event 3

 

Event 3: Instant (Runoff) Winner

$ballots = cat C:\Scripts\votes.txt | foreach {
  $tmp = $_.split(",")
  $ballot = New-Object psobject
  add-member -inp $ballot noteproperty candidat $tmp
  $ballot
}


$totalBallots = $ballots.length

for($i=1; $i -lt 4; $i++){
  $round = $ballots | group {$_.candidat[0]} | sort count -desc | select Name, @{n="Percent";e={"{0:N2}" -f (($_.count/$totalBallots)*100)}}
  
  $first = $round[0]
  if($first.Percent -ge 50){
    "The winner is {0} with {1}% of the vote." -f $first.Name,$first.Percent
    return
  }
  
  $last = $round[-1].Name
  $ballots | foreach {$_.candidat = $_.candidat | where {$_ -ne $last}}
}

The winner is Pilar Ackerman with 50.17% of the vote.

2008 Scripting Games - Advanced Event 2

 

Event 2: Skating on Thin Ice

$winners = cat C:\Scripts\skaters.txt | foreach {
  $item = $_.split(",")
  $scores = $item[1..7] | sort
  
  $skater = new-object psobject
  add-member -inp $skater noteproperty Name $item[0]
  add-member -inp $skater noteproperty HighestScore $scores[-1]
  add-member -inp $skater noteproperty LowestScore $scores[0]
  add-member -inp $skater noteproperty Score (($scores[1..($scores.length-2)] | measure-object -average).Average)
  add-member -inp $skater noteproperty Medal $null
  $skater
  
} | sort Score -desc | select -first 3

$winners[0].Medal="Gold medal"
$winners[1].Medal="Silver medal"
$winners[2].Medal="Bronze medal"

0..2 | foreach { "{0}: {1}, {2}" -f $winners[$_].Medal, $winners[$_].name ,$winners[$_].Score }

Results:
Gold medal: Guido Chuffart, 88.2
Silver medal: Jack Creasey, 85.8
Bronze medal: Cecilia Cornejo, 85.4
 

2008 Scripting Games - Advanced Event 1

 

Event 1: Could I Get Your Phone Number?

It seems I've taken the long path on this event, brute forcing every possible combination, padding all 3 letters to four chars.

 

$phone=Read-Host "Enter 7 digit phone number"
$letters = @{"2"="abc";"3"="def";"4"="ghi";"5"="jkl";"6"="mno";"7"="pqrs";"8"="tuv";"9"="wxyz"}
$numbers = 0..($phone.length-1) | foreach { "{0,-4}" -f $letters["$($phone[$_])"]}

"Computing word from Number, this may take a while..."

$wordList = cat c:\scripts\wordList.txt | where {($_.length -eq 7) -and ($_.substring(0,1) -match "[$($numbers[0])]")}


for($a=0; $a -lt 4; $a++){
    for($b=0; $b -lt 4; $b++){
        for($c=0; $c -lt 4; $c++){
            for($d=0; $d -lt 4; $d++){
                for($e=0; $e -lt 4; $e++){
                    for($f=0; $f -lt 4; $f++){
                        for($g=0; $g -lt 4; $g++){
                                    $word = "{0}{1}{2}{3}{4}{5}{6}" -f $numbers[0][$a],$numbers[1][$b],$numbers[2][$c],$numbers[3][$d],$numbers[4][$e],$numbers[5][$f],$numbers[6][$g]
                                    if($wordList -contains $word) {$wordList | where {$_ -eq $word}; return}
                        }
                    }
                }
            }
        }
    }
}

"Scan completed"

Thursday, February 14, 2008

Scripting Games 2008

The 2008 Scripting Games begins tomorrow. So, download the Games Competitors Pack and start coding :)