123456789101112131415161718192021 |
- #!/usr/bin/ruby
- # Author: Daniel "Trizen" Șuteu
- # License: GPLv3
- # Website: https://github.com/trizen
- # 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.
- # If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
- # https://projecteuler.net/problem=17
- # Runtime: 0.357s
- var lingua_num = frequire('Lingua::EN::Numbers');
- var sum = 0;
- range(1, 1000).each { |i|
- sum += lingua_num.num2en(i).count(/[a-z]/);
- }
- say sum;
|