aboutsummaryrefslogtreecommitdiff
path: root/challenge-194/robert-dicicco/ruby/ch-2.rb
blob: 38121e7102a083ab9c83cf97d37a2fa3b7da42f3 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env ruby

=begin

AUTHOR: Robert DiCicco

DATE:   2022-12-06

Challenge 194 Frequency Equalizer ( Ruby )

 

SAMPLE OUTPUT

ruby .\FrequencyEqualizer.rb

Input: $s = 'abbc'

Output: 1

 

Input: $s = 'xyzyyxz'

Output: 1

 

Input: $s = 'xzxz'

Output: 0

=end

 

ss = ["abbc", "xyzyyxz", "xzxz"]

x = 0

seen = Hash.new

 

ss.each do |s|

  puts("Input: $s = \'#{s}\'")

  ln = s.length;

  while x < ln

    zsub = s[x,1]

    if seen.key?(zsub)

      seen[zsub] += 1

    else

      seen[zsub] = 1

    end

    if (x < ln)

      x += 1

    end

  end

  highest = seen.values.max

  lowest  =  seen.values.min

  lowest + 1 == highest ? puts("Output: 1") : puts("Output: 0")

  puts(" ")

  seen = Hash.new

  x = 0

end