View Single Post
  #14  
Old 12-11-2010, 03:00 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by xAndrewx View Post
I would really recommend a new system, you could do something like

HTML Code:
public function onCheckArray(arr) {
  for (temp.i: getstringkeys("this.")) {
    if ((@ this.(@ temp.i)) == (@ temp.arr)) return true;
    if (temp.arr.size() == this.(@ temp.i).size()) {
      temp.check = 0;
      for (temp.f: temp.arr) {
        if (temp.f in this.(@ temp.i)) temp.check++;
      }
      if (temp.check == temp.arr.size()) return true;
    } 
  }
  return false;
}
That would require relying on a "hack" function retrieving like that could become problematic.

1. Store each recipe id in an array. (this.recipes = {})
2. Store recipe information in it's own variable. (this.recipe.(@id) = {"name", {"ingredient", 1, "other", 1}})
3. Cycle through each recipe and provided ingredients until a match is found.

Rough implementation:

PHP Code:
function getResult(ingredients) {
  
temp.found "";
  for (
temp.recipethis.recipes) {
    
temp.requires getRequirements(temp.recipe);
    for (
temp.0temp.ingredients.size() && ; temp.+= 2) {
      
temp.item ingredients[temp.i];
      
temp.qty ingredients[temp.i+1];
      
// Matching requirements
      
temp.ind temp.requires.index(temp.item);
      if (
temp.item in temp.requires && temp.qty >= temp.requires[temp.ind+1]) {
        
// Matching ingredient
      
}
    }
    if (
temp.found) break;
  }
  return 
temp.found;
}

function 
getResult(recipeid) {
  return 
this.recipe.(@recipeid)[0];
}

funciton getRequirements(recipeid) {
  return 
this.recipe.(@recipeid)[1];

__________________
Quote:
Reply With Quote