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( 
 @o){for$y(@o){   ($a-$  b)*($a-$c)*  ($b-$
 c)||next;$_=$a  .$x.$   b."$y$c";$%   =42
      /84+      eval;    print"",$_,  "$S="
      ,$S,     $%,$/                 }}} }};
      ;sub    ARGV{                 $S=   $".
      "";@   ARGV}                 ;1+     2+3

Leave a Comment

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