0

How to solve pangram in a more elegant way without using linq or regex

I am on exercism.io to do C# challenges. I solved a pangram challenge. Now I did get some comments from my mentor. I like to implement his comments but I am not sure how to do it. Every attempt I do seems to be less elegant than my first submission. I do not like to use linq or regex (haven't mastered that yet), that seems to easy to me. I am convinced that it can be done without. The comment from my mentor was that the code was hard to read because I am removing characters from my reference. https://code.sololearn.com/c8M41LJW9czQ So I should make a immutable reference. But than I need to keep track on which characters have been detected.

23rd Feb 2020, 4:09 PM
sneeze
sneeze - avatar
4 odpowiedzi
0
Another reverse approach, am not sure about efficiency.. Instead of remove, take sort input, take char count if adjacent are not equals... If count==26 true else false..
23rd Feb 2020, 4:30 PM
Jayakrishna 🇮🇳
+ 4
sneeze This Q&A Post is a bit old. However, I thought I would respond anyway as it might still be helpful. See the first link below where I clean up the original code and the other link where I present a much simpler solution. Pangram Cleaned Up by David Carroll https://code.sololearn.com/cxB4UILIDKnV/?ref=app Notes: - Spacing can work wonders in the code. - Ternary Operator not needed in return statements. - No need for explicit declarations when doing assignment at the same time. Pangram Simplified by David Carroll https://code.sololearn.com/c0GEHi9cYN17/?ref=app Notes: Create a HashSet<char> chars and add characters from the input is between 'a' and 'z'. Then return true if character count is 26.
22nd Nov 2020, 5:04 AM
David Carroll
David Carroll - avatar
+ 1
Good one.. Additionally I just want say, if input contains only alphabetical charecters, then since your using HashSet, Count property give set size so without using for loop, count=input hash.Count-1; will give same result. (-1, excluding space count.) So one more alternatively using a regex that replaces otherthan alphabet with "" empty char, with works in 2 steps... & You're welcome..
24th Feb 2020, 11:04 AM
Jayakrishna 🇮🇳
0
Thanks. I used your approach. Made a hashset (yeah, I can use it now and in a usefull way!!). And checked it against a reference called Alphabet. See the second method in my update code. https://code.sololearn.com/c8M41LJW9czQ
23rd Feb 2020, 9:36 PM
sneeze
sneeze - avatar