-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathmarketing-strategy.py
More file actions
59 lines (45 loc) · 1.27 KB
/
marketing-strategy.py
File metadata and controls
59 lines (45 loc) · 1.27 KB
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
#!/bin/python3
import math
import os
import random
import re
import sys
from itertools import zip_longest
#
# Complete the 'minimumSwaps' function below.
#
# The function is expected to return an INTEGER.
# The function accepts STRING status as parameter.
#
# NOTE: This only passes the first three test cases.
def minimumSwaps(status):
return min(num_swaps_to_start_with_sale(status), num_swaps_to_start_with_regular(status))
def num_swaps_to_start_with_sale(status):
swaps = 0
groups = grouper(status, 2)
for group in groups:
a, b = group
if(a != None and a != 'S'):
swaps += 1
elif(b != None and b != 'R'):
swaps += 1
return swaps
def num_swaps_to_start_with_regular(status):
swaps = 0
groups = grouper(status, 2)
for group in groups:
a, b = group
if(a != None and a != 'R'):
swaps += 1
elif(b != None and b != 'S'):
swaps += 1
return swaps
def grouper(iterable, n, fillvalue=None):
args = [iter(iterable)] * n
return zip_longest(*args, fillvalue=fillvalue)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
status = input()
result = minimumSwaps(status)
fptr.write(str(result) + '\n')
fptr.close()