|
Given three doubles minx, maxx and delta I want to work out how many times delta fits in the interval between minx and maxx without touching the maxx.
I've found this solution to the problem in some inherited code. This is fine when m is small, but as m grows it obviously takes longer and longer. I guess it was easy to code, but not particularly efficient.
public int FindMaxM(double minx, double maxx, double delta)
{
int m;
while (minx + m * delta < maxx)
{
m++;
}
return m;
}
My own implementation looks like this, but I wondered in an academic way if there was an even better way to do it. How would you implement it?
public int FindMaxM(double minx, double maxx, double delta)
{
int m = (int) (((maxx - minx)/delta));
if (minx + m * delta >= maxx)
{
m--;
}
return m;
}
|
|
|
|
|
Just off the cuff I would say:
m = (int)((maxx-minx) / delta);
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I am not paid by lines, so I might do something like this.
return --((int)Math.Ceiling((maxx - minx) / delta));
|
|
|
|
|
The answers so far probably don't satisfy the "without touching the maxx" requirement; it may depend on your definition of "touching". You might get away with it by subtracting a tiny fraction of delta from maxx before using the division approach...
|
|
|
|
|
|
Plenty of novices ask pretty much the same question when start to work with brokers who help them to earn money by means of the Forex trading. This question concerns the compensation that brokers take in order to get profits from collaboration with traders. Brokers are often to forget this when it comes to actual trading process and that is why the compensation in the most cases is not limited by spread rates the brokers set in every particular case. Due to the fact this scheme is bit complicated and important because every trader should know the rules the other participants of the Forex trading follow we have decided to enlighten it below.
In a case you want to disclose all forex trading software secrets and rules you need to know what the participants of this market come back in the trading day by day and what benefits they expect to get because you may like in idea of changing your profession of a trader into a broker’s occupation within the Forex market. Well, we hope you figure out by now that knowing what fee your broker gets from working with you can be very handy and interesting info to know so let’s try to figure out by item what benefits and compensations a broker may get in the Forex market.
Unlikely other assets’ brokers FX brokers never charge commissions on the traders with who they work. They use other ways of the money source which appear during the actual Forex trading process:
1) By Currency Buying/Selling
The lion’s share of profits a broker gets from forex trading comes from actual buying and selling of currencies. Money comes from getting spreads which stands for the differences between the bid and the ask prices. The ask price is that price at which the FX market sells a trader the currency and the bid price in its turn the price at which this currency can be bought from you while you are conducting your trading positions.
2) By Charging Leveraged Spreads
When a broker offers high leverage to traders he or she makes it not profitable to earn money on spreads because they are getting to be too small. By means of the high leverage brokers can multiply the potential profits however with high risks as well. Proposing the leverage 1:100 a Forex broker can make 100 times more profits than without leverage.
3) By Getting Overnight Swap Spreads
In a case the when the difference between the set interest rates is positive in the particular position of the trader the broker can pay the so called overnight swap to the trader he or she works with. In a case when the difference between the interest rates is negative the Forex trading broker get money from the account of the trader.
4) Asking for a Commission on Payment Processing
Commissions are not taken abut sometimes they are masked as payments for certain service online Forex brokers provide. You as a trader can be asked to pay for making a withdrawal or deposit. For sure, such fees are ridiculously small and measured not I pips but in the currency units but still in such way you can reduce the expenses a broker has to make while providing you the numerous online services for proper and better Forex trading.
NB: Make sure that your broker doesn’t belong to those ones who earn money on their clients’ losses. Beware of brokers offering too small spreads from working with you, proposing the irrelevant leverage conditions, too good to be true overnight swaps and free payment processing service.
Latest blogpost:Tips for Seekers of Free Forex Buy and Sell Indicator Offers.
We're online: forex market.
modified 1-Dec-11 3:17am.
|
|
|
|
|
Is there available a good introductory tutorial with code for that problem?
Чесноков
|
|
|
|
|
If you can handle FORTRAN, one source is here[^]. Translation to a modern language shouldn't be hard, as FORTRAN is a very basic language, and all of its constructs have modern equivalents.
If you're interested in such things, this guy has hundreds of different theoretical physics solutions posted on his site. What a gem! I'm bookmarking it for future use. Thanks for leading me to search for it for you.
Will Rogers never met me.
|
|
|
|
|
When we need to store passwords for user authentication, the password gets "encrypted" somehow. Typically, a block of random bytes - the "Salt" - is added to the clear text password, next comes a hash algorithm, and finally a textual representation of the bytes received from the hash function is stored.
I've seen different ways of such handling: e.g. not using a Salt at all, a string concatenation of password and a textual representation of the Salt, a binary XOR. Not using a Salt at all is considered unsafe. How would you "salt" the password, and why do you prefer your method?
How do you store the result in your database - as binary data, converted to hexadecimal, ...?
MD5 is said to have some flaws. Do you still use it?
Thanks a lot for sharing your experience.
|
|
|
|
|
IMHO multiple layers of encryption give much better protection than betting everything on a single layer. In addition to character substitution, other techniques such as transposing characters' positions make the decrypter's job exponentially harder.
Any salt characters improve security, as long as you can unambiguously identify the salt characters to remove them for decryption.
|
|
|
|
|
MD5 is not used anymore, not a strong type of hash algorithm. You should use SHA-256 instead.
Overall algorithm would depend on your application, for example if you use a captcha I would recommend only using a hash algorithm to store the passwords. But if you don't you could use salt, it is the ultimate answer to brute force attack.
|
|
|
|
|
You have probably solved this by now, but since you got a recent response, I thought I woudl add my two pence worth.
I tend to use the UserID as the salt - not the username, but the unique value I assign in the database table (personally, I tend to use GUIDs for these) and take an SHA hash of the combined id and password. I then store the hash as a comparison value in the DB.
If you don't use some salt, then it is relatively easy to spot common passwords (they would all have the same value as a hash) and if you crack one of them (by looking at the hash for common passwords) you have access to all those accounts. For example, if 50% of your accounts have the same hash, change your password to "password" and see what hash your account has. If it matches, then you know the password for 50% of the accounts.
MD5 does indeed have some problems - it is officially classed as "broken" and should not be used for new designs. What that means is that there is a way to get a valid input (not necessarily the original input, but valid) from the MD5 hash value. It isn't a real problem, but with security it is a good idea to avoid it as a result. SHA is currently unbroken, and you should use that - the .NET cryptography namespace includes SHA in several sizes.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Hi all,
I'm studying software design patterns. Right now I'm going through the various patterns presented on the Wikipedia article at http://en.wikipedia.org/wiki/Software_design_pattern[^] (yeah, I know.. it's wikipedia... but it's free). I feel like I'm understanding the material, but I also feel that some real-world examples would be helpful. Anyone know of a good site to find real-world examples of design patterns? Doesn't even have to contain code... can dig into code when I'm actually ready to implement these. I just want to make sure I understand the concept behind each pattern.
Thanks!
PS -- not sure if this is the right forum to put this in but it seemed the closest match of the available selections. Thanks again!
Hypermommy
|
|
|
|
|
|
Doh! Didn't see it. Any way for a user like me to move a message or shall I just wait for an admin to do it (and probably rightfully chastise me in the process. ).
I'll definitely check out the article and thanks!
Hypermommy
|
|
|
|
|
I have a formula y=x*(x-1) , given y , how do you find x ? (x is never less than 2.)
It occured to me that x*(x-1) is very close to x^2 especially as x increases, so I'm taking the square root and using CEILING (at least in SQL).
Something about this doesn't seem kosher, how would y'all do this?
|
|
|
|
|
if those variables are integers, then for x>1 you know (expand the multiplications to verify):
(x-1)^2 < x*(x-1) < x^2
which means (still assuming x>1):
x-1 < SQRT(y) < x
or
SQRT(y) < x < 1+SQRT(y)
so yes the ceiling should do it, as would the floor of SQRT(y)+1
if those variables are reals, then you either write the formula for a quadratic equation, or you use an iterative process, such as Newton-Raphson's.
|
|
|
|
|
Oh, yes, of course integers, the only real numbers. 
|
|
|
|
|
OK.
Now could you please go here[^] and offer your usual wisdom. Thanks.
|
|
|
|
|
Oh, right I saw that earlier, not sure what to say.
|
|
|
|
|
Well, this is a quadratic equation, with roots at 0 and 1 and therefore a midpoint at ½.
y = (x - ½)² - ¼ (expand and compare with the initial constant which was 0)
(x - ½)² = y + ¼
x - ½ = sqrt(y + ¼)
x = sqrt(y + ¼) + ½
Since you're already using a square root this won't be much more expensive than what you're doing now (maybe less, not sure of the cost of ceil) and it's accurate.
x(x - 1) isn't that close to x², it differs by x and therefore the relative error only goes down as 1/x. That's a very poor approximation and I don't see why you'd use it if it's also an expensive one with a sqrt in it.
|
|
|
|
|
|
Hello
I'm searching for some algorithm that could compare two files by content and return the list of differences. I have successfully implemented the LCS - Longest Common Subsequence algorithm and got it up and running with backtracking, but this algorithm is only usable for short strings. Event with some optimizations (trimming) this algorithm blows up the memory with long string (marix size is quadratic to the length processed string)
Can you please help me out on what my options are?
Thanks you very much and have a wonderful day!
Tomas
|
|
|
|
|
|
Luc's may have won, but I like mine PIEBALDdiff[^].
It doesn't bother with LCS or Levenshtein (yet) and still gets good results with (probably) less memory and more flexibility. 
|
|
|
|