017 Number letter counts.sf 573 B

123456789101112131415161718192021
  1. #!/usr/bin/ruby
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Website: https://github.com/trizen
  5. # If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
  6. # If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
  7. # https://projecteuler.net/problem=17
  8. # Runtime: 0.357s
  9. var lingua_num = frequire('Lingua::EN::Numbers');
  10. var sum = 0;
  11. range(1, 1000).each { |i|
  12. sum += lingua_num.num2en(i).count(/[a-z]/);
  13. }
  14. say sum;