STLP 2013 Coding Event

Spring, 2013
Rupp Arena, Lexington, KY

The 2013 STLP Coding competition will place competitors in a live, time-constrained environment where they are challenged to complete a series of tasks by writing working code to complete and automate the process. The script can be as short as a few lines, or as elaborate as the participant’s skillset and imagination allow. To properly test the competitors’ individual performance, no online internet-based resources will be allowed, although offline resources (electronic or dead-tree) are permitted. So break out your text editor/IDE and the reference guide for your language of choice, and sign up for the onsite competition!
The following languages are permitted:

  • VBScript
  • JScript/Javascript
  • PHP
  • Perl
  • Python
  • Java
  • C, C++, C#

The following skills may be used in the challenge prompts:

  1. Input/Output
  2. Variables/Arrays/Dynamic arrays
  3. Variable type conversion – explicit/implicit
  4. String manipulation – Concatenating/Dividing/Replacing/Evaluating
  5. Number manipulation
  6. Date/Time manipulation
  7. File System access – reading/writing files, moving/copying files, reading file properties
  8. Looping/Iteration
  9. Branching
  10. Subroutines/Functions
  11. Error handling

Entries are graded on the following criteria:

  • Copyright - Does not infringe
  • Accuracy - Solve the entire prompt, according to the instructions
  • Design - Elegant, efficient design
  • Technique - Good coding practices
  • Time - Solve the prompt within the allotted time

Students should bring their own laptop. Internet access during the competition will NOT be allowed; however, hard copy or electronic reference guides are allowed. If your entry is in the form of acompiled programrather than an interpreted program (script) thenthe source code must accompany it.

Prompt:

Your mission, should you choose to accept it, is to code a solution for the following:

  1. Accept user input in the form of properly formatted roman numerals (values between 1 and 4999) and convert it to arabic numerals, which are then output to the user.
  2. Accept a second user input in the form of arabic numerals (values between 1 and 4999) and convert it to properly formatted roman numerals, which are then output to the user.
  3. In each case, ensure that the input is valid. The script should not crash or provide bad output, regardless of input.

Reading Roman Numerals

Roman Numerals, as used today, are based on seven symbols:

Symbol / Value
I / 1
V / 5
X / 10
L / 50
C / 100
D / 500
M / 1000
/ Numbers are formed by combining symbols together and adding the values. SoIIis two ones, i.e. 2, andXIIIis a ten and three ones, i.e. 13. There is no zero in this system, so 207, for example, isCCVII, using the symbols for two hundreds, a five and two ones. 1066 isMLXVI, one thousand, fifty and ten, a five and a one.
Symbols are placed from left to right in order of value, starting with the largest. However, in a few specific cases,to avoid four characters being repeated in succession (such as IIIIorXXXX) these should be reduced as follows:
  • the numeralIshould be placed beforeVandXto make 4 units (IV) and 9 units (IX) respectively
  • Xshould be placed beforeLandCto make 40 (XL) and 90 (XC) respectively
  • Cshould be placed beforeDandMto make 400 and 900 according to the same pattern
An example using the above rules would be 1904: this is composed of 1 (one thousand), 9 (nine hundreds), 0 (zero tens), and 4 (four units). To write the Roman numeral, each of the non-zero digits should be treated separately. Thus 1,000 =M, 900 =CM, and 4 =IV. Therefore, 1904 isMCMIV. This reflects typical modern usage.

Scoring Rubric

