Skip to content

Commit ff95149

Browse files
authored
Add Roman Numeral in Tcl (#5079)
1 parent 4cdaf4a commit ff95149

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

archive/t/tcl/roman-numeral.tcl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package require Tcl 8.6
2+
package require math::roman
3+
4+
proc usage {msg} {
5+
puts $msg
6+
exit 1
7+
}
8+
9+
if {$argc != 1} { usage "Usage: please provide a string of roman numerals" }
10+
11+
set input [string trim [lindex $argv 0]]
12+
13+
if {$input eq ""} {
14+
puts 0
15+
exit 0
16+
}
17+
18+
if {[catch {math::roman::tointeger $input} err]} {
19+
usage "Error: invalid string of roman numerals"
20+
} else {
21+
puts [math::roman::tointeger $input]
22+
}

0 commit comments

Comments
 (0)