Skip to content

Commit 3d7cb49

Browse files
[Dana] Add palindrome program (#51)
--------- Co-authored-by: Kostis Sagonas <kostis@cs.ntua.gr>
1 parent d787f49 commit 3d7cb49

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

dana/programs/palindrome.dana

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
def main
2+
3+
def check_pal is byte: s as byte[]
4+
5+
var res is byte
6+
var i l is int
7+
8+
l:=strlen(s)
9+
i:=0
10+
res:=true
11+
12+
loop:
13+
if i = l/2: break
14+
elif not s[i] = s[l-i-1]:
15+
res:=false
16+
break
17+
else:
18+
i:=i+1
19+
20+
return: res
21+
22+
23+
val is_pal is byte
24+
val input is byte []
25+
26+
writeString: "Give a string with maximum length 30: "
27+
readString: 30, input
28+
writeString: input
29+
30+
is_pal := check_pal: input
31+
32+
if is_pal:
33+
writeString: " ... is palindrome\n"
34+
else:
35+
writeString: " ... is not palindrome\n"

0 commit comments

Comments
 (0)