Criteria / Points Possible / Points Earned
1. The solution converts roman numerals to arabic. / 40
2. The solution converts arabic numerals to roman. / 35
2. Proposed solution is original, elegant, efficient and uses non-repetitious code. / 10
3. The script uses error checking for invalid input. / 10
4. The script is easy to read (e.g. uses good scripting practices such as indentation, commenting, use of meaningful names for variables/subroutines. / 5
Total / 100

Time to finish: 2 hrs. A few additional minutes will be given initially to read the prompt and ask questions. Overtime period(s) will be added if there are no completed, valid entries at the end of 2 hours.

Bowling Green site with lots of links to coding help:

Solutions:

Roman:

Option Explicit

Dim strInput, strSum

Dim arrChar(), arrInt

Dim intInput, intCount, intLen, intPos, intSum

strInput = InputBox("input a number using roman numeral notation")

intLen = Len(strInput) - 1

RedimarrChar(intLen)

RedimarrInt(intLen)

For intPos = 0 to intLen

arrChar(intPos) = Mid(strInput, intPos + 1, 1)

arrInt(intPos) = ConvertRoman(arrChar(intPos))

Next

intSum = 0

For intPos = 0 to Ubound(arrChar) - 1

If arrInt(intPos) >= arrInt(intPos + 1 ) Then

intSum = intSum + arrInt(intPos)

Else

intSum = intSum - arrInt(intPos)

End If

Next

intSum = intSum + arrInt(intLen)

Wscript.echointSum

Function ConvertArabic

If intInput > 999 Then

intInput = intInput - 1000

ConvertArabic = "M"

ElseIfintInput > 499 Then

intInput = intInput - 500

ConvertArabic = "D"

ElseIfintInput > 99 Then

intInput = intInput - 100

ConvertArabic = "C"

ElseIfintInput > 49 Then

intInput = intInput - 50

ConvertArabic = "L"

ElseIfintInput > 9 Then

intInput = intInput - 10

ConvertArabic = "X"

ElseIfintInput > 4 Then

intInput = intInput - 5

ConvertArabic = "V"

ElseIfintInput = 1 Then

intInput = intInput - 1

ConvertArabic = "I"

End If

End Function

Function ConvertRoman(strChar)

Select Case Ucase(strChar)

Case "I"

ConvertRoman = 1

Case "V"

ConvertRoman = 5

Case "X"

ConvertRoman = 10

Case "L"

ConvertRoman = 50

Case "C"

ConvertRoman = 100

Case "D"

ConvertRoman = 500

Case "M"

ConvertRoman = 1000

End Select

End Function

Arabic:

Option Explicit

Dim strInput, strSum

Dim arrChar()

Dim intInput, intCount

intCount = 0

strSum = ""

strInput = InputBox("input a number using arabic numeral notation")

intInput = cint(strInput)

Do WhileintInput > 0

Redim Preserve arrChar(intCount)

arrChar(intCount) = ConvertArabic

strSum = strSumarrChar(intCount)

intCount = intCount + 1

Loop

wscript.echostrSum

Function ConvertArabic

If intInput > 999 Then

intInput = intInput - 1000

ConvertArabic = "M"

ElseIfintInput > 899 Then

intInput = intInput - 900

ConvertArabic = "CM"

ElseIfintInput > 499 Then

intInput = intInput - 500

ConvertArabic = "D"

ElseIfintInput > 399 Then

intInput = intInput - 400

ConvertArabic = "CD"

ElseIfintInput > 99 Then

intInput = intInput - 100

ConvertArabic = "C"

ElseIfintInput > 89 Then

intInput = intInput - 90

ConvertArabic = "XC"

ElseIfintInput > 49 Then

intInput = intInput - 50

ConvertArabic = "L"

ElseIfintInput > 39 Then

intInput = intInput - 40

ConvertArabic = "XL"

ElseIfintInput > 9 Then

intInput = intInput - 10

ConvertArabic = "X"

ElseIfintInput > 8 Then

intInput = intInput - 9

ConvertArabic = "IX"

ElseIfintInput > 4 Then

intInput = intInput - 5

ConvertArabic = "V"

ElseIfintInput > 3 Then

intInput = intInput - 4

ConvertArabic = "IV"

ElseIfintInput >= 1 Then

intInput = intInput - 1

ConvertArabic = "I"

End If

End Function

Function ConvertRoman(strChar)

Select Case Ucase(strChar)

Case "I"

ConvertRoman = 1

Case "V"

ConvertRoman = 5

Case "X"

ConvertRoman = 10

Case "L"

ConvertRoman = 50

Case "C"

ConvertRoman = 100

Case "D"

ConvertRoman = 500

Case "M"

ConvertRoman = 1000

End Select

End Function