blob: 289187feed9222445e226de98e6717c0a3a90ca7 (
plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#!/usr/bin/ruby
#
# See https://theweeklychallenge.org/blog/perl-weekly-challenge-004
#
#
# Run as: ruby ch-2.rb < input-file
#
require "optparse"
#
# Parse options
#
params = ARGV . getopts ('f:')
filename = params ["f"]
#
# Find words from the file 'filename' which can be made
# from the letters in 'letters'.
#
def find_words (filename, letters)
letters = letters . downcase . split (//)
File . open (filename) do |f|
f . each_line do |word|
copy = word . downcase
letters . each do |letter|
copy . sub! letter, ""
end
if copy == ""
puts (word)
end
end
end
end
ARGF . each_line do |letters|
find_words filename, letters
end
|