(Challenge) Singlify Double Letters | Sololearn: Learn to code for FREE!


(Challenge) Singlify Double Letters

Here's an easy one. Take an input string and replace all double letters with single letters. E.g. Happy Mississippi! => Hapy Misisipi! The only tricky bit may be the shrinking length as letters are removed.

12/26/2017 4:17:07 AM

David Ashton

97 Answers

New Answer


Closed-source-like JavaScript approach. I created both this code itself and the method to convert normal JavaScript source code to closed-source-like JS. I have a private code to automatically convert any JS source code to closed-source-like JS very easily, but it sould be difficult for other people to reverse the process :) This could be beneficial for companies who want to sell their apps or if the security of an app depends on it being closed source https://code.sololearn.com/WBWYRMIVmv2S/?ref=app




I... I made a little something. :> https://code.sololearn.com/cQ8971friVmg/?ref=app




Ok, got it. https://code.sololearn.com/cM6sEnKa3Emp/?ref=app


I'm late, but it alright πŸ˜€ https://code.sololearn.com/cpmlzQHuw6qD/?ref=app


My JavaScript one-liner https://code.sololearn.com/WvSeUwPZSZVH/?ref=app


https://code.sololearn.com/cfmru654iTXS/?ref=app Simple and straightforward :)


My apologies for not clarifying whether code-created double letters need to be reduced further (I didn't think about it because real words don't have triple and quadruple letters), but 'lasssso' becomes 'lasso' and no problem if your code takes it further to 'laso'. Thanks for all the great efforts!




Congratulations Sir Ashton for Moderator Badge!! and for 100 codes!


I'm having an absolutely impossible time trying to choose a 'best answer' going through all these brilliant innovative clever creative demonstrations of thinking outside the box and learned a whole new bag of tricks in the process. But since it wouldn't be fair to just wander off without naming a winner, I'm going to choose Augustinas Lukauskas's simple but elegant JavaScript that actually works! https://code.sololearn.com/WBWYRMIVmv2S/?ref=app. (I would be pulling out my hair if I had any....) Congrats to everyone for a terrific job!


My try.. https://code.sololearn.com/cXjo3PuWpkfm/?ref=app


Here's mine by the way. Not nearly as elegant as many of the really clever solutions here! https://code.sololearn.com/cGF8xWbsutl0/?ref=app


You can input string https://code.sololearn.com/cfMzkK5EdSBQ/?ref=app


singlify=lambda c:c[0]+"".join(c[i] for i in range(1,len(c)) if c[i-1]!=c[i])


Here's a one liner https://code.sololearn.com/c3Ywr609v43A/?ref=app


Loved the challenge!! Here's mine in C https://code.sololearn.com/c2xKYMbanem6/?ref=app


This code deletes repeated characters: https://code.sololearn.com/c8l5bioH78i7/?ref=app


My try is in Java this time because many Python versions are here. Edit: I am adding Python. :) https://code.sololearn.com/c9Kiu73fUKWF/?ref=app https://code.sololearn.com/cUK7USFdGNv7/?ref=app