aboutsummaryrefslogtreecommitdiff
path: root/challenge-207/robert-dicicco/ruby/ch-1.rb
blob: c709241a3cf99abbe01718470ebdfeecb52eb8b8 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env ruby
=begin
--------------------------------------
AUTHOR: Robert DiCicco
DATE  : 2023-03-06
Challenge 207 Keyboard Word ( Ruby )
--------------------------------------
=end

$rows = ["qwertyuiop", "asdfghjkl", "zxcvbnm"]
words = [["Hello Alaska Dad Peace"], ["OMG Bye"]]
$flag = 0

def CheckLetters(w)
    w = w.downcase   # convert to lc
    ln = w.length
    (0..2).each do |str|
        $flag = 0
        (0..ln-1).each do |x|
            unless $rows[str].include? w[x]
                $flag += 1
             end
        end
        if ($flag == 0)
            puts("\t#{w}")
        end
    end
 end

def GetWords(tws)
    tws.each do |tw|
        tw.delete! '[]\"'
        #puts("#{tw}")
        CheckLetters(tw)
    end
    puts(" ")
end

words.each do |wds|
    puts("Input: @words = #{wds}")
    puts("Output: ")
    test_words = wds.to_s.split
    GetWords(test_words)
end
=begin
------------------------------------------
SAMPLE OUTPUT
ruby .\KeyboardWord.rb
Input: @words = ["Hello Alaska Dad Peace"]
Output:
        alaska
        dad

Input: @words = ["OMG Bye"]
Output:
-------------------------------------------
=end