Skip to content

Instantly share code, notes, and snippets.

@hadashiA
Created January 5, 2012 13:02
Show Gist options
  • Save hadashiA/1565170 to your computer and use it in GitHub Desktop.
Save hadashiA/1565170 to your computer and use it in GitHub Desktop.
原稿用紙枚数換算シンプル
#!/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