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
|
#!/usr/bin/env python
# -----------------------------------------
# AUTHOR: Robert DiCicco
# DATE : 2023-05-03
# Challenge 215 Number Placement ( Python )
# -----------------------------------------
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 = 1;
while zcnt < len(arr):
if ((arr[zcnt] == 0) and (arr[zcnt-1] == 0)):
arr[zcnt] = 1
zcnt += 1;
print(f"Output: 1 = {arr}\n")
def HowManyZeroes(arr):
z = 0
zcnt = 0
while z < (len(arr)):
if (arr[z] == 0):
zcnt += 1
z += 1
return zcnt
for nums in numbers:
print(f"Input: @numbers = {nums} Count = {counts[cnt]}")
zeroes = HowManyZeroes(nums)
if (zeroes < (counts[cnt] * 2)):
print("Output: 0\n")
else:
CheckZeroes(nums)
cnt += 1
# -----------------------------------------
# SAMPLE OUTPUT
# python .\NumberPlacement.py
# 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]
# -----------------------------------------
|