aboutsummaryrefslogtreecommitdiff
path: root/challenge-145/abigail/tcl/ch-2.tcl
blob: 13645cea5b67908b35c82d0125bfea7b94b7469e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#
# See ../README.md
#

#
# Run as: tclsh ch-2.tcl < input-file
#

while {[gets stdin line] >= 0} {
    set palindromes [dict create]
    for {set i 0} {$i < [string length $line]} {incr i} {
        for {set j $i} {$j < [string length $line]} {incr j} {
            set str [string range $line $i $j]
            if {$str == [string reverse $str]} {
                dict set palindromes $str 1
            }
        }
    }
    puts [dict keys $palindromes]
}