Well, I tried my best for another challenge from codegolf.com.
I can’t imagine how these guys can solve this in less than 50 characters. I managed to solve it in 132 characters in Perl. Maybe I could try to solve it in Ruby too … later
Here is my approach:
@{$$a[$_]}=split/ /,<>;for 0..9;for(0..9){$A=$B=0;for$y(0..9){$A+=$$a[$_][$y]; $B+=$$a[$y][$_];}$Z=$A if$A>$Z;$Z=$B if$B>$Z;}print$Z;
Maybe someone else wants to give it a try. The task is to calculate the highest sum from a given 10 x 10 grid. Have fun!










3 Comments
Habs auch mal probiert… bin auf 170 Zeichen gekommen:
$x=$y=0;$s=explode(”\n”,$s);foreach($s as $l){$l=explode(” “, $l);$x=array_sum($l)>$x?array_sum($l):$x;$r=0;for($i=0;$i$y?$r:$y;}echo$x>$y?$x:$y
unglaublich wie das Leute mit 67 schaffen (bei PHP) o_O
Ich weiß zwar nicht ob Perl den Trinitäts Operator kennt, aber wenn dem so ist, dann ginge deines noch ein wenig kürzer:
@{$$a[$_]}=split/ /,;for 0..9;for(0..9){$A=$B=0;for$y(0..9){$A+=$$a[$_][$y];
$B+=$$a[$y][$_];}$Z=$A>$B?$A:$B;}print$Z;
jetzt wo dus sagst … ich glaube ich habe es damals zwar in erwägung gezogen, aber dann doch nicht gemacht. ich versuchs mal
danke für den tipp!