 |
|
 |
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
 |
|
 |
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
 |
|
 |
I have a set of parallel-ish lines (they may not be parallel, but they don't cross) that define an area. On each line, I calculate two points (lets say P1 and P2) which define an operating region. With an ordered set of lines, I know for line 1 (L1), the polygon showing the operating region starts at P1 and ends at P2. The next point in the polygon is L2P1, whereas the (n-1)th point is L2P2 (where n is the number of lines I have).
My problem is:
1) Lines may be drawn either way, so P1 and P2 in two 'adjacent' lines may not be on the same side.
2) Lines may not be in order.
So, knowing the number of lines, and which points belong to the same line (i.e., I know which points are paired),
can I calculate the order of the lines / points, so that I can draw my polygon?
It seems like a hulling problem, but is there a way to say 'all these points are on the hull boundary'?
Wouldn't that lead to multiple solutions for certain sets of points?
|
|
|
|
 |
|
 |
Actually - is this a travelling salesman problem?
|
|
|
|
 |
|
 |
Can you show some diagrams of the possible scenarios? I'm not sure I have it entirely clear in my head.
If the hull is known to be convex, and we're talking 2D, I would take an approach like:
- find a point inside the shape (the average location of all the control points should do)
- go around the control points in order of angle from that central point
I don't think the pairing of points on the same line matters, once you have the collection of points.
|
|
|
|
 |
|
 |
I have to write a program in java for wordwrap with minimum regard...
for example if we have "aaa bb cc ddddd" and want to wrap it in lines with this method the final form should be like this :
------ Line width: 6
aaa Remaining space: 3 (cost = 3 squared = 9)
bb cc Remaining space: 1 (cost = 1 squared = 1)
ddddd Remaining space: 1 (cost = 1 squared = 1)
attention that we don't know number of lines...I don't understand the algorithm which is in wikipedia ,in this link :
http://en.wikipedia.org/wiki/Word_wrap[^]
but unfortunately I still have problem with understanding the algorithm...can some one explain it with example for me ?
|
|
|
|
 |
|
 |
You have already asked this question in Q&A. Read the guidelines, and ask your question ONCE if you don't want to annoy people who might otherwise have an answer for you.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
 |
|
 |
Hi...I wanna write a program in java that can count the number of balanced matrix of N*N...the only way that I know is to consider all the possible assginments for the matrix and then choose the answers...I searched the topic and found something about it in wikipedia...it solved the problem with dynamic programming but unfortunately I don't understand exactly the algorithm...can anyone help and explain completely with example for me what to do ?
this is the link that I found :
http://en.wikipedia.org/wiki/Dynamic_programming#A_type_of_balanced_0.E2.80.931_matrix[^]
|
|
|
|
 |
|
 |
plz can anyone tell me how to store the data in text file using file handling in java...
plx Mail me comprehensive program of file handling, explain with comment and few of explanation...
asadali.nazir@gmail.com
|
|
|
|
 |
|
 |
See here[^] for all the information you need.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
 |
|
 |
Unless you want a lot of spam in your inbox, please do not put your e-mail address in a message posted publicly.
"Science is facts; just as houses are made of stones: so, is science made of facts. But, a pile of stones is not a house, and a collection of facts is not, necessarily, science." Henri Poincare
|
|
|
|
 |
|
 |
This article: Graphical solution to eight queen problem[^] mentions "the old algorithm from Horowitz-Sahani". Does anyone here have more information on this? I haven't found anything online, I'm thinking it's only in a text book.
|
|
|
|
 |
|
|
 |
|
 |
Ah, good, thanks. That first one still just shows the snippet* posted in the article I mentioned, I was hoping to see more on the algorithm.
* And that's what I came up with on my own last week.
Also, I note in the second one that he's using recursion -- my algorithm is non-recursive.
P.S. I just ordered a used copy of that book from Amazon.
modified 1 Jan '12.
|
|
|
|
 |
|
 |
I would be interested in seeing your algo to see how it stacks up with some of my algos for removing recursion.
Dave.
|
|
|
|
 |
|
 |
Once I've seen what's in the book I'll decide whether or not mine is unique enough to form an article.
|
|
|
|
 |
|
 |
The book arrove today. My code is very much like the code they show on page 338 with two main differences:
0) They have the test in a separate function and therefore a global array.
(Which also has a needless call to ABS.)
1) They have an extra while loop.
public static System.Collections.Generic.IEnumerable<System.Collections.Generic.IList<int>>
nQueens
(
int HowMany
)
{
int[] board = new int [ HowMany ] ;
int row = 0 ;
board [ row ] = -1 ;
while ( row >= 0 )
{
board [ row ]++ ;
if ( board [ row ] == HowMany )
{
row-- ;
}
else
{
int i ;
for ( i = 0 ; i < row ; i++ )
{
int diff = board [ row ] - board [ i ] ;
if ( ( diff == 0 ) || ( System.Math.Abs ( diff ) == ( row - i ) ) )
{
break ;
}
}
if ( i == row )
{
row++ ;
if ( row == HowMany )
{
yield return ( System.Array.AsReadOnly ( board ) ) ;
row-- ;
}
else
{
board [ row ] = -1 ;
}
}
}
}
yield break ;
}
|
|
|
|
 |
