

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, slapdowns and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Cofounder
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 Cofounder
Microsoft C++ MVP





My maths is quite poor and I need some help writing an algorithm/pseudo for a simple cost estimator:
rules
I have three inputs x, y and z. The inputs each have a separate max value that if breached return an error. These max values, X = 20, Y = 15, Z = 30.
Now I need a function that compares the inputted values and if possible swaps the values to keep them under the constraints. Also,
Z should always contain the smallest value as long as the swapped value still meets the max value constraints.
So for a few examples if the user entered X=15,Y=5,Z=10 the values for y and Z would be swapped to make z the lowest value. With X=5 Y=18 Z=2 X and Y would be swapped with x to fit under max values. With X=10 Y=8 Z=2 nothing would be swapped. X=31 Y=18 Z=10 nothing would be swapped and you would get an error.
I have written this codepen so far:
http://codepen.io/FredHair/pen/gpvoPR?editors=101[^]
It finds the minVal, medVal and maxVal. I just need some help with the next logic steps for swapping the values.
The values themself represent a bounding box, orientating an inputted box that would lead to a cost estimate.
I have already had a go at writing this into a program but I made numerous logical errors.
If anyone can offer any insight into the maths and best way to write this I can then write the code.
Any help is greatly appriceted, I hope I have made myslef clear, feel free to look at codepen and ask any questions.
Regards,
F





Hi All
I had to solve a specific problem for a client, this problem take some time to come with a original solution, that is working.
What i would like to know is if my solution is a original solution, if it fits as an algorithm or more like a recipe (since is very specific to this problem), and also if it is an original algorithm where should I publish it.
Thanks in avance for your answers.
Now the problem:
I Work with business process management, a common issue in BPM is who to define who does which tasks and how to implement a rule based on the responsabilities and role of the user.
In this case an aproval depend on the CEO (the one that must do the task). However he can delegate the task (everytime or in vacation) to the CFO and Manager A.
Also the Manager A delegates to both the Assistant Manager 1 (AM1) and Assistant Manager 2 (AM2), and the CFO delegates to Finantial Manager A (FMA) and Finantial Manager B (FMB).
So a process may be aproved by any of these groups:
 CEO
 CFO and Manager A
 CFO and AM1 and AM2
 FMA and AM1 and AM2
 FMB and AM1 and AM2
 FMA and Manager A
 FMB and Manager B
Second part:
(Assume CEO  Level 1, CFO  Level 2, Manager A  Level 2, The others  Level 3)
We seen that someone in level 2 can aprove with someone in level 3 of another branch.
However it gets tricky since AM1 (level 3) can delegate its on tasks on CFO (level 2 of the other branch)
So this line
 CFO and AM1 and AM2
turns into 2 lines:
 CFO and AM1 and AM2
 CFO and CFO and AM2 (because CFO only aproves once so it become:  CFO and AM2)
This seems hard, but belive i am not give all the requirements, the real problem as some issues more, but the main question is the one I explained above.
The Solution
I will give the solution, maybe write an article where. However first i want to know if it already exists, or something similar. But google for task delegation returns results obviously nothing to do with this problem.





Hi,
Seems related to oriented graph
Numerous mathematical tools exist for graphs.
So there is little chance that your solution is original, or at least efficient tools already exist for this family of problems.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





Tanks ppolymorphe
I was always looking at trees and not graphs.
After your tip i did some research and i think my solution fits more or less in Direct Acyclic Graph more than oriented graph. The image (of the Hasse diagram) in this site is prety similiar with my solution https://en.wikipedia.org/wiki/Directed_acyclic_graph[^]
I am going to read some more about this.





Rui__Silva wrote: Tanks ppolymorphe You're welcome.
Rui__Silva wrote: After your tip i did some research and i think my solution fits more or less in Direct Acyclic Graph more than oriented graph. Oriented is a direct translation from French, the right translation is Directed
Glad you found what you were looking for.
 If you consider my answer useful, you can up vote it (green arrow when the mouse is on left at beginning of answer).
 If you think the problem solved, change the tittle of your question and add Answered or Solved
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





Anonymous downvote countered.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
 Homer





Thanks you ! Thanks you ! Thanks you all up voters
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
modified 1Jul15 14:36pm.





