Bubble Programming Challenge: 3 – Palindrome Checker

So… it’s Friday again… time for another Bubble Programming challenge…

The concept is simple:

The Palindrome Checker Challenge


A Palindrome is a word, phrase, number, or string of text, which is the same backwards as it is forwards (e.g “radar”, “1234321”, etc.).

The challenge is simple:

Using only vanilla Bubble, create some logic to determine whether a text, input by the User, is a palindrome or not.

Here’s an example: Palindrome Checker (bubbleapps.io)

as before - No plugins, and No custom code allowed (at least initially… once you’ve solved it with Vanilla Bubble, feel free to try the same with plugins/code if you like to compare).


**notes**:

There are at least two different approaches here, and depending on which one you take you may run into some issues/limitations of Bubble which make this more challenging than it should be.

My first two attempts to solve this were rather more complex than they needed to be - but there is a relatively clean, and simple way to do this with Vanilla Bubble, although it took me 3 attempts to find it (you might find it straight away!).

Also, be sure to check that your solution is 100% accurate… there is one particular pathway to solving this which (due to how Bubble works) might lead you to a false sense of success here, giving the correct result most, but not all of the time.

Also, in my example I’m ignoring spaces and capitalization, but considering punctuation. It’s up to you how you approach that.

Give it a try :slight_smile:

6 Likes

Damnit, Adam… when you post these, my productivity on anything else goes to sh*t until I come up with a solution! Hmm, can I bill you? :slight_smile:

nope

yep

Editor link coming via DM.

Thanks again for posting these, Adam… they really are fun and interesting.

4 Likes

Good one, “Madam, I’m Adam”.

4 Likes

Are we limited by the possibilities of the Free plan? :upside_down_face:

Nope… not at all (all my solutions to these challenges are on the free plan)

Love these challenges!

2 Likes

DONE
Preview : tutorial_bubble

1 Like

FYI, @amer… I just gave it a quick test, and it doesn’t seem to be working.

challenge

1 Like

Yes , because my previous solution is for integers only
but now is for both string and integers


thanks :revolving_hearts:

2 Likes

As I mentioned in my first post… this is a bit more challenging than it might first appear, and there’s at least 1 Bubble ‘trap’ that people might fall into with this…

Whereby, due to a particular way that Bubble works, certain strings which aren’t palindromes will be evaluated as palindromes incorrectly…

An example of such a string is “abcecaba” which is not a Palindrome.

If you’ve fallen into this particular trap, your solution will say that it is a palindrome.

@amer it looks as though you’ve fallen into this trap :slight_smile: (I’m sure you’ll figure it out…)

image

For anyone else attempting to solve this, be sure to test your solution with “abcecaba” (or a similar string) to check if you’ve avoided the issue…

OK @adamhholmes I will fix it
but you I test your solution seem to have a problem Madam is not palindrome !!.

  • Madam is not a palindrome. A palindrome is a word or phrase that reads the same backward as it does forward. Madam reads “madam” backward, which is not the same as the original word.

we have to think together for good solution

Huh, @amer? How does madam not read the same forward and backward? It is definitely a palindrome.

2 Likes

@mikeloc
madam is palindrome
but
Madam is not palindrome

Ah, okay… you’re being technical about the capitalization (which isn’t standard when determining a palindrome). In my solution, I lowercased the string as I was checking it, so mine would also show Madam as a palindrome. In the spirit of the challenge and the manner by which I think most folks would judge if you have successfully completed the challenge, it’s a palindrome.

2 Likes

@mikeloc I understand that you think that Madam is a palindrome because you lowercased the string before checking it. However, the definition of a palindrome is a word or phrase that reads the same backward as it does forward, regardless of capitalization. So, Madam is not a palindrome because the letter “M” is different from “a”.

OK, challenge as you say, but one of rules of palindrome is

  • Palindromes are case-sensitive, so the capitalization of letters matters when determining if a word is a palindrome.

but if question need as you say no problem

As I pointed out in the initial post, I’m ignoring capitalization and spaces in my example - because that’s the standard way to determine a palindrome.

Obviously it’s easier to make it ‘strict’, and just check the exact characters, than it is to ignore those things - but it’s not important in this case, and the challenge clearly stated it’s up to you how you decide to handle that:

So either ignoring spaces, cases, and punctuation, as if they weren’t there (the standard way to determine a palindrome), or including them in the evaluated string (a more strict version) is entirely up to you.

3 Likes

Seems to work:

P.S. Ignoring spaces, cases and punctuation cause I spent too much time on overthinking and complicating things during solving this pretty simple task. And now I’m too lazy on a Friday evening to apply few more operators :neutral_face:

3 Likes

Done :slightly_smiling_face:
In the path to complete the solution of all challenges i
preview :tutorial_bubble


2 Likes

@artemzheg Nice work…

So, as I mentioned in my initial post… there are two main approaches to this (that I can think of anyway)…

The first way is to compare the first and last characters of the string… then the next two, and the next two and so on (until you reach the middle)…

The other way is to reverse the string and compare it to the original string.

and I’ve now seen both of them used to solve this.

Both methods involve first splitting the String up into a list of its characters…

Initially, I thought that was a much harder thing to do in Bubble than it turned out to be…

With JavaScript it’s simple (again)… you can split by an empty string split('')… but in Bubble you can’t do that…

For some reason, it just won’t allow you to split by an empty string, no matter how you try to do it.

So my initial attempts at this involved breaking up the string with a combination of truncating and truncating from end… and adding each character to a list…

But that once again raised the issue of not being able to add things to a list if they’re already in the list…

So I had to use the workaround of creating a text containing a unique index number, then splitting that text to extract each letter, and comparing the first and last.

Here’s my initial solution (It’s messy, and a bit slow… but it does work):

Palindrome Checker | Solution 1 (bubbleapps.io) (I’m not especially proud of this attempt)!!


Of course, I’d overlooked (as I so often do) the simple regex solution to splitting a string into it’s component characters… (as pointed out by @romanmg in a previous challenge), which certainly makes this a lot easier…



So there’s a much cleaner and simpler way to do this than that… although it does open up the possibility of running into another issue with Bubble lists (that I’ve already mentioned), which a few people (including me) have run into - and teaches a useful lesson about how to do certain list operations in Bubble.

I’ll post my more elegant solution to this in a few days time, as well as explain the issue with the sometimes inaccurate evaluation of the palindrome, once hopefully a few more people have had a go and maybe come up with some alternative ideas.

4 Likes

Nice job… that’s definitely working 100% now :slight_smile:

2 Likes