Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am very sure that there is a technical term for this problem, but unfortunately I do not know it.
I have an alphabetical charset and the requirement is to create the combination of all the chars with a maximum length
The idea is (sample):
Generate a collection of A, AA, AAA, AAAA, AAAAA, AAAAAA
Next: A, AB, ABA, ABAA, ABAAA
Next A, AB, ABB, ABBA, ABBAA
The reason:
We have to query an API that delivers search results.
But if I don't get search hits from the API on AAA, I don't need to search for AAAA anymore, because it can't get search hits either. I can then move on to AAB.
The question:
My problem is that I'm not sure how the code has to be built to achieve this goal. I lack the structural approach.
I've already tried nested loops, but unfortunately I don't get the result.
I also used Combination Libraries, but they focus on other problems.
Many thanks for hints!
What you're looking for is a particular data structure called a Tree, but probably more specifically in your case, a Trie.
Trie data structures are commonly used in things like Autocomplete. With the image below, if someone typed "te", I can traverse the Trie and see what options would come after that (tea, ted, ten).
It looks like this would also fit your use case from what I can tell.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
How can I get my NPC AI to locate all objects within X distance, identify each object and then be able to Target a specific object?
An example being:
The AI is in an area, and there are 4 objects within it's range. Those objects are 2 tree, a rock, and a pig. The AI needs wood, and then will need some rock. How do I get the AI to be able to identify the 2 tree, the rock, and the pig, and then go to a tree, and then go to the rock?
To search for certain type objects:
var foundObjects = FindObjectsOfType<TextMesh>();
https://docs.unity3d.com/ScriptReference/Object.FindObjectsOfType.html
To locate them (note that foundObjects is object[], you need to loop over them):
foundObject.transform.position;
Needs can be stored in priority queue. It is basically self ordering data collection, if you solve the highest priority task of ex: finding 2 wood, it will get you the next highest priority task to do.
This question is broad, There are so many aspects to going about this. I suggest attempting one aspect / researching it. Once you come to a stump in code that you cant understand, come ask. If I had to suggest a starting point, I would look up how to code the distance from one object to another. Then look up how to do that for multiple objects in a scene. Then look up how to identify those, whether it be by Tag or GameObject, etc..
Start from there, I wish you the best of luck on your journey!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Let's say I have few points : -5,-4,-3,-2,-1,0,1,2,3,4,5
I'm at point 0, I need to create a line that goes all through the points of 1,2,3,4,5,-1,-2... etc.
The line would start at 0 and end at whatever point that ends as the shortest.
The answer for this example would be that it'd go like this 0->1->2->3->4->5->-1->-2->-3->-4->-5 or that it'd go first to -1 and go all through the minus to the plus, same result (5*4=20 length).
If for example we'd go 0->1->-1->2->-2... it'd end as the longest line that goes straight from point to point (1+2+3+4+5+6+7+8+9+10=10*11/2=55 length)
The question is how to write this in code?
The points might also consist of 2 or 3 dimensional points, where the start would be (0,0,0,0) or whatever, eventually the line can go through all of these points, but which way will achieve the shortest line?
How to make it as a code, as we see it in the eye?
I think this is basically the Travelling Salesman problem. You've got N destinations, and each pair of destinations has a concrete length between them, and you're trying to find out the shortest travel time to visit all destinations.
You've got two different directions to pursue this, that I can see. First, is to read up on the Travelling Salesman problem and the various algorithms that have been proposed for it (it's a very famous algorithm problem) and then try to implement one in C# - though just to warn you, you should be very proficient in math, because it's not an easy problem. Or, alternatively, you can look for someone else's existing implementation for it and just use it without understanding the theoretical underpinnings.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Hello experts, I have to generate series of folders from a TextBox into specified location.I am having two textboxes to specify the limit of folders(say 30 folders).The problem am facing is that the folder names that i will be providing are alpha-numeric(say 121cs3h101) .
How to set limit when i provide an alpha-numeric values?
(For example: i provide textbox1=12cs3h101 and textbox2=12cs3h131 , i need the series limit to be generated). I am working with visual studio 2013 in c# windows form application. Thanks in advance.
ok I will try to give you a lead.
To parse a string or find specific characters one can use RegEx.Match or a simler method called String.Split. In both cases you have to be aware how your string is structured and how it can vary. The limits of variation are very important.
If as you say the beginning is always"12cs3h" you can either split the string at the character 'h'.
string[] sa = s.Split('h');
Or you can even use the index of 'h' (since the length seems to be fixed) and take the rest of the string to get the numbers.
int index = s.IndexOf('h');
The rest is up to you, ... convert, enumerate and so on.
EDIT: There is a nice method that does the enumeration job for you: Enumerable.Range Good luck
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a list of terms (words), say around 500,000, they are loaded into some data structure, like a Dictionary or Trie perhaps.
In my program I want to open each text document and search for occurrences of these terms. When i find one I want to stop and transform the string in the text file (replacing it with the transformed string), and continue searching. Once complete with the file, I write to disk the new modified file.
My questions are as follows
What would be the best data structure to use for this purpose - a Tree type structure or .NET Dictionary
How do i search the text? Do I break it up into words and compare each chunk against the list I have, or some other method like RegEx, or .NET methods like Contains()?
I'm just looking for some advice on where to start, because I think speed will be really important when I'm dealing with very large and numerous text files.
EDIT: Yes the Transformation is same for each string - based on an algorithm - so each string will look different though. (like for example using a Cipher on the word to make is unreadable. Anyway I'm just looking for someone to point me in the right direction, I'm not familiar with many algorithms and data structures out there.
From a class I took once, I remember we covered a couple of different algorithms. Here are the ones that I remembered to be pretty effective with large text files...
Boyer-Moore:
http://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_search_algorithm
Knuth-Morris-Pratt:
http://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm
These will only help with the lookup, then you can do the manipulation yourself
A hash table (Dictionary) is going to give you faster lookups than a tree structure. A well-built hash table can find a matching word entry with two or three probes, while a tree structure may require up to an order of magnitude more comparisons.
As for splitting up the words, it would seem to be simple enough to collect all alphabetical characters (and possibly digit characters) up to the next whitespace or punctuation character for each word. You will probably want to convert each word into all-lowercase before looking it up in the dictionary.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
In one of the interview I was asked to test a method. The details are mentioned below. Though I could answer , still they were expecting some more test cases. Am I missing any scenarios here ?
string concatenatefunc(strin1,string2).
{
//returns concatenation
}
This method accepts two string parameters and returns the concatenation. No other details are mentioned. I need to test this method and i have written below scenarios/unit test cases:
1.Pass empty parameters and see empty string is returned
2.Pass valid non empty strings and see the string returned is correct or not.
3.Pass the special characters in the both the parameters and test the response.
4.Pass integers and test the response.
5.pass large strings(not sure what we can give as the max length) and test the response.
....
Anything to add here?
You're not testing for null parameters.
Test for multi language support. An area that many developers fail to test which can give a guy like me problems. I have the danish character 'ΓΈ' in my name. This has been a problem in my web based interactions with several VERY BIG companies including software companies, preventing me from logins, accounts, payments etc.
Number 5 will really depend on the size of available resources so testing that might be problematic.
You could add tests for either parameter being empty and see if the non-empty parameter is returned
Same for Passing integers, test if either parameter is integer
Then you could start mixing them empty/integer, non-empty/integer, etc. and reverse