aboutsummaryrefslogtreecommitdiff
path: root/challenge-221/robert-dicicco/ruby/ch-1.rb
blob: 2bb6caae75a10364e84b10e789bcfc751d66f637 (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
60
61
62
#!/usr/bin/env ruby
=begin
-------------------------------------
AUTHOR: Robert DiCicco
DATE  : 2023-06-12
Challenge 221 Task 1 Good Strings ( Ruby )
-------------------------------------
=end

total_score = 0

words = [["cat", "bt", "hat", "tree"], ["hello", "world", "challenge"]]
chlist = ["atach","welldonehopper"]
cnt = 0
listcnt = 0

words.each do |wds|
    puts("Input: @words = #{wds}")
    chars = chlist[cnt]
    total_score = 0
    wds.each do |w|
        ln = w.length
        score = 0
        for cnt in 0..ln-1 do
            tst = w[cnt,1]
            if chlist[listcnt].include? tst
                 score += 1
            else
                break
            end
        end
        if score == ln
            puts("#{w}")
            total_score += score
            score = 0
         end
    end
    puts("\tTotal: #{total_score}\n\n")
    cnt += 1
    listcnt += 1
end

=begin
-------------------------------------
SAMPLE OUTPUT
ruby .\GoodStrings.rb
Input: @words = ["cat", "bt", "hat", "tree"]
cat
hat
        Total: 6

Input: @words = ["hello", "world", "challenge"]
hello
world
        Total: 10
-------------------------------------
=end