Hello, everybody.
I've got next problem. There is three objects:
1. first one, with next characteristics: circular area of view, speed, drag coefficient;
2. wind (or water current, doesn't matter; some sort of resistance) with some strength and direction;
3. polygon, concave (in general case).
I need to build path of first object inside this polygon, which will:
1. cover whole polygon by view area;
2. be optimal by travel time;
3. takes into account wind direction and strength.
In other words, I need to carry out exploration in a given area on optimal trajectory while scout can be drift away.
Thanks, Viktor.





Do you have a question?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson





My question, actually, is: what algorithms should I use to build this trajectory?.. I know, that maybe this is strange. I investigate this problem last few days and already have some sort of solution. I just want to find some people who might solve this task earlier.





Viktor Grabarchuk wrote: I just want to find some people who might solve this task earlier. The thing has a location, a direction (vector, some arrow) and a speed (velocity in them expensive manuals)
Once you have those three things in an oject, you can introduce "forces" like gravity.
Do keep in mind that you are asking for something rather complex; there is a huge difference in resistance between wind and water, also depending on the shape of the object it hits, any currents that form due to that shape, any contaminations and other stuff. Other stuff like temperatures of below 0 where water does not tend to flow
Start out with something fun one can easily play with; have a ball bounce on the screen and change the gravity to be equal to the moon. Once you have one force, introducing a new one should not be hard.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]





I have a an array of values like:
array(0.2,0.0,0.4,0.7) min: 0.0 , max: 5.0
and every value represent something and I have some attributes in the database that corresponds to these values. Now what I need to do is I need to search the records from database on the bases of above mentioned array. Kindly suggest me an algorithm that would do something like this. I need something like machine learning that would be able to do this thing with flexibility. What I have found from my research that following algorithm is closer to what I am looking for:
http://www.econ.ohiostate.edu/jpeck/Econ501aL4.pdf
http://www.solver.com/knearestneighborsclassificationexample
For Example: Configuration array => ('attr1'=> 0.2, 'attr2'=>0.54, 'attr3'=>0.66, 'attr4'=> 0.78)
Records:
 attr1  attr2  attr3  attr4 
1) 0.45 0.33 0.55 0.66
2) 0.32 0.12 0.34 0.99
3) 0.78 0.41 0.10 0.74
4) 0.88 0.12 0.74 0.10
5) 0.72 0.02 0.00 0.55
Now I need an algorithm which can get me results (records) using the above mentioned array.






I have a quick question.
Which type of math subjects should i refresh myself on for algorithms class??
Is there any Direct recources i can find for this??
Thankyou






There's no specific math subject that would be more important than others for algorithms in general. The most important skill for developing or understanding algorithms is logical thinking and the ability to break a problem into smaller parts. Unless, of course, if you're going to deal with algorithms for a specific problem domain in particular  like graphics or sound processing  then certain math subjects will certainly be more helpful than others.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson





Not just for algorithms, but for Computer Science in an overall sense  Mathematics for Computer Science[^]. You'll also find video lectures there.
modified 5Jun15 1:48am.





I would say Boole Algebra.
Everywhere you have a condition, it is Boole Algebra.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





Hi friends,
find the θ bound for f(n)=n2/2n/2?
we need to find the upper bound and lower bound.
If anybody know please send the solution with explaination.
Thanks,
Arjun





C
modified 23May15 13:46pm.





Chaitanya Pai wrote: I have tried a lot to arrive at the solution. Show what you have tried and explain what does not work, and people will try to help you. But no one is going to hand you a complete solution.
modified 23May15 8:16am.





I am having a major 'head against wall' problem here...
Given two base 36 values ('A0ZWS0P' and 'A0ZWS9P', for example) and a third (random) value,
how would you go about determining whether the random value was 'between' the starting and ending values?
I am working in 2012 VB.Net





It depends on how you're (internally) representing the values.
If you're using regular .NET integer types (e.g., Int32, Int64) then just compare the values.
If you're using strings to represent the values, then
1. if necessary, pad the strings to the same length (leading spaces or zeros)
2. use a caseINsensitive string comparison.
The string representation is a very poor design for something like this!
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.





My bad, I elided some details....
The values are part of numbering sequences for ticket books. Say I have a book with a number range of '9ER78Y' to 9ER79J', stored as strings ('start and 'end') (not my design, it was inherited). Now I am given a ticket number of '9ER79A' I need to find the book of tickets that contains this ticket.
The only way I can see to do it is a brute force table scan, of over 500,000 books
I am not sure an index would help, unless I added a discriminator column to represent the book start and end range





