Results tagged “funstuff” from PHactotum Wheneverly

Event 2: Skating on Thin Ice

|

Here is my submission for the Advanced Event 2 in the Microsoft Scripting Games 2008

   1: '*********************************************************************

   2: ' Script Name: Event2.vbs

   3: '     Version: 1.0

   4: '      Author: Perry Harris (PHactotum)

   5: '     Updated: 1:25 AM Wednesday, February 20, 2008

   6: '     Purpose: Solves the 2008 winter Scripting Games Advance Event 2: Skating on Thin Ice

   7: '              

   8: '       Usage: cscript Event2.vbs [phone number]

   9: '       Notes:

  10: '    Keywords: 

  11: '  versioning: 1.0    Original release

  12: '*********************************************************************

  13: Option Explicit

  14: Const ForReading = 1

  15: Dim objFS

  16: Dim objFile

  17: Dim strLine

  18: Dim aScore

  19: Dim i

  20: Dim ScoreMax, ScoreMin,ScoreTotal,ScoreAvg

  21: Dim GoldScore, GoldName

  22: Dim SilverScore, SilverName

  23: Dim BronzeScore, BronzeName

  24: GoldScore = 0

  25: SilverScore = 0

  26: BronzeScore = 0

  27: GoldName = ""

  28: SilverName = ""

  29: BronzeName = ""

  30:  

  31: 'Open and read our WordList

  32: Set objFS = CreateObject("Scripting.FileSystemObject")

  33: Set objFile = objFS.OpenTextFile("C:\Scripts\Skaters.txt", ForReading)

  34:  

  35: Do until objFile.AtEndOfStream

  36:     strLine = objFile.ReadLine

  37:     aScore = split(strLine,",")

  38:     ScoreMax = aScore(1)

  39:     ScoreMin = aScore(1)

  40:     ScoreTotal = 0

  41:     for i = 1 to ubound(aScore)

  42:         If aScore(i) > ScoreMax then ScoreMax = aScore(i)

  43:         If aScore(i) < ScoreMin then ScoreMin = aScore(i)

  44:         ScoreTotal = ScoreTotal + aScore(i)

  45:     next

  46:     ScoreTotal = ScoreTotal - ScoreMax - ScoreMin

  47:     ScoreAvg = ScoreTotal / (uBound(aScore)-2)

  48:     

  49:     If ScoreAvg > GoldScore then

  50:         BronzeName = SilverName

  51:         BronzeScore = SilverScore

  52:         SilverName = GoldName

  53:         SilverScore = GoldScore

  54:         GoldName = aScore(0)

  55:         GoldScore = ScoreAvg

  56:     Else If ScoreAvg > SilverScore then

  57:         BronzeName = SilverName

  58:         BronzeScore = SilverScore

  59:         SilverName = aScore(0)

  60:         SilverScore = ScoreAvg

  61:         Else If ScoreAvg > BronzeScore then

  62:             BronzeName = aScore(0)

  63:             BronzeScore = ScoreAvg

  64:             end if

  65:         end if

  66:     end if

  67:     

  68: Loop

  69: Wscript.StdOut.WriteLine "Gold medal: " & GoldName & ", " & GoldScore

  70: Wscript.StdOut.WriteLine "Silver medal: " & SilverName & ", " & SilverScore

  71: Wscript.StdOut.WriteLine "Bronze medal: " & BronzeName & ", " & BronzeScore


Event 1: Could I get your Phone Number?

|

Here is my submission for the Advanced Event 1 in the Microsoft Scripting Games 2008

   1: '*********************************************************************

   2: ' Script Name: Event1.vbs

   3: '     Version: 1.0

   4: '      Author: Perry Harris (PHactotum)

   5: '     Updated: 12:04 AM Wednesday, February 20, 2008

   6: '     Purpose: Solves the 2008 winter Scripting Games Advance Event 1: Could I get your Phone Number?

   7: '              

   8: '       Usage: cscript Event1.vbs [phone number]

   9: '       Notes:

  10: '    Keywords: 

  11: '  versioning: 1.0    Original release

  12: '*********************************************************************

  13: Option Explicit

  14: Dim strNumber

  15: Dim colMatches

  16: Dim objRegEx

  17: Dim Nums

  18: Dim objFS

  19: Dim objFile

  20: Dim strAll

  21: Dim i

  22: Const ForReading = 1

  23:  

  24: ' Retreive our phone number

  25: if WScript.Arguments.Count < 1 then

  26:     WScript.StdOut.Write "Please enter a 7 digit phone number: "

  27:     strNumber = WScript.StdIn.ReadLine

  28: else

  29:     strNumber = WScript.Arguments(0)

  30: end if

  31:  

  32: 'Verify our phone number is 7 digits and only uses the digits 2 - 9

  33: Set objRegEx = CreateObject("VBScript.RegExp")

  34: objRegEx.Pattern = "[2-9]{7}"

  35: Set colMatches = objRegEx.Execute(strNumber)

  36: if colMatches.Count <> 1 then

  37:     WScript.StdOut.WriteLine "I'm sorry, we only accept 7 digit numbers using the numbers 2 - 9."

  38:     WScript.StdOut.WriteLine "Please try again."

  39:     WScript.Quit

  40: end if

  41:  

  42: 'Convert our phone number to a regular expression

  43: set Nums=CreateObject("Scripting.Dictionary")

  44: Nums.Add 2, "[aAbBcC]"

  45: Nums.Add 3, "[dDeEfF]"

  46: Nums.Add 4, "[gGhHiI]"

  47: Nums.Add 5, "[jJkKlL]"

  48: Nums.Add 6, "[mMnNoO]"

  49: Nums.Add 7, "[pPrRsS]"

  50: Nums.Add 8, "[tTuUvV]"

  51: Nums.Add 9, "[wWxXyY]"

  52:  

  53: for i = 2 to 9

  54:     strNumber = replace(strNumber,i,Nums.item(i))

  55: next

  56:  

  57: objRegEx.Pattern = strNumber & "\r\n"

  58:  

  59: 'Open and read our WordList

  60: Set objFS = CreateObject("Scripting.FileSystemObject")

  61: Set objFile = objFS.OpenTextFile("C:\Scripts\wordlist.txt", ForReading)

  62:  

  63: strAll = objFile.Readall

  64:  

  65: 'Now let's see if there is a match in our word list

  66: Set colMatches = objRegEx.Execute(strAll)  

  67:  

  68: If colMatches.Count > 0 Then

  69:     Wscript.StdOut.WriteLine colMatches(0)

  70: else

  71:     WScript.StdOut.WriteLine "Sorry, no Matches were found"

  72: End If


Microsoft Scripting Olympics

|

Sounds like fun.  I think I'll try this.  I've looked over the events and they look doable.  The schedule might be tight, as the last entries are due on the first day of DEC2008, but we'll see.

I may even post my submissions here.

August 2017

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 30 31    

Find recent content on the main index or look in the archives to find all content.

Archives