# Palindromic Number in Euphoria

Published on 19 February 2023 (Updated: 19 February 2023)

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

## Current Solution

``````include std/io.e
include std/types.e
include std/text.e
include std/get.e as stdget
include std/math.e
include std/utils.e

-- Indices for value() return value

-- Indices for parse_int() return value
enum PARSE_INT_VALID, PARSE_INT_VALUE

function parse_int(sequence s)
-- Trim off whitespace and parse string
s = trim(s)

-- Error if any errors, value is not an integer, or any leftover characters
boolean valid = (
result[VALUE_ERROR_CODE] = GET_SUCCESS
and integer(result[VALUE_VALUE])
)

-- Get value if invalid
integer value = 0
if valid
then
value = result[VALUE_VALUE]
end if

return {valid, value}
end function

procedure usage()
puts(STDOUT, "Usage: please input a non-negative integer\n")
abort(0)
end procedure

function is_palindromic_number(integer value)
-- Convert number to string
sequence s = sprintf("%d", value)

-- Check if palindrome
integer len = length(s)
for n = 1 to intdiv(len, 2)
do
if s[n] != s[len + 1 - n]
then
return FALSE
end if
end for

return TRUE
end function

-- Check 1st command-line argument
sequence argv = command_line()
if length(argv) < 4 or length(argv) = 0
then
usage()
end if

-- Parse 1st command-line argument
sequence result = parse_int(argv)
integer value = result[PARSE_INT_VALUE]
if not result[PARSE_INT_VALID] or value < 0
then
usage()
end if

-- Indicate whether palindromic number or not
puts(STDOUT, iif(is_palindromic_number(value), "true\n", "false\n"))

``````

Palindromic Number in Euphoria was written by:

• rzuckerm

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.