This question already has answers here:
How to get all the unique n-long combinations of a set of duplicatable elements?
(5 answers)
Closed 3 years ago.
I am trying to save every combination of AAAAAAAA - ZZZZZZZZ to a text file. So far after having many many errors, I have got almost nowhere. I could post my code if needed, but it doesn't work or get near the wanted outcome.
So I was wondering how to do this in c#. My method at the moment is beyond repair, I will have to start all again in order to fix this.
As the output I would like something along the lines of
AAAAAAAA, AAAAAAAB, AAAAAAAC ... ZZZZZZZX, ZZZZZZZY, ZZZZZZZZ
Thanks in advance for any help.
This is a basic combinatorics question:
You want to write a string of 8 characters.
Each character can be a letter between A-Z (26 options), therefore, there are 26^8 combinations: 26*26*26*...26.
That is 208827064576 combinations.
Each combination is 10 bytes (8 for string, then \r\n), which is a total of 1944.85 GB.
Are you sure you want to write it to a file?
This will take about 1.5-2 Terabytes. That's a huge text file to start with, probably impractical.
Secondly, the way to do this simply is to have 8 nested loops, each running through A to Z, then concatenate the string inside the inner loop, appending to the data store each time.
Related
This question already has answers here:
Regular expression for version numbers
(8 answers)
Closed 2 years ago.
I have a required to validate the version numbers using regex. I tried few but not working as expected.
Any idea what regex to use to validate versions like 1.0.10.135 in C#. Every number should grow upto 3 digits in each section.
Update I tried this "[\d]{1,3}.[\d]{1,3}.[\d]{1,3}.[\d]{1,3}" and it accepted "1.0.0.3##", which is not correct.
If you want to go with a regex, I'm surprised you haven't found one that worked. Here's a quick one (it worked the first time I tried it):
(?<major>\d{1,3})\.(?<minor>\d{1,3})\.(?<patch>\d{1,3})(\.(?<build>\d{1,3}))?
It names the parts, and makes the last part optional
This question already has answers here:
How to calculate distance similarity measure of given 2 strings?
(7 answers)
How to compare two rich text box contents and highlight the characters that are changed?
(3 answers)
Closed 5 years ago.
What I need to do seems simple enough but I can't seem to find a good way to do it. My app reads text off of a document but sometimes gets it wrong. Users are allowed to change the text in a verification step. What I need to know is how many characters changed, including case.
For example,
Original value: i23 MAin St
Value changed to: 123 Main Street
The number of characters changed in this instance would be 6. I then need to capture this value in a variable for later use. Is there a good way to do this in c#?
This question already has answers here:
Counting the occurrences of every duplicate words in a string using dictionary in c# [closed]
(3 answers)
Closed 6 years ago.
I am making something like, the user will input any url and the text will be obtained.
The text will then be parsed and the words will be counted.
I am currently reading this article from microsoft:
https://msdn.microsoft.com/en-us/library/bb546166.aspx
I can now get the text and i am currently trying to think of an efficient way to count every words.
The article example required a search data but i need to search every word and not a specific word.
Here is what i am thinking:
get the text and convert it to string
split them (delimiters) and store in array
loop through the array then check every occurrences of it.
would this be efficient?
Using Linq
If you have a small amount of data can just do a split on spaces, and create a group
var theString = MethodToGetStringFromUrl(urlString);
var wordCount = theString
.Split(' ')
.GroupBy(a=>a)
.Select(a=>new { word = a.Key , Count = a.Count() });
see fiddle for more a working copy
Some Experiments and Results
Messed around in .net fiddle a little bit and using Regexs actually decreased the performance and increased the amount of memory used see here to see what I am talking about
Other alternative
Because you are getting the request from a Url it might be more performant to search inside of the stream before converting it to a string and then performing the search
Don't optimize unless you need to
Why do you need to find a performant way to do this count? Have you run into any issues or just think you will, a good rule of thumb is generally not to prematurely optimize, for more information check out this good question on the topic : When is optimisation premature?
This question already has answers here:
Comparing list of strings with an available dictionary/thesaurus
(2 answers)
Closed 7 years ago.
I'm using C# to write a program that generates lines of text over and over. The user enters a set of numbers, 1-26, in whatever order, and the program matches each number to a letter.
The point is to have it go through every order of the alphabet until it eventually generates an actual word. For example, someone could enter 7-2-15-26-3, and it would eventually read that set of numbers as "hello".
I got the program to work and to print every outcome to a txt file, but because there are so many different possible outcomes, it is almost impossible to find an actual word in the file without going through every single line.
One of my tests only had 11 letters to choose from, it took a few minutes to finish and the txt file was so big, it would not open.
So my question is, does anyone know of a library or spell check that I could use to check if each string is an actual word? If I could check it each time, I could have it only print the outcomes that are words. I would have it check against preset words, but I won't always know what the outcome will be so I need to check against everything.
I have searched online but haven't found much. Again, I'm using C#. Thank you for any help.
Edit: Sorry about asking a question that had already been answered, I didn't see the other question before. I'll try the NHunspell and see how that works.
Try Nhunspell, it's free (.Net version of popular "Hunspell")
E.g.
Check Spelling,
bool correct = hunspell.Spell("Recommendation");
Get suggestions,
List<string> suggestions = hunspell.Suggest("Recommendatio");
More c# code samples
I suggest that you incorporate an english dictionary into your application so that you have something to check against.
Every time a new word is generated, it checks through the dictionary and takes all the matching results through regex and returns null if no word matches.
Hope this helps.
This question already has answers here:
Determine a string's encoding in C#
(10 answers)
Closed 9 years ago.
I have a string read as a UTF8 (not from a file, can't check BOM).
The problem is that sometimes the original text was formed with another encoding, but was converted to UTF8 - so the string is not readable, sort of gibberish.
is it possible to detect that this string is not actual UTF8?
Thanks!
No. They're just bytes. You could try to guess, if you wanted, by trying different conversions and seeing whether there are valid dictionary words, etc., but in a theoretical sense it's impossible without knowing something about the data itself, i.e. knowing that it never uses certain characters, or always uses certain characters, or that it contains mostly words found in a given dictionary, etc. It might look like gibberish to a person, but the computer has no way of quantifying "gibberish".