I want to make a challenge about genetic algorithm. It is not sandboxed right now. But the task is given a list of neuclide(String with only "ATGC"), the scoring function, and another parameter, you must do a genetic algorithm. (Be note it is the sketch of the sketch) However, the scoring function is inputted as function. How to do that?
There seems to be no existing consensus for this, and very few challenges require functions as input, so you can pretty much decide it for yourself. I would allow the two methods in Peter Taylor's answer, and a third alternative:
- If a language can pass functions as function arguments by some standard mechanism, like first-class functions, function pointers or CJam blocks, then the scoring function can simply be taken as an argument.
- If a language has
evalor equivalent, which interprets and runs a string as code, then a string that defines the scoring function can be taken as input.
- One can also assume that the scoring function has already been defined as
S(or some other name), and can be used in the answer. The definition of
Sis not counted toward the score.
If you want, you can restrict the last alternative to languages that don't support the first two.
If an answer is in a language which allows passing functions (as first class objects, function pointers, etc) then the answer can be given as a function which takes another function as one of its parameters.
If an answer is in a language which has some form of eval then it can be a function or a full program which takes a string and evals it appropriately.
If a language doesn't have any suitable mechanism, tough luck.