Created
January 5, 2012 13:02
-
-
Save hadashiA/1565170 to your computer and use it in GitHub Desktop.
原稿用紙枚数換算シンプル
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/env ruby | |
# -*- coding: utf-8 -*- | |
GYO = 20 | |
RETSU = 20 | |
num_letters = num_gyo = num_retsu = 0 | |
open(ARGV.last) do |io| | |
io.each_char do |c| | |
if c.match(/\r?\n/) | |
num_gyo += 1 | |
else | |
num_retsu += 1 | |
num_letters += 1 | |
if num_retsu >= RETSU | |
num_gyo += 1 | |
num_retsu = 0 | |
end | |
end | |
end | |
end | |
div, mod = num_gyo.divmod(GYO) | |
puts <<-RESULT | |
文字数#{num_letters} | |
行数#{num_gyo} | |
枚数#{div}枚と#{mod}行 | |
RESULT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment