Skip to content

Instantly share code, notes, and snippets.

@mshock
Created June 22, 2012 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mshock/2975204 to your computer and use it in GitHub Desktop.
Save mshock/2975204 to your computer and use it in GitHub Desktop.
golf - greatest row || column sum
# 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
@mshock
Copy link
Author

mshock commented Jun 22, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment