Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Need Help To Convert Code To Delphi
kvarnerexpress
post Jan 29 2006, 03:42 PM
Post #1


Super Member
*********

Group: Members
Posts: 407
Joined: 13-December 04
Member No.: 2,696



. any help is appreciated.

the code is supposed to give the index of elements in an array with a maxSum for any combination of elements in the array while the maxsum is still less than an allowedMax. See the example at the end of code.


CODE

function maximum_subset_sum ($max, $candidate_array) {
$working_array = array();
while ($next = each($candidate_array)) {
$candidate = $next['value'];
$sums_to_date = array_keys($working_array);
while ($marked_sum = each($sums_to_date)) {
$known_sum = $marked_sum['value'];
$possibly_new = $known_sum + $candidate;
if(($possibly_new <= $max) &&
!IsSet($working_array[$possibly_new])){
$working_array[$possibly_new] = $candidate;
}
}
if(($candidate <= $max) &&
!IsSet($working_array[$candidate])){
$working_array[$candidate] = $candidate;
}
}
$max_sum = max(array_keys($working_array));
$return_array = array($working_array[$max_sum]);
while ($max_sum != $working_array[$max_sum]) {
$max_sum = $max_sum - $working_array[$max_sum];
array_push($return_array, $working_array[$max_sum]);
}
return($return_array);
}

// example use
$best_sum = maximum_subset_sum(40, array(39,23,19,14,9,5,3,2,1));
print("Largest sum is " . array_pop($best_sum));
while ($value = array_pop($best_sum)) {
print(" + $value");
} // will print "Best sum is 23 + 14 + 3"
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Where can i get a delphi compiler?(4)
  2. Ac C E L E R At E Your Develo P M E N T(0)
  3. Interview De Olivier Dahan Sur Delphi 2005(0)
  4. Borland Dévoile Delphi 2005(0)
  5. Premier Contact Avec Le Futur De Delphi(0)
  6. Sémaphores Et Mutex En Delphi Et Java(0)
  7. Delphi 2005 Gratuit Pour Une Utilisation Personnel(0)
  8. Gestion Des Exceptions Sous Delphi(0)
  9. Raccourcis Delphi(0)
  10. Delphi(6)
  11. Delphi Question(9)
  12. Crack The Binary Code...(4)
  13. Delphi Upgrade!(2)
  14. Make Anty-spyware Program In Delphi 7 ?(6)
  15. My First Contribution(0)
  1. Delphi Is Easy And Most Oop-d Language.(6)
  2. Delphi Panels Help(0)
  3. Delphi Password Loading To Text Box(1)
  4. Delphi Questions...(1)
  5. How Do I Convert Hexadecimal To Decimal?(2)
  6. Source Code Troubles {delphi}(2)


 



- Lo-Fi Version Time is now: 26th July 2008 - 03:47 PM