Skip to content

Instantly share code, notes, and snippets.

@Adamantish
Last active March 14, 2019 11:51
Show Gist options
  • Save Adamantish/10c00f5beffc7de16f9b6b11528637ce to your computer and use it in GitHub Desktop.
Save Adamantish/10c00f5beffc7de16f9b6b11528637ce to your computer and use it in GitHub Desktop.
This sounded like a cute, simple task. https://www.youtube.com/watch?v=zp4BMR88260 . Avoiding regex to showoff ruby expressivity
# frozen_string_literal: true
require 'set'
BAD_LETTERS = 'gkmqvwxz'
WORD_LIST_PATH = '/my_path/words_alpha.txt' # Found at https://github.com/dwyl/english-words/blob/master/words_alpha.txt
BAD_LETTERS_SET = BAD_LETTERS.split.to_set
WORD_LIST = File.new(WORD_LIST_PATH)
def word_check(word)
word.each_char.none? { |char| BAD_LETTERS.include?(char) }
end
longest_word = ''
WORD_LIST.each_line do |word|
next if longest_word.size >= word.size
longest_word = word if word_check(word)
end
p "There is no word longer than '#{longest_word.chomp}' displayable on a 7 segment display"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment