blob: dd25015f392f95442ea76f2a9cfd680c618f9a8a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
' Challenge 095
'
' TASK #1 › Palindrome Number
' Submitted by: Mohammad S Anwar
' You are given a number $N.
'
' Write a script to figure out if the given number is Palindrome. Print 1 if true otherwise 0.
'
' Example 1:
' Input: 1221
' Output: 1
' Example 2:
' Input: -101
' Output: 0, since -101 and 101- are not the same.
' Example 3:
' Input: 90
' Output: 0
Function is_palindrome(n as long) as integer
dim p10 as long
' negative numbers are not palindromes
if n < 0 then
is_palindrome = 0
exit function
end if
' find highest power of 10 < n
p10 = 1
do while n > p10*10
p10 = p10*10
loop
' remove highest and lowest digits until number is <10
do while n >= 10
if (n mod 10) <> int(n/p10) then
is_palindrome = 0
exit function
end if
n = int((n mod p10) / 10) ' remove high and low digits
p10 = int(p10 / 100)
loop
'if number is less than 10, it is a palindrome
is_palindrome = 1
End Function
print trim(str(is_palindrome(val(command(1)))))
|