042 Coded triangle numbers.sf 333 B

12345678910111213141516171819
  1. #!/usr/bin/ruby
  2. # Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # https://github.com/trizen
  5. # https://projecteuler.net/problem=42
  6. # Runtime: 0.653s
  7. var words = eval('[' + %f'p042_words.txt'.read + ']')
  8. var dict = Hash()
  9. dict{('A'..'Z')...} = (1..26)...
  10. say words.count { |word|
  11. 8*word.chars.map{ dict{_} }.sum + 1 -> is_square
  12. }