Do you need to do this within a DB query (SQL), or is the "search" inmemory?
Are there any other constraints on the problem space that might be used to simplify things?
(E.g., are the ranges all exactly the same size? or a multiple of some size?)
If you need to do significant numbers of checking at a time, then some preprocessing of the data while loading into memory is a good tradeoff.
If these are oneoff checks against the DB, then preprocessing is probably not worth it.
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.





You can implement this with a form of binary search.
 [Preparation] Sort the strings representing the first ticket in each book in ascending order:
a. zeropad any short strings (e.g. "ABC1" should be padded to "00ABC1"
b. sort the strings using a caseinsensitive sort
c. pad the list with a dummy ending value (e.g. "ZZZZZZ").
d. pad the list with a dummy starting value (e.g. "000000").
 [Eliminate low values] Use a binary search to find the location of largest value less than or equal to the target string. If the result points to the starting dummy value, then no such value exists.
 [Eliminate high values] Use a binary search to find the location of the smallest value larger than the target string. If the result points to the ending dummy value, then no such value exists.
The range [low, high) contains your result. If low != high, the range should contain a single element that is the desired ticket book. If low == high, no ticket book was found.
Note that you can handle missing books in the sequence by adding dummy book starting values to the array.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time  a tremendous whack.
Winston Churchill





C# (sorry; I don't do "VB")...
IsInBetween( "A0ZWS0A" );
IsInBetween( "A0ZWS0P" );
IsInBetween( "A0ZWS7P" );
IsInBetween( "A0ZWSAP" );
private static void IsInBetween( string value ) {
string s1 = "A0ZWS0P";
string s2 = "A0ZWS9P";
bool isInbetween =
value.CompareTo( s1 ) == 0 
value.CompareTo( s2 ) == 0 
( value.CompareTo( s1 ) > 0 && value.CompareTo( s2 ) < 0 );
Console.WriteLine( "Is {0} between {1} {2}? {3}", value, s1, s2, isInbetween );
}





I will try this....I also am a C# guy, for the last 10 years or so, but the job specced VB so, learn it I did





Good for you ... I've been able to avoid VB.NET thus far (though I did dabble in it back when it was called "Visual Basic 1.0").





And why not use >= and <= operators.
It gives something like:
bool isInbetween = ( value.CompareTo( s1 ) >= 0 && value.CompareTo( s2 ) <= 0 );
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





A base 36 numbering scheme should be the math rappresentation of a normal numer expressed with 36 different ciphers.
It should be quite an easy task to create a function that converts the strings that you have to plain binary numbers (base 2) understandable to the computer. This function is equivalent to an ascii to bin conversion, only the symbols that have top be handled are 36.
The sequence, I suppose, is: 0 1 2 3 4 5 6 7 8 9 A B C D E F G . . . . . Z
The generic rappresentation of a number expressed in base x is:
Vn*X^n + V(n1)*X^n1 + V(n2)*X^n2 + ... + V(0)
In plain the sum of all ciphers by the power of the base at the position taken as exponent.
This is sample to convert a base 36 number to a base 2 numberEDIT: This sample converts any ascii rappresentation of a number in all bases between 2 and 36. It acts as the standard atoi, atol, etc. It converts all applicable characters up to the end of string or the first non number with respect to the choosed base. If the first string char is not a valid cipher, or the string is empty it returns NULL.
long long GenRadVal(char *str, int base)
{
if (base<2  base>36)
return 0LL;
long long val = 0;
for (int i = 0; str[i]; i++)
{
int c = toupper(str[i]);
if ((c < 0)  ((c > '9') && (c < 'A'))  (c > 'Z'))
break;
c = c > '9' ? c  'A' + 10 : c  '0';
if (c >= base)
break;
val *= base;
val += c;
}
return val;
}
This will give you back a 64 bits number equivalent to the string. To go back to the original value you can use itoa() function in C.
Now comparisons are easy..
P.S. the reverse for this function is the stdlib function itoa() with base=36.
modified 17May15 12:01pm.





This will not do a parse of the string as Base 36!
It is treating the 'digits' as in reverse order.
I.e., the rightmost digit corresponds to the highest power of 36.
The representation of nonoverlapping ranges (see other comments above) will not survive this "parse".
Here's one in C#:
static long Parse36(string s)
{
long v = 0;
foreach(char c in s)
{
char uc = char.ToUpper(c);
bool isDigit = ('0' <= uc && uc <= '9');
if (!(isDigit  ('A' <= uc && uc <= 'Z')))
throw new FormatException();
int d = uc  (isDigit ? '0' : ('A'  10));
v = v * 36 + d;
}
return v;
}
(It can be simplified a bit if you can guarantee the strings contain only 09, AZ uppercase.)
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.





Thanks Matt, I put it up too fast.
I corrected it with a version that acts like standard libc conversion routines, and can be used for any base.





I dont know if this will help, but here's a few snippets I made to convert between bases in Javascript
var characters='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
To convert decimal to base 36:
var decimal=21828139225;
var a=decimal,code='';while(a!=0) var code=characters.charAt(a%characters.length)+code,a=Math.floor(a/characters.length);
alert(code);
To convert base 36 to decimal:
var code='A0ZWS0P';
for(var i=decimal=0,len=code.length;i<len;i++) decimal+=parseInt(characters.indexOf(code.charAt(i)))*Math.pow(characters.length,code.lengthi1);
alert(decimal);
A while back, I took this whole base conversion thing way too far, and made the ultimate base conversion tool which can be found at https://www.dropbox.com/s/qmize4qx4hf6lrn/Number%20System%20Conversion%20and%20Encryption.html?dl=0
If you're ever in doubt, you can always resort back to the conversion chart, it never lies!
Happy Coding!





I would simply pad the 3 strings on left with '0's so that all values have same length.
After that, it is a simply string comparison problem.
From other answers, I see that you have 500000 books
I guess you have a database, and that books contain consecutive numbers
 make sure all first ticket number of books have the same length by padding 'o' on left.
 make this field an index
 search the base to find the first book with number <= random
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





Message Automatically Removed





What? Unclear, and probably not related to algorithms.





By magic. If you want more detailed answers, please post more specific questions.





In pseudocode, the general C4.5 algorithm for building decision trees is:
1. Check for base cases
2. For each attribute a
2.1. Find the normalized information gain ratio from splitting on a
3. Let a_best be the attribute with the highest normalized information gain
4. Create a decision node that splits on a_best
5. Recur on the sublists obtained by splitting on a_best, and add those nodes as children of node






Message Automatically Removed





Please read: Howtogetananswertoyourquestion[^]
As I have a feeling you won't actually do it, here's the important part:
Quote: Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Have you heard about Google?
And please stop posting the same question again.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson





Message Automatically Removed






Apparently you can't be bothered to do your own research because I found a java implementation of C4.5 in about 15 seconds. All you have to do is bother to lift a finger to type "C4.5 java" into Google.





Can someone explain this question please
There are 2 types of tiles: Type 1: ** * Type 2: ** (where each star is a square block) Each tile can be rotated or flipped in all ways. There is a box with 2byn dimensions. So, for example, if n=10 then the box dimensions are 2 X 10 as shown below. ****** ****** You have infinite supplies of Type 1 and Type 2 tiles. You have to cover the box with the tiles that you have. You can use any number of type 1 tiles and type 2 tiles. You can choose to use all tiles of same type and none tiles of the other type. But you cannot overlap the tiles. Also, when you cover the box with tiles, none of the tiles should be out of the boundaries of the box, and no part of the box should be empty (no block shud be empty). The tiles should perfectly cover the box with no holes and no protrusions. Your task is to write a program in python that will count the number of different ways (configurations) in which u can cover the box with tiles. 2 cofigurations of covering a box are different if the type or orientation (or both) of any tile of those 2 configurations are different. To clarify things further, there are following configurations of the tiles: 1) ** 2) * * 3) ** * 4) ** * 5) * ** 6) * ** If there are 2 tiles in the configuration that are of same type and placed in same orientation, then if you swap the positions of these 2 tiles, it WILL NOT be counted as a different configuration because all tiles of same type and same orientation are identical. Write a program that will accept an input, n, and produce an output, the total number of different configurations to cover the box of dimensions 2 X n. Example: If n=2, output should be 2. Because 1 configuration could be 2 type1 tiles placed vertically, and another configuration could be 2 type1 tiles placed horizontally. If n=3, output should be 5





That's a task, not a question. And your post is not a question that fits the purpose of this forum. You didn't ask for an explanation of a specific part of this task, so do you want the whole thing explained in even more words than it already consists of?
I suggest you try a bit harder understanding it and, if needed, come back with a more specific question.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson





It would help if you fixed the formatting, but I get the general idea.
Unsurprisingly, it's a tiling problem. There is a rectangle that you have to fill with these shapes, filling it perfectly. Then you have to count in how many distinct ways that can be done, with "distinct" meaning exactly what you'd expect (but they spell it out for good measure).



