A function is a piece of reusable code that will produce consistent output(s) given consistent input(s). Note that consistent doesn't necessarily mean identical; it merely means that the function won't do something unexpected (i.e. randint(1, 4)
will always return a random integer n
such that 1 <= n <= 4
, and never an integer outside of that range, a floating point value, or the lyrics to a song).
Additionally, there must be some consistent method of providing input to the function (like function arguments, putting input on the stack, or saving input in specified registers), a consistent method of retrieving the output (like return values, modified parameters, stack contents, or register contents), and a consistent method of calling the function.
For languages that have support for functions/methods/procedures, the syntax and input, output, and calling conventions should be usedtheir built-in functions are acceptable so long as they meet these requirements. ForAdditionally, for any language (including languages without such constructs (suchsuch as purely imperative languages), if there is a way to write a piece of code that adheres to the above constraints, it is acceptable.
As for writing a submission that uses a function, the result of evaluating the submission code should either result in a named function being defined, or an unnamed function being defined that can be assigned a variable reference, and can subsequently called.
Examples of acceptable submissions (not an exhaustive list):
- Macro functions (C/C++:
#define ISEVEN(X) (X % 2 == 0)
) - Named and unnamed lambda functions (Python:
lambda x: x % 2 == 0
) - Functions with helper functions also defined (Python:
f = lambda x: x == 0; lambda x: f(x % 2)
)