Created
July 4, 2012 01:28
-
-
Save usaturn/3044604 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/gawk -f | |
# usage: | |
# gawk -f poker.awk card.txt | |
# | |
# 1. ファイルから行単位で数字を読み出す | |
# 2. 数字を添え字にして連想配列にする | |
# 3. Value値に、同じ添え字(数字)があったら+1する | |
# 4. END句で、連想配列を全て読み出し、Value値が2の物があった場合に、one pairと表示する | |
# ※ 基本動作のみ | |
{ | |
card[$1]++ | |
} | |
END{ | |
for(i in card) if (card[i]==2) print "cards is one pair" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment