Created
June 22, 2012 21:04
-
-
Save mshock/2975204 to your computer and use it in GitHub Desktop.
golf - greatest row || column sum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# current solution using map and autosplit - 80 | |
#!perl -pa | |
map{$c[$i++]+=$_;$r[$j]+=$_}@F;$i=0;$j++}{$_=(sort{$a<=>$b}@r,@c)[-1] | |
######################################### | |
=pod | |
old solutions and scratch | |
# run switch solution - 102 | |
#!perl -an | |
($r,$i)=0;for(@F){$c[$i++]+=$_;$r+=$_};$t=(sort{$a<=>$b}@c,$r)[10];$p=$t>$p?$t:$p}{print$p | |
# long for loop solution - 113 | |
for(map{split}<>){$c[$i++]+=$_;$r+=$_;if(!($i%10)){$t=(sort{$a<=>$b}@c,$r)[10];$p=$t>$p?$t:$p;($r,$i)=0}}print$p | |
# just for columns! missed that row part =) | |
#!perl -an | |
$a=(sort map{$a[$_]+=$F[$_];$b+=$F[$_]}0..9,$b)[9]}{print$a | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm sure that I can shave some characters off of my current solution but I'm planning on trying a regex-based approach next.