aboutsummaryrefslogtreecommitdiff
path: root/challenge-215/robert-dicicco/ruby/ch-2.rb
blob: 270c0ecd51c062b557fd5860442f34d9496b5645 (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
63
64
65
66
67
68
69
70
#!/usr/bin/env ruby
=begin
-----------------------------------------
AUTHOR: Robert DiCicco
DATE  : 2023-05-03
Challenge 215 Number Placement ( Ruby )
-----------------------------------------
=end

numbers = [[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,0,0,0,0,1]];
counts  = [1,2,3]

cnt = 0;

def CheckZeroes(arr)
    zcnt = 0;
    while zcnt < arr.length() - 1
        if ((arr[zcnt] == 0) && (arr[zcnt-1] == 0))
             arr[zcnt] = 1;
        end
        zcnt += 1;
    end
    puts("Output: 1 = #{arr}")
    puts("")
end


def HowManyZeroes(arr)
    z = 0
    zcnt = 0
    while z < (arr.length()) - 1
        if (arr[z] == 0)
            zcnt += 1
        end
        z += 1
    end
    return zcnt
end

numbers.each do |nums|
    puts("Input: @numbers = #{nums}")
    puts("Count: #{counts[cnt]}")
    cnt += 1
    zeroes = HowManyZeroes(nums)
    if (zeroes < cnt * 2)
        puts("Output: 0")
        puts("")
    else
        CheckZeroes(nums)
    end
end

=begin
-----------------------------------------
ruby .\NumberPlacement.rb
Input: @numbers = [1, 0, 0, 0, 1]
Count: 1
Output: 1 = [1, 0, 1, 0, 1]

Input: @numbers = [1, 0, 0, 0, 1]
Count: 2
Output: 0

Input: @numbers = [1, 0, 0, 0, 0, 0, 0, 0, 1]
Count: 3
Output: 1 = [1, 0, 1, 0, 1, 0, 1, 0, 1]
-----------------------------------------
=end