Last active
February 5, 2019 01:22
-
-
Save bloc40/5a48a84b2ef24bef64052cdb86173890 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def word_hash | |
| hash = {} | |
| Hash.new(0) | |
| ('a'..'z').to_a.each_with_index do |e, i| | |
| hash[e] = i + 1 | |
| end | |
| hash | |
| end | |
| def word_points(word) | |
| hash = word_hash | |
| sum = 0 | |
| word.split('').each do |c| | |
| sum += hash[c] | |
| end | |
| sum == 100 | |
| end | |
| describe '#word_points' do | |
| let(:word1) { 'abcd' } | |
| let(:word2) { 'quarter' } | |
| it 'returns false' do | |
| expect(word_points(word1)).to eq false | |
| end | |
| it 'returns true' do | |
| expect(word_points(word2)).to eq true | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def word_hash | |
| hash = {} | |
| ('a'..'z').to_a.each_with_index do |e, i| | |
| hash[e] = i + 1 | |
| end | |
| hash | |
| end | |
| def word_points(word) | |
| hash = word_hash | |
| sum = 0 | |
| word.downcase.split('').each do |c| | |
| sum += hash[c] if ('a'..'z').to_a.include?(c) | |
| end | |
| sum == 100 | |
| end | |
| unix_100_points_words = [] | |
| unix_word_dictionary = File.open('/usr/share/dict/words') | |
| unix_word_dictionary.each do |word| | |
| word = word.gsub(/\n/, '') | |
| unix_100_points_words << word if word_points(word) | |
| end | |
| p unix_100_points_words | |
| describe '#word_points' do | |
| let(:word1) { 'abcd' } | |
| let(:word2) { 'quarter' } | |
| let(:word3) { 'Quarter' } | |
| it 'returns false' do | |
| expect(word_points(word1)).to eq false | |
| end | |
| it 'returns true' do | |
| expect(word_points(word2)).to eq true | |
| end | |
| it 'returns true' do | |
| expect(word_points(word3)).to eq true | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def word_hash | |
| hash = {} | |
| Hash.new(0) | |
| ('a'..'z').to_a.each_with_index do |e, i| | |
| hash[e] = i + 1 | |
| end | |
| hash | |
| end | |
| def word_points(word) | |
| hash = word_hash | |
| sum = 0 | |
| word.split('').each do |c| | |
| sum += hash[c] if ('a'..'z').to_a.include?(c) | |
| end | |
| sum == 100 | |
| end | |
| unix_100_points_words = [] | |
| unix_dict = File.open('/usr/share/dict/words') | |
| unix_dict.each do |word| | |
| unix_100_points_words << word if word_points(word.downcase.gsub(/\n/, '')) | |
| end | |
| p unix_100_points_words | |
| describe '#word_points' do | |
| let(:word1) { 'abcd' } | |
| let(:word2) { 'quarter' } | |
| it 'returns false' do | |
| expect(word_points(word1)).to eq false | |
| end | |
| it 'returns true' do | |
| expect(word_points(word2)).to eq true | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment