Default Rules: Code Golf I/O
What input/output methods do you think should be allowed/disallowed while code golfing on this site? What guidelines for input/output methods do you think should be in place?
One method per answer, please. Vote up/down according to if you believe the given method should be allowed.
Functions may take input via a …
3y ago
Functions may use arguments or …
3y ago
You may output delimiter-separ …
3y ago
Functions may take multiple ar …
3y ago
Programs may take input from p …
3y ago
Regexes may output via the lis …
3y ago
In languages without STDIN (eg …
3y ago
You may modify the input in-pl …
3y ago
Turing machines supporting mul …
3y ago
Command-line arguments may be …
3y ago
Unless explicitly asking for e …
3y ago
Numerical I/O may be given as …
3y ago
Programs may output via exit c …
3y ago
Turing machines may use the co …
3y ago
Image output may be a pixel sh …
3y ago
Programs/functions may use the …
3y ago
Functions may return bools via …
3y ago
A program may use IOs for inpu …
1y ago
A program may output a boolean …
1y ago
19 answers
A program may use IOs for input and output.
A input can be read via IO, which can be a port with (multiple) IOs each IO reads a symbol (a bit or more when you have a ADC). Or it can come from frames, such as UART frames, I2C, SPI, Ethernet, .... (any bus you like).
And Output can be done the same but reversed.
0 comment threads
Functions may take input via arguments and output via return value
Functions may also use STDIN/STDOUT as they wish.
Functions may use arguments or lists of arguments interchangeably
For example, if a challenge requires defining f(x, y, z)
, f(a)
is also acceptable where a[0] = x, a[1] = y, a[2] = z
.
0 comment threads
You may output delimiter-separated values instead of a list
For example, the output [1,2,3]
could be represented as 1 2 3
or 1|2|3
.
Functions may take multiple arguments with currying
For some languages like Haskell this is almost a necessity, as only one-argument functions exist and multi-argument functions are implemented with currying. (You might take a list or tuple of the values but this isn't the natural way to do multi-arg functions in Haskell.)
The same thing should be allowed for languages which do have proper multi-argument functions. In JavaScript, one might want to use f=a=>b=>...
and call f(a)(b) instead of using f=(a,b)=>...
and calling f(a, b).
1 comment thread
Programs may take input from prompts from the GUI
For Mathematica, JS, Matlab, et. al. this is the closest thing they have to STDIN.
0 comment threads
In languages without STDIN (eg ///) programs may input through insertion into the source code
Also applies to cellular automata, in which the most natural way of taking input is specifying some space for a user-created structure.
0 comment threads
Turing machines supporting multiple halt states may output with the state they halt on
Similar to the exit code submission.
You may modify the input in-place
If a function takes an input a
, it is acceptable that a
contains the intended output after executing instead of other forms of output. Note that this means a
must be mutable to begin with and the function must actually mutate a
.
Numerical I/O may be given as a character code
Input 64 may be given as @
instead. This mostly exists for languages like Brainfuck that only take input through character codes.
0 comment threads
Command-line arguments may be used as input instead of stdin
Languages/systems that support reading input from command-line arguments may use those as input instead of reading from stdin.
1 comment thread
Unless explicitly asking for exactly two values, you may use any truthy/falsey values in decision problems
For instance, considering the hypothetical challenge "Determine if a number is non-divisible by 3", n=>n%3
would be a valid solution, as it outputs a truthy (non-zero) value when it is non-divisible and a falsey (zero) value when it is.
0 comment threads
Image output may be a pixel shader
A pixel shader inputs x,y
coordinates of a pixel and prints the color of a pixel (scalar for grayscale, tuple for full color, bool for binary...). Relevant for Shadertoy/GLSL answers and graphical output challenges.
0 comment threads
Functions may return bools via the presence/absence of an error
Crashing to mean false
and not crashing to return true
. Another branch of the exit code answer.
0 comment threads
A program may output a boolean value by using different amount of time or instructions till it returns.
If a program needs to determine a boolean value, it may return in less than N second (or instructions) when the value is false
but take longer than N + ϵ second (or instructions) when the value is true
or vice versa.
The difference (ϵ) has to be large enough to be detectable without much effort. I would suggest there is a factor of at least 16 between true
and false
(i.e. $ϵ > 15 \cdot N$) . A infinite ϵ should be allowed (if it doesn't return after N second, kill it and consider the result as true
). The poster has to give an estimate of N.
0 comment threads