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