extinctsion / lyrchel_number

MIT License
0 stars 3 forks source link

Optimize Performance by Avoiding String Conversions in Palindrome and Number Reversal Checks #7

Open KartikMouli opened 2 weeks ago

KartikMouli commented 2 weeks ago

The current implementation of the lychrel_test function repeatedly converts numbers to strings for checking if a number is a palindrome and for reversing the digits. These conversions can slow down the program when processing large datasets or iterating over many numbers.

Improvement: To improve performance, we can avoid these string conversions and implement direct number reversal and palindrome checks using integer operations. This will reduce the overhead caused by converting numbers back and forth between integers and strings.

Proposed Solution:

Number Reversal : Implement a number reversal function that uses integer arithmetic to reverse the digits of a number without converting it to a string.

Palindrome Check : Use the same logic as above to check if a number is a palindrome by reversing it as an integer and comparing it to the original number.

Benefits:

Improved performance, especially when testing a large range of numbers. Reduced memory usage as we avoid unnecessary string operations.

KartikMouli commented 2 weeks ago

@extinctsion i would like to work on it ! can u please add hactoberfest label and assign this issue to me.

extinctsion commented 1 week ago

@KartikMouli sure, Ill assign this issue to you. Happy coding!

KartikMouli commented 1 week ago

@extinctsion I have created the pull request. Pls review !

extinctsion commented 1 week ago

Okay. I'll check it in few days. Don't worry