Palindromic Number in Tcl

Published on 09 October 2025 (Updated: 09 October 2025)

Welcome to the Palindromic Number in Tcl page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

package require Tcl 8.6

proc usage {} {
    puts stderr "Usage: please input a non-negative integer"
    exit 1
}

proc isNonNegativeInteger {s} { return [regexp {^[0-9]+$} $s] }


proc isPalindrome {s} {
    set n [string length $s]
    set i 0
    set j [expr {$n - 1}]
    while {$i < $j} {
        if {[string range $s $i $i] ne [string range $s $j $j]} {
            return 0
        }
        incr i
        incr j -1
    }
    return 1
}

if {$argc != 1} { usage }

set input [string trim [lindex $argv 0]]
if {![isNonNegativeInteger $input]} { usage }

puts [expr {[isPalindrome $input] ? "true" : "false"}]

Palindromic Number in Tcl was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.