aboutsummaryrefslogtreecommitdiff
path: root/challenge-194/robert-dicicco/python/ch-2.py
blob: 3b68b1e8a89b2639ac67a7e9c003aad3f15df8a0 (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
#!/usr/bin/env python

'''

AUTHOR: Robert DiCicco

DATE:   2022-12-06

Challenge 194 Frequency Equalizer ( Python )

 

SAMPLE OUTPUT

python .\FrequencyEqualizer.py

Input: $s = abbc

Output: 1

 

Input: $s = xyzyyxz

Output: 1

 

Input: $s = xzxz

Output: 0

'''

 

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

x = 0

 

for s in ss :

  x = 0

  seen = dict()

  print(f"Input: $s = {s}")

  ln =len(s)

  while x < ln :

    zsub = s[x:x+1]

    if zsub in seen :

      seen[zsub] += 1

    else :

      seen[zsub] = 1

    x += 1

 

  highest = max(seen.values())

  lowest  = min(seen.values())

 

  if (lowest + 1 == highest) :

    print("Output: 1\n")

  else :

    print("Output: 0\n")