aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x[-rw-r--r--]challenge-282/peter-meszaros/perl/ch-1.pl (renamed from challenge-282/peter-meszaros/ch-1.pl)0
-rwxr-xr-x[-rw-r--r--]challenge-282/peter-meszaros/perl/ch-2.pl (renamed from challenge-282/peter-meszaros/ch-2.pl)0
-rwxr-xr-xchallenge-282/peter-meszaros/tcl/ch-1.tcl70
-rwxr-xr-xchallenge-282/peter-meszaros/tcl/ch-2.tcl66
4 files changed, 136 insertions, 0 deletions
diff --git a/challenge-282/peter-meszaros/ch-1.pl b/challenge-282/peter-meszaros/perl/ch-1.pl
index 28c5aa8e5a..28c5aa8e5a 100644..100755
--- a/challenge-282/peter-meszaros/ch-1.pl
+++ b/challenge-282/peter-meszaros/perl/ch-1.pl
diff --git a/challenge-282/peter-meszaros/ch-2.pl b/challenge-282/peter-meszaros/perl/ch-2.pl
index e8a81a67c3..e8a81a67c3 100644..100755
--- a/challenge-282/peter-meszaros/ch-2.pl
+++ b/challenge-282/peter-meszaros/perl/ch-2.pl
diff --git a/challenge-282/peter-meszaros/tcl/ch-1.tcl b/challenge-282/peter-meszaros/tcl/ch-1.tcl
new file mode 100755
index 0000000000..20e26c8645
--- /dev/null
+++ b/challenge-282/peter-meszaros/tcl/ch-1.tcl
@@ -0,0 +1,70 @@
+#!/usr/bin/env tclsh
+#
+# Task 1: Good Integer
+#
+# Submitted by: Mohammad Sajid Anwar
+#
+# You are given a positive integer, $int, having 3 or more digits.
+#
+# Write a script to return the Good Integer in the given integer or -1 if none
+# found.
+#
+# A good integer is exactly three consecutive matching digits.
+#
+# Example 1
+#
+# Input: $int = 12344456
+# Output: "444"
+#
+# Example 2
+#
+# Input: $int = 1233334
+# Output: -1
+#
+# Example 3
+#
+# Input: $int = 10020003
+# Output: "000"
+#
+
+package require tcltest
+
+set cases {
+ {12344456 444 "Example 1"}
+ {1233334 -1 "Example 2"}
+ {10020003 000 "Example 3"}
+ {1233334555 555 "Example 4"}
+}
+
+proc good_integer {str} {
+ set l [expr [string length $str] - 3]
+ for {set i 0} {$i <= $l} {incr i} {
+ set s0 [string index $str $i]
+ set s1 [string index $str [expr $i + 1]]
+ set s2 [string index $str [expr $i + 2]]
+ if {$s0 == $s1 && $s0 == $s2} {
+ if {$i > 0} {
+ if {[string index $str [expr $i - 1]] == $s0} {
+ continue
+ }
+ }
+ if {$i < $l} {
+ if {[string index $str [expr $i + 3]] == $s0} {
+ continue
+ }
+ }
+ return "$s0$s0$s0"
+ }
+ }
+ return -1
+}
+
+tcltest::configure -verbose {pass}
+foreach case $cases {
+ tcltest::test [lindex $case 2] {} {
+ good_integer [lindex $case 0]
+ } [lindex $case 1]
+}
+
+exit 0
+
diff --git a/challenge-282/peter-meszaros/tcl/ch-2.tcl b/challenge-282/peter-meszaros/tcl/ch-2.tcl
new file mode 100755
index 0000000000..f279c32cb7
--- /dev/null
+++ b/challenge-282/peter-meszaros/tcl/ch-2.tcl
@@ -0,0 +1,66 @@
+#!/usr/bin/env tclsh
+#
+# Task 2: Changing Keys
+#
+# Submitted by: Mohammad Sajid Anwar
+#
+# You are given an alphabetic string, $str, as typed by user.
+#
+# Write a script to find the number of times user had to change the key to type
+# the given string. Changing key is defined as using a key different from the
+# last used key. The shift and caps lock keys won’t be counted.
+#
+# =head2 Example 1
+#
+# Input: $str = 'pPeERrLl'
+# Ouput: 3
+#
+# p -> P : 0 key change
+# P -> e : 1 key change
+# e -> E : 0 key change
+# E -> R : 1 key change
+# R -> r : 0 key change
+# r -> L : 1 key change
+# L -> l : 0 key change
+#
+# =head2 Example 2
+#
+# Input: $str = 'rRr'
+# Ouput: 0
+#
+# =head2 Example 3
+#
+# Input: $str = 'GoO'
+# Ouput: 1
+#
+
+package require tcltest
+
+set cases {
+ {pPeERrLl 3 "Example 1"}
+ {rRr 0 "Example 2"}
+ {GoO 1 "Example 3"}
+}
+
+proc changing_keys {str} {
+ set l [split [string tolower $str] {}]
+
+ set cnt 0
+ for {set i 1} {$i < [llength $l]} {incr i} {
+ if {[lindex $l $i] != [lindex $l [expr $i - 1]]} {
+ incr cnt
+ }
+ }
+
+ return $cnt
+}
+
+tcltest::configure -verbose {pass}
+foreach case $cases {
+ tcltest::test [lindex $case 2] {} {
+ changing_keys [lindex $case 0]
+ } [lindex $case 1]
+}
+
+exit 0
+