|
For example,
1,3,6,8,11,45,99
The interval between numbers is:
2,3,2,3,34,54
So the greatest difference is 54.
How to implement this function?
function get_greatest_diff($arr_of_numbers) {}
Started by another on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
MaxDiff = $diff; } }
You should do something like this :
$greatest_diff = 0; for($i = 0; $i <[$i]; if($current_diff > $greatest_diff){ $greatest_diff = $current_diff; } } echo $greatest_diff;.
|
|
Title says it all! is there a very simple algorithm to figure out which of 4 numbers is the greatest?
Started by every_answer_gets_a_point on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
Nate's answer is more efficient as it uses.
; } }
The greatest value will be max and it's index in largest .
|
|
Not sure if anyone has done this before, didn't see it in the posts. But and apologies to any French out there, but if you google 'French Military Victories' and press the 'I'm feeling lucky' button, then follow the highlighted link, you should enjoy ...
Started by Boneman on
, 15 posts
by 9 people.
Answer Snippets (Read the full thread at sffchronicles):
The greatest warrior in anchient history i would say would actually campaign is one of the ....
Flavius Belisarius (505? - 565) was one of the greatest generals of the Byzantine on - triumph, disgrace and recall....
Is a worthy candidate.
|
Ask your Facebook Friends
|
Can someone give an example for finding greatest common divisor algorithm for more then two numbers?
I believe programming language doesn't matter.
Started by Bogdan Gusiev on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
:)
Oh, and....
I'm watching this one to see if there are any other optimizations .
The obvious optimization is you can stop if the running GCD ever reaches 1 .
Start with the first pair and get their GCD, then take the GCD of that result and the next number .
|
|
Quote: : I haven't read all this thread, but my vote would go to Belisarius. Almost all his victories were against odds, often with pathetic forces, jealous and disobedient subordinates and a distrustful emperor who starved him of the resources to accomplish...
Started by svalbard on
, 11 posts
by 5 people.
Answer Snippets (Read the full thread at sffchronicles):
|
|
With three numbers, $x , $y , and $z , I use the following code to find the greatest and place it in $c . Is there a more efficient way to do this?
$a = $x; $b = $y; $c = $z; if ($x > $z && $y <= $x) { $c = $x; $a = $z; } elseif ($y > $z) { $...
Started by Gordon on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Max(array($a, $b, $c));
if you need to.
You can also use an array with max.
See the documentation on max for more information.
Probably the easiest way is max($x, $y, $z).
|
|
Hi,
I would like to know if there's an efficient algorithm to find the greatest m elements in an N x N matrix, with a method header like this:
double[] greatestValues(double[][] matrix, int numberOfElements);
Any ideas?
Started by David Hodgson on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
If you treat the N x N matrix as an array of N x N items you can apply one of the following... .
It might actually be more efficient to take the values of the matrix, insert them into a tree and go from there, instead of only trying to work with the matrix .
|
|
Given an ordered set of 2D pixel locations (adjacent or adjacent-diagonal) that form a complete path with no repeats, how do I determine the Greatest Linear Dimension of the polygon whose perimeter is that set of pixels? (where the GLD is the greatest...
Started by Jared Updike on
, 6 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
I just need to turn my point set into a convex polygon first (probably... .
On this page:
http://en.wikipedia.org/wiki/Rotating_calipers http://cgm.cs.mcgill.ca/~orm/diam.html it shows that you can determine the maximum diameter of a convex polygon in O(n) .
|
|
I found in MYSQL and apparently other database engines that there is a "greatest" function that can be used like: greatest(1, 2, 3, 4), and it would return 4. I need this, but I am using IBM's DB2. Does anybody know of such an equivalent function, even...
Started by Mike Stone on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
UPDATE: Apparently #1 won't work.
To my "SQL Pocket Guide", MAX(x) returns the greatest value in a set.
|
|
If I have a list in Python like
[1, 2, 2, 2, 2, 1, 1, 1, 2, 2, 1, 1]
how do I calculate the greatest number of repeats for any element? In this case 2 is repeated a maximum of 4 times and 1 is repeated a maximum of 3 times.
Is there a way to do this but...
Started by hekevintran on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Repetition pair greatest = (-1, -1) reps = 1 for e in l: if e == previous: reps += 1 else: if reps > greatest[1]: greatest = (previous, reps) previous = e reps = 1 if reps > greatest[1]: greatest = (previous, ....
|