Last active
August 29, 2015 13:57
-
-
Save arsatiki/9720903 to your computer and use it in GitHub Desktop.
Outrun problem in AWK
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
function max(a, b) { | |
return a > b? a: b; | |
} | |
$1 == "#" { | |
print "Seed", $3 | |
next; | |
} | |
{ | |
for (i = NF; i > 0; i--) | |
count[i] = max(count[i], count[i-1]) + $i; | |
} | |
END { | |
for (i in count) | |
result = max(result, count[i]); | |
print result; | |
} |
function m(a,b) {return a>b?a:b}
$1 == "#" {next}
{for(i=NF;i>0;i--) c[i]=m(c[i]+$i,c[i-1]+$i)}
END {for (i in c) r = m(r,c[i]); print r}
137 merkkiä ja bugi korjattu.
function m(a,b){return a>b?a:b}
/#/{next;}
{for(i=NF;i>0;i--)c[i]=$i+m(c[i],c[i-1])}
END {for(i in c)r=m(r,c[i]);print r}
function m(a,b){return a>b?a:b}
/#/{print $3;next}
{for(i=NF;i>0;i--)c[i]=$i+m(c[i],c[i-1])}
END{for(i in c)r=m(r,c[i]);print r}
function m(a,b){return a>b?a:b}/#/{s=$3;next}{for(i=NF;i;i--)c[i]=$i+m(c[i],c[i-1])}END{for(i in c)r=m(r,c[i]);print s,r}
121
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
function m(a,b) {return a>b?a:b}
$1 == "#" {next;}
{for(i=NF;i>0;i--) c[i]=m(c[i]+$i c[i-1]+$i)}
END {for (i in c) r = m(r, c[i]); print r}
140 merkkiä tasan