|
Yes, it is like a snake. The word 'abj' form your example isn't valid according to the rules of the game. Each next letter must be a neighbor to the previous. For example: 'adi', 'hec'...the word 'ada' is not valid (a letter from a box of the matrix is used only once).
I was thinking of a solution with combinations and a check if the letters are neighbors (this is only an idea, I haven't thought about it much) .
Still learning...
|
|
|
|
|
Hi,
I have several remarks:
1.
From every position you could move to 8 adjacent squars, however you only have 7 SeekWords calls; you skipped one, it will become even slower!
2.
I don't see the word length anywhere in your code; the code as it is will search for all the longest words; i.e. on a 5*5 board it will find several 25-character words, and a lot of shorter ones because "the head of the snake" gets caught in a dead-end. On a 6*6 board, it will find several 36-character words, and a lot of shorter ones, including all the ones found for a 5*5 board. The complexity of the job is more than exponential in z, where z is the size of the board.
Therefore, there is no decent general solution; it grows at an enormous pace.
3.
However, there are ways to improve, not so much by changing the algorithm (you have to investigate all possibilities, there is no escape), but rather by changing the implementation. The biggest factor I can see is the matrix. I suggest you smash it into a linear array, i.e. let Grid[0]...Grid[z-1] represent the first row, Grid[z]...Grid[2*z-1] be the second row, etc.
That means the current position (former x,y) becomes p, and a line such as SeekWords(word + Grid[x, y], visited, x - 1, y - 1); becomes SeekWords(word + Grid[p], visited, p-z-1);
which just is simpler, hence faster.
4.
visited[] could hold booleans instead of ints with values 0 and 1; I don't expect that to influence performance. Also visited[] could be a class member, making it unnecessary to pass it as a method parameter; doing this probably would slow things down, since class members are "farther away" than method parameters.
5.
if x equals 0 there is no need to try three SeekWords(x-1) since they will fail their initial test.
similar for y==0, x==z-1 and y==z-1
you could perform one test inside SeekWords as in
SeekWords(...) {
if (...) {
if (x>0) {
SeekWords(... x-1 y-1)
SeekWords(... x-1 y)
SeekWords(... x-1 y+1)
}
if (x<z-1)>etc.
Of course, in a one-dimensional array it becomes slightly more complex.
One easy and fast way is to make 8 extra boards, one for each direction, initialize them properly and then just do eight times something like if (canStepInDirectionMM[p]) SeekWords( p-z-1)
canStepInDirectionMM[] would contain true everywhere except for those starting positions that don't allow a step in the direction (use M for minus, Z for none, P for plus in both X and Y direction).
Doing so, the complex if at the start of SeekWords reduces to if(!visited[p]) {...}
I expect the above to speed up things by say a factor of 3, so maybe it becomes acceptable for a 6*6 board, but I see no easy way to tackle larger boards unless there were an acceptance test on the words, say "an exact length of N letters", or "all letters appear in alphabetical order". If so, the nesting of SeekWords with be curtailed most of the time, leaving only very few (relatively speaking) combination to be investigated.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
In the code I have posted, some parts are missing, including the one with the word length. For word with maximum length 5 and minimum length 3 is very good. I will consider your suggestions.
I have an idea. If the current word is 4 characters, the program will also search the first four characters of the dictionary words. If there isn't a match, the words which derive from the current also won't have a match.
Current word: ac
Dictionary:
abcde
abefg
abegh
In the example there is no word starting with 'ac', so the words derived from 'ac' won't be in the dictionary. This will save a lot of roaming in the grid.
Still learning...
|
|
|
|
|
Well, I've managed to accomplish my goals. Before the program searched words with max length 8 letters for about 3 minutes. Now it searches words with max length 15 letters for less than 4 seconds!
Still learning...
|
|
|
|
|
I made an application with a form that starts another thread.
see: http://www.codeproject.com/script/Forums/View.aspx?fid=1649&msg=2979123
Now when I drag or resize the form the thread blocks
for about 1/4 of a second...
Googled a bit and it seems to be a typical Windows problem,
is there a way around it?
I tought of even using a different proces (with "real time priority")
instead of that 2nd thread, but that's maybe a drastic and complex solution.
|
|
|
|
|
invader82 wrote: Googled a bit and it seems to be a typical Windows problem,
is there a way around it?
No. Considering Windows is not a real-time O/S (despite the priority name), your thread, even under the best of conditions, can be put on hold for a while other things are going on in the system. Your thread is never guaranteed a set amount of time to run, nor is it ever on a set schedule.
|
|
|
|
|
Well, the dragging takes place in the gui thread.
So I made a faster multimedia timer that periodically (about 1ms) invokes a method on the gui thread that:
- Sets the ManualResetEvent
- Does Thread.Sleep(0) to give up his quantum
It will never be 100% reliable, but still, it's way better than before
I know that windows is no real time operating system,
but using some real time middleware is not always an option.
|
|
|
|
|
Hi,
One simple thing you can do to reduce the amount of redrawing when dragging and resizing is to change the performance options for your PC.
In XP, go to the System control panel , click the advanced tab and then the performance button. Under Visual Effects there are a few presets but firstly try the best performance option and see if there is any improvement.
Alan.
|
|
|
|
|
I don't think that is a very good solution...
I found my own solution (not 100% reliable ...)
|
|
|
|
|
How exactly do I set s user to be disabled? I can get the value.. but how do I set it:
bool? AuthenticablePrincipal.Enabled
Gets or set a Nullable boolean vlaue that speecifies whether this account can authenticate...
but how do I set it to false?
UserPrincipal getUser = UserPrincipal.FindByIdentity(context, userName);
getUser.Enabled = false;
Does not work.
|
|
|
|
|
You also need to follow those statements with:
getUser.Save();
If you're already doing that, then I don't know. It's worked for me in the past.
BDF
People don't mind being mean; but they never want to be ridiculous.
-- Moliere
|
|
|
|
|
Well our AD is at server 2008 level.. That wouldn't make a difference would it?
I did try with a save before and it didn't work
|
|
|
|
|
I don't know if 2008 would make a difference or not, sorry.
Jacob Dixon wrote: a save before
No, you have to do the save after.
This is an existing user that's been saved to the store, I'm assuming.
BDF
People don't mind being mean; but they never want to be ridiculous.
-- Moliere
|
|
|
|
|
I have a program that contains a “start time” and “end time” to equal TempHours
I would like dHours to be the rounded figure.
I am trying to round the number up to next tenth of an hour
(IE 4.11 hours is 4.2 hours but 4.10 hours stays at 4.1 hours)
What do I need to add to the below statement to get it working
decimal dHours = Math.Round(decimal.Parse(TempHours.ToString()),3);
Thanks
|
|
|
|
|
ok,
Two questions for you
1) What does not working mean?
2) What type is the TempHours variable?
Alan.
|
|
|
|
|
Why are you changing it to a string?
If TempHours is already a numeric type (single, double, decimal, etc), just do this:
decimal dHours = Math.Round(TempHours, 1, MidpointRounding.AwayFromZero);
Second parameter is the number of decimals. 1 = To the nearest tenth. Third parameter tells it you always want to round up to the next value, never down.
|
|
|
|
|
Hi,
why would you call ToString() and then Parse() to turn a number into another number? This is nonsense, as it wastes lots of CPU cycles: numbers are stored in binary for a reason, it takes a lot of divide-by-10s to perform a ToString() on a number.
Math.Round does rounding in the regular way, i.e. 1-4 go down, 5-9 go up.
However you want 1-9 to go up, hence add 0.04 to the original number, then use Math.Round
Warning: you did not define how it should work for negative numbers; whatever straight code you come up with, there is a 50% chance it won't do what you want for negative numbers. If so, test for negative, and provide two different formulas.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Thank you all for your replies. Great info! Although I didn't write the orig code, I'm learning quite a bit in trying to get it to work.
|
|
|
|
|
protected void Page_Init(object sender, EventArgs e)
{
RadioButtonList rbl = new RadioButtonList();
rbl.ID = "rbl1";
rbl.Items.Add("a");
rbl.Items.Add("b");
PlaceHolder1.Controls.Add(rbl);
rbl.SelectedIndexChanged += new EventHandler(rbl_SelectedIndexChanged);
Button btn = new Button();
btn.ID = "btn1";
btn.Text = "Button";
PlaceHolder2.Controls.Add(btn);
btn.Click += new EventHandler(btn_Click);
}
protected void Page_Load(object sender, EventArgs e)
{
}
private void btn_Click(object s, EventArgs e)
{
Label2.Text = "buttons click event fired";
}
private void rbl_SelectedIndexChanged(object s, EventArgs e)
{
Label1.Text="radiobuttonlist control selectedindexchanged event fired";
//RadioButtonList rbl2=(RadioButtonList)s;
//Label1.Text = rbl2.SelectedValue;
}
Jyoti Goel
|
|
|
|
|
there is no working SelectedIndexChanged in RB, use CheckedChanged instead
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
|
Have some patience, it is considered bad form to repost.[^]
hmmm pie
|
|
|
|
|
Another deleted post???
...No, just someone else posting the contents of thier brain
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Had posted the post in ASP.NET, but didn't know where my post will receive more traffic, since there were C# issues involved. So I double posted! Anyway I've resolved the issue. The original post is in the ASP.NET corner.
Thanks
|
|
|
|
|
The point is that you post it where it's most applicable, NOT where you think it will get the most attention.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|