A small repo for code diversions and doing weird stuff with C. Try to write C programs using as few bytes as possible in the source code by using a lot of dumb tricks for fun. If you think you can make any of these smaller, let me know please! Code is written to be small in source, not performant.
Makefile at top level to come. Code in all directories should compile with gcc -o name source.c
.
- implicit
int
: simply enumerating variables on a line, for example likex,y,z;
will save three bytes by implyingint
- global implicit initialization : declaring
int
variables like above in global scope will set them to0
main
'sargc
to initialize : declaring anint
inmain
's argument will default it as one if the binary is invoked as./a.out
- implicit library includes : many libraries like
stdio
will be inluded by the compiler if functions likeprintf
are used for(;COND;)
looping :for
andwhile
loops take up the same amount of bytes, butfor
is generally preferable since the semi-colons in it can eat others in regular code- serial assignment : variables set to the same value can save a little space via
x=y=z=0;
vsx=0;y=0;z=0;
- assign to input param : when subfunctions that return a value are needed,
f(a){return 2<<a&3;}
can be converted intof(a){a=2<<a&3;}
since the compiler will generally have the return value stored at the input - ternary operator : often is a tighter stand in for
if..else
- ternary condition as result : for some compilers (gcc)
a?:c
gives the same result asa?a:c
. This sits on the fact that only one of the results will be evaluated
TBD
Each problem will have an ungolfed, hopefully readable, source. The golfed sources will be suffixed with a _terse
in the filename.