Last active
August 29, 2015 14:00
-
-
Save Plutor/11060635 to your computer and use it in GitHub Desktop.
How far does the normal baseball game get while being perfect
This file contains hidden or 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
# 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