2 replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
source | link

Iterate over functions

This is also possible in other languages, but usually longer than the straightforward method. However, Julia's ability to redefine its unary and binary operators make it quite golfy.

For example, to generate the addition, subtraction, multiplication and division table for the natural numbers from 1 to 10, one could use

[x|y for x=1:10,y=1:10,| =(+,-,*,÷)]

which redefines the binary operator | as +, -, * and ÷, then computes x|y for each operation and x and y in the desired ranges.

This works for unary operators as well. For example, to compute complex numbers 1+2i, 3-4i, -5+6i and -7-8i, their negatives, their complex conjugates and their multiplicative inverses, one could use

[~x for~=(+,-,conj,inv),x=(1+2im,3-4im,-5+6im,-7-8im)]

which redefines the unary operator ~ as +, -, conj and inv, then computes ~x for all desired complex numbers.

Examples in actual contests

Iterate over functions

This is also possible in other languages, but usually longer than the straightforward method. However, Julia's ability to redefine its unary and binary operators make it quite golfy.

For example, to generate the addition, subtraction, multiplication and division table for the natural numbers from 1 to 10, one could use

[x|y for x=1:10,y=1:10,| =(+,-,*,÷)]

which redefines the binary operator | as +, -, * and ÷, then computes x|y for each operation and x and y in the desired ranges.

This works for unary operators as well. For example, to compute complex numbers 1+2i, 3-4i, -5+6i and -7-8i, their negatives, their complex conjugates and their multiplicative inverses, one could use

[~x for~=(+,-,conj,inv),x=(1+2im,3-4im,-5+6im,-7-8im)]

which redefines the unary operator ~ as +, -, conj and inv, then computes ~x for all desired complex numbers.

Examples in actual contests

Iterate over functions

This is also possible in other languages, but usually longer than the straightforward method. However, Julia's ability to redefine its unary and binary operators make it quite golfy.

For example, to generate the addition, subtraction, multiplication and division table for the natural numbers from 1 to 10, one could use

[x|y for x=1:10,y=1:10,| =(+,-,*,÷)]

which redefines the binary operator | as +, -, * and ÷, then computes x|y for each operation and x and y in the desired ranges.

This works for unary operators as well. For example, to compute complex numbers 1+2i, 3-4i, -5+6i and -7-8i, their negatives, their complex conjugates and their multiplicative inverses, one could use

[~x for~=(+,-,conj,inv),x=(1+2im,3-4im,-5+6im,-7-8im)]

which redefines the unary operator ~ as +, -, conj and inv, then computes ~x for all desired complex numbers.

Examples in actual contests

1
source | link

Iterate over functions

This is also possible in other languages, but usually longer than the straightforward method. However, Julia's ability to redefine its unary and binary operators make it quite golfy.

For example, to generate the addition, subtraction, multiplication and division table for the natural numbers from 1 to 10, one could use

[x|y for x=1:10,y=1:10,| =(+,-,*,÷)]

which redefines the binary operator | as +, -, * and ÷, then computes x|y for each operation and x and y in the desired ranges.

This works for unary operators as well. For example, to compute complex numbers 1+2i, 3-4i, -5+6i and -7-8i, their negatives, their complex conjugates and their multiplicative inverses, one could use

[~x for~=(+,-,conj,inv),x=(1+2im,3-4im,-5+6im,-7-8im)]

which redefines the unary operator ~ as +, -, conj and inv, then computes ~x for all desired complex numbers.

Examples in actual contests