|
 |
Thank you for your reply. I gather that this is your algorithms since it only has one "while" loop. It may take me a while to digest this, I am primarily a MASM developer, but come here for algorithms.
Do you have any guesses as to how large "HowMany" can be and not run out of memory, i.e., what would be the maximum n for nQueens with this algo?
Dave. (Another Desert Rat from West Phoenix)
|
|
|
|
 |
|
 |
Oh, yes, that's mine. The book uses a Pascal-like language the authors created called SPARKS.
On my system (Win 7 32bit, 4GB RAM), somewhere around 438330000 depending on what else is going on:
C:\Projects>nQueens 438330000
^C
C:\Projects>nQueens 438335000
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at PIEBALD.Lib.LibMth.<nQueens>d__0.MoveNext()
at PIEBALD.Utilities.nQueens.Main(String[] args)
I have heard that .net limits the size of a structure (e.g. an array) to two gigabytes.
Member 4194593 wrote: Desert Rat from West Phoenix
Ah, then I invite you to join the Tosche Station group. http://www.codeproject.com/Members/Tosche-Station[^]
modified 11 Jan '12.
|
|
|
|
 |
|
 |
Does .net limit you if the /3GB switch is used in c:\boot.ini.bat?
Dave.
|
|
|
|
 |
|
 |
I expect so, but I haven't tried it.
|
|
|
|
 |
|
 |
If you go to try it, be aware if the pitfalls:
Boot.ini is System,Hidden,Readonly.
I think you need to be Administrator.
Change the permissions to R/W.
Even as Admin you cannot edit boot.ini with ordinary editors, use RUN NOTEPAD.
Open boot.ini
Change [OS] multi(0)... and add /3GB.
Save boot.ini
For your own safety, change permissions back to RO.
Boot the system.
Also, you do have a good disk image backup don't you?
Dave.
|
|
|
|
 |
|
 |
Ah, thanks, but I'm not going to try it.
|
|
|
|
 |
|
 |
Message Automatically Removed
|
|
|
|
 |
|
 |
Turing Machine Simulator
Write a program that simulates a Turing machine (Tm). A Tm is a primitive model of a general purpose computer. Programs for a Tm consist of a collection of quadruples, each of the following form:
<state> <symbol> <action> <nextstate>
where
<state> ::= a non-negative integer
<symbol> ::= 1 | B
<action> ::= <symbol> | L | R
<nextstate> ::= a non-negative integer
A Tm stores data on a tape divided into squares, each of which contains one symbol, either 1 or B. Only one square can be inspected at a time. Initially, a sequence of symbols is written on the tape (this is the input to the Tm), the Tm's "read/write head" is positioned over the leftmost symbol, and the state of the Tm is set to some "start state".
At any point in a Tm computation, the Tm is in a particular state with its read/write head scanning the symbol in a particular square. What happens next depends on whether the Tm's program contains a quadruple whose <state> is the Tm's current state and whose <symbol> is the symbol contained in the square currently being scanned. If such a quadruple exists (there cannot be more than one such), the <action> part of this quadruple controls what happens next:
if <action> specifies a symbol, then that symbol replaces whatever symbol is in the square currently under scan
if <action> is L, the Tm's read/write head is moved one square to the left (the symbol in the square previously under scan is not changed)
if <action> is R, the Tm's read/write head is moved one square to the right (the symbol in the square previously under scan is not changed)
After one of the above actions is done, the Tm changes to state <nextstate> and we repeat the process of searching for an appropriate quadruple to "execute". This is continued until no quadruple matches the current state and symbol under scan, in which case the Tm halts and we consider its output to be the sequence of symbols between the first and last 1's on the tape, inclusive (if no 1's remain, we consider the output to be just B).
The input is a sequence of Tm instruction quadruples followed by a "start" line that specifies the initial state for the Tm, followed by the sequence of symbols that make up the initial value stored on the Tm's tape. Generically:
<state> <symbol> <action> <nextstate>
<state> <symbol> <action> <nextstate>
<state> <symbol> <action> <nextstate>
<state> <symbol> <action> <nextstate>
...
start <state>
<symbol>
<symbol>
<symbol>
<symbol>
<symbol>
...
For example:
0 1 R 0
0 B 1 1
start 0
1
1
1
1
Given the above input, the output should be:
11111
Note
If a quadruple requires moving left from the leftmost symbol on the tape, or right from the rightmost symbol, a square containing the symbol B must be added to the appropriate end of the tape (which is thus "finite, but unbounded")
|
|
|
|
 |