Thursday, November 10, 2011

Euler Problem 17

My try to solve Project Euler problem no. 17

require 'rubygems'
require 'linguistics'    # yeah, I use linguistics gem. Easier rather than doing the function by myself :P

Linguistics::use( :en )

totallength = 0

1001.times do |x|
  if x > 0
    #puts x.en.numwords.delete(" -").length
    totallength += x.en.numwords.delete(" -").length
  end
end

puts totallength

No comments:

Post a Comment