-
Notifications
You must be signed in to change notification settings - Fork 0
/
necklace.py
56 lines (41 loc) · 1.6 KB
/
necklace.py
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
''' This program helps in distributing the Diamonds and Emralds in the Necklace between 2 theives..
Notation:- Diamond = 1;
Emerald = 0;
Total no. of Gems = 2(k1 + k2)
No. of Diamonds = 2D
No. of Emralds = 2E
Loop Invariant :- 1) Size of window := k1+k2
2) position of window :=
Variables :- d:= Total no. of Diamonds
i:= position of window
'''
try :
Necklace = []
D = int(raw_input('\n Enter even no. of Diamonds in Necklace \n'))
E = int(raw_input('\n Enter even no. of Emralds in Necklace \n'))
if((D%2!=0) and (E%2!=0)):
print '\n cant divide necklace equally diamond & emrald must be of even no.\n'
exit(1)
D = D/2
E = E/2
length_of_necklace = 2*(D+E)
print '\n enter the order of diamond and emralds as - Diamond = 1; Emerald = 0;\n'
for i in range(0,length_of_necklace):
val = int(raw_input())
if (val ==0 or val ==1):
Necklace.append(val)
else:
print '\n wrong input for diamond & emrald\n'
exit(2)
i = 0
diamond_count=0
window_size = (D+E)
diamond_count = sum(Necklace[i:window_size])
#print "\n\n\n",diamond_count,"\n"
while(diamond_count != D):
diamond_count = diamond_count - Necklace[i] + Necklace[i+D+E]
i = i+1
print "\nThief 1 gets from index", i+1, "till ", i+D+E
print "\nThief 2 gets the remaining necklace\n"
except ValueError:
print ' \nWRONG INPUT : Enter Integer Values only'