Code Golf: All +-*/ Combinations for 3 integers

Perl 130 chars So long as external libraries are permitted: use Algorithm::Permute”permute”; permute{for$x(@a=qw(+ – / *)){for$y(@a){$_=”@ARGV”;s/ /$x/;s/ /$y/;printf” $_ = %.0f”,eval}}}@ARGV 2nd newline is significant. Without a module, and assuming that all three inputs are distinct, here’s another solution: @n=& ARGV; @o=( q[+], “-“, q{/}, ‘*’ );; for$ {a}(@ n){ for $b(@n){for$c(@ {n}){ for $x( … Read more

Generating unique, ordered Pythagorean triplets

Pythagorean Triples make a good example for claiming “for loops considered harmful“, because for loops seduce us into thinking about counting, often the most irrelevant part of a task. (I’m going to stick with pseudo-code to avoid language biases, and to keep the pseudo-code streamlined, I’ll not optimize away multiple calculations of e.g. x * … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)