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.
publicint FindMaxM(double minx, double maxx, double delta)
while (minx + m * delta < maxx)
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?
publicint FindMaxM(double minx, double maxx, double delta)
int m = (int) (((maxx - minx)/delta));
//if the division is resulting in an actual integer reduce the gridsizeif (minx + m * delta >= maxx)
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.
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.
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
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.
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!
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.
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?