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?


2 Answers 2


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 eval or 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 S is not counted toward the score.

If you want, you can restrict the last alternative to languages that don't support the first two.

  • 1
    \$\begingroup\$ Good point. I didn't think of your third option, but I agree with it. \$\endgroup\$ Commented Feb 5, 2016 at 16:39

However works.

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.

  • \$\begingroup\$ Or Java 8's "functional interfaces" can also be used \$\endgroup\$ Commented Feb 5, 2016 at 14:12
  • 2
    \$\begingroup\$ If you really want to be inclusive you could allow people to designate a position in the source code where the "function" can be dumped into (as a plain code snippet). That's probably unnecessary though. \$\endgroup\$ Commented Feb 5, 2016 at 17:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .