Skip to content

Instantly share code, notes, and snippets.

@Plutor
Last active August 29, 2015 14:00
Show Gist options
  • Save Plutor/11060635 to your computer and use it in GitHub Desktop.
Save Plutor/11060635 to your computer and use it in GitHub Desktop.
How far does the normal baseball game get while being perfect
# Run against *.EV? in a file from <http://www.retrosheet.org/game.htm>
BEGIN {
FS=","
}
$1 == "id" {
if (awayisperfect) { print "perfect" }
if (homeisperfect) { print "perfect" }
awayisperfect = 1
homeisperfect = 1
}
$1 == "play" && $7 ~ /^[SDTHWE]/ {
if ($3 == 0 && awayisperfect) {
print $2
awayisperfect = 0
}
if ($3 == 1 && homeisperfect) {
print $2
homeisperfect = 0
}
}
# Pipe to `sort | uniq -c` for useful data. Example output for 2013:
#
# $ awk -f perfectouts.awk *.EV? | sort | uniq -c
# 3396 1
# 994 2
# 302 3
# 123 4
# 34 5
# 7 6
# 4 7
# 2 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment