Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   evalArray() (https://forums.graalonline.com/forums/showthread.php?t=134263375)

Crow 05-28-2011 03:19 PM

evalArray()
 
I've written a small function that basically applies a calculation to all elements of an array using Zero's eval function.

Here it is:
PHP Code:

function evalArray(arrev) {
  if (
arr[0].size() == 0)
    
arr = { arr };
  
  
// evaluate all array elements
  
temp.nArr = new[arr[0].size()];
  for (
temp.0arr[0].size(); i++) {
    
temp.eva ev;
    for (
temp.0eva.size(); k++)
      for (
temp.0arr.size(); l++)
        if (
eva[k] == "E" l)
          
eva[k] = arr[l][i];
    
    
nArr[i] = evalPost(eva);
  }
  
  return 
nArr;


The first argument is either a single array of values to use in the calculations or an array of multiple arrays holding values (if you want to use more than one). The function will return an array the size of the (first) value array, holding all the solutions.

The second argument is your formula in post-fix notation (more on that in Zero's thread). In this array you can use E0, E1, E2 and so on to refer to the current array element of the specific array (starting at 0, obviously) depending on how many arrays you've given to the function.


Example:
PHP Code:

temp.a1 = { 12};
temp.a2 = { 45};
echo(
evalArray({ a1a2 }, { "E0""E1""+"2"*" })); // returns { 10, 14, 18 } 


Maybe this is useful for some of you guys. I've written it for a project of mine.


All times are GMT +2. The time now is 11:31 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.