blob: 0395d94fac65665d011ec1d0f9286ec228684f60 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
def is_palindrome (instr)
return instr == instr.reverse
end
def find_palindromes (input)
print input, ": "
seen = {}
for start in 0 .. input.length - 1 do
for endstr in start .. input.length - 1 do
cand = input[start .. endstr]
if is_palindrome(cand) and not seen[cand] then
print cand, " "
seen[cand] = 1
end
end
end
puts " "
end
for test in ["redivider", "rotors", "challenge"] do
find_palindromes(test)
end
|