-
Notifications
You must be signed in to change notification settings - Fork 0
/
2019-jumble.rb
28 lines (25 loc) · 1.14 KB
/
2019-jumble.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Jumble
#
# from: https://programmingpraxis.com/2019/03/01/jumble
#
# Last week I gave a rather silly solution to the Scrabble problem. Today’s
# exercise is my penance for that silliness.
#
# As I’ve mentioned previously, my day job is on a team of programmers that
# supports our enterprise-wide computer system. I sit in a cube farm, where
# there is neither audible nor visual privacy. We recently hired a new
# programmer to replace a retiring team member, and he has a daily calendar on
# his desk that provides a jumbled series of letters that you have to rearrange
# to form a word. Yesterday’s puzzle was L T E A D E; most of the puzzles I
# solve in a few seconds, but that one took several minutes. The calendar
# appears to have a flaw: the solutions, one day after the next, are in
# alphabetical order, so I know before I start that the first letter will be E.
# Your task is to write a program that solves jumbles.
def jumble(word, dict)
chars = word.downcase.chars.sort
dict.select do |w|
w.chomp!
chars.size == w.size && chars == w.downcase.chars.sort
end
end
puts jumble(ARGV.first, File.readlines("/usr/share/dict/words"))