+ 5

How can we generate a string palandrome from any given string by adding minimum letters to it?

python

26th Aug 2017, 8:42 PM
Balaswamy
Balaswamy - avatar
8 ответов
+ 9
Only adding to the right counts?
26th Aug 2017, 8:56 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
27th Aug 2017, 1:13 AM
hamletmun
hamletmun - avatar
+ 8
Very nice, short and clean code :)
27th Aug 2017, 5:12 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
1232 would only require 1 to become 12321
27th Aug 2017, 12:12 AM
hamletmun
hamletmun - avatar
+ 5
I guess this is too simple? string = input() print(string + string[::-1])
26th Aug 2017, 10:43 PM
David Ashton
David Ashton - avatar
+ 4
I'm guessing you also want the code to find embedded palindromes at the end of the word so less letters need to be added, e.g. 'panini' only needs 'nap' added to make a palindrome and 'lotto' just needs an 'l'. That will take a bit more thinking... 🤔
27th Aug 2017, 12:25 AM
David Ashton
David Ashton - avatar
+ 2
I'd say @hamletmun nailed it.
27th Aug 2017, 1:55 AM
David Ashton
David Ashton - avatar
+ 1
thanks @hamlermun
27th Aug 2017, 3:15 AM
Balaswamy
Balaswamy - avatar