+ 1
How do I make my code simpler?
I've been solving a lot of the hard code coach challenges but I can't help but feel like my code is too long and more complex than it needs to be. Is there a way for me to improve in that area. As in, how does one review their code and improve it? Is it just a matter of proficiency? Does anyone know of a logical method/steps/thought process I can use in order to improve in this area. I'll link some of my code. I'd appreciate any feedback or review of it. Thank you. https://code.sololearn.com/cwnA8C0JNh0L/?ref=app https://code.sololearn.com/ceZYz3Fc06L3/?ref=app
7 Réponses
+ 6
I think the issue you may be having is your choice of algorithm rather than your implementation of it as such.
For the security problem, you can simply remove all x's from the string. Then just raise the alarm if 'T#x27; or '$T' appears in the remaining string.
For the sign one, you don't need to put all words into a list (if I have read it correctly). You just need to check if any word is a palindrome (if str1 == str1[::-1]).
Simpler code comes from simpler algorithns. I don't think your code is overly long for what you were trying to do 😉
+ 5
Yes! Coding is so much about working out how to solve a problem as efficiently as possible. There are countless ways of solving any problem, but the real skill is in finding the most efficient.
Of course, it is still important to keep your code as clean and as readable as possible since you (or somebody else) may need to cone back to it later, and unclean code can be very challenging to read/decipher what it does!
+ 4
Chey Brown you can always edit your question after posting.
edit : your code is nothing but the link at the end of your question description.
you have got 3 of them
1) https://code.sololearn.com/cwnA8C0JNh0L/?ref=app
2) https://code.sololearn.com/ceZYz3Fc06L3/?ref=app
and this is the reapeted one 👇
https://code.sololearn.com/cwnA8C0JNh0L/?ref=app
+ 3
The first link and the last are the same. Sorry, I posted it twice by accident 😅
+ 2
Wow! So it's more about me asking myself "is this the most efficient solution to this problem" as opposed to "is this the simplest way to code my solution / algorithm to this problem"?
+ 1
I tried but I couldn't get rid of the inserted code. Only the question and description part. Don't know if it's an issue with my phone though
+ 1
Arsenic Thank you, I was able to figure it it thanks your explanation. So much for being a problem solver 😅