roy-and-leds-6

Its Diwali time and there are LED series lights everywhere. Little Roy got curious about how LED lights work.

He noticed that in one single LED Bulb there are 3 LED lights, namely Red, Green and Blue.

State of the bulb at any moment is the sum of Red, Green and Blue LED light.

Bulb works as follows:

Roy took out all the LEDs and found that Red LED stays ON for R seconds, Green LED stays ON for G seconds and Blue LED stays ON for B seconds. Similarly they stay OFF for same respective R, G, B number of seconds. (Initially all the LEDs are OFF. See Sample Test Case Explanation for better understanding)

Roy has one query for you, given the total number of seconds T, find the number of seconds Red, Green, Blue, Yellow, Cyan, Magenta, White, Black(no light) lights are visible.

Input:

One line containing space separated integers T, R, G, B

Output:

One line containing 8 space separated integers indicating the number of seconds Red, Green, Blue, Yellow, Cyan, Magenta, White, Black (no light) lights are visible. (See Sample I/O for clarification)

Constraints:

 1 ≤ T, R, G, B ≤ 1000000 

Sample Test Case Explanation:SAMPLE INPUT
12 2 3 5

SAMPLE OUTPUT
1 1 1 3 2 2 0 2

Explanation

As shown in the image above, we have 0 to 11, a total of 12 seconds. State of Bulb for each second is also shown. Red, Blue and Green occur for 1 second; Yellow occur for 3 seconds; Cyan, Magenta and Black occur for 2 seconds and White does not occur at all. (Remember you have to output in R, G, B, Y, C, M, W, B sequence and hence the output is (1\; 1\; 1\; 3\; 2\; 2\; 0\; 2)

Source: hackerearth | Difficulty: EASY
Tags: Implementation

Ad-hoc


Solutions:
def led():
	T,R,G,B = list(map(int,input().split()))
	red = [0]*1000001           #we note down occurences of R,G,B in these three arrays/list
	green = [0]*1000001
	blue = [0]*1000001
	colors = [0]*8         #used to store final result
	r = 0
	rp = 0
	g = 0
	gp = 0
	b = 0
	bp = 0
	for i in range(T):     #note down frequency of occurences in Big O(n)
		if i >= R + 2*R*r and i < 2*R + 2*R*r:
			red[i] = 1
			rp += 1
			if rp%R == 0:
				r += 1
		if i >= G + 2*G*g and i < 2*G + 2*G*g:
			green[i] = 1
			gp += 1
			if gp%G == 0:
				g += 1
		if i >= B + 2*B*b and i < 2*B + 2*B*b:
			blue[i] = 1
			bp += 1
			if bp%B == 0:
				b += 1
	for i in range(T):
		if red[i] == 1 and green[i] == 0 and blue[i] == 0:   #red
			colors[0] += 1
		elif red[i] == 0 and green[i] == 1 and blue[i] == 0: #green
			colors[1] += 1
		elif red[i] == 0 and green[i] == 0 and blue[i] == 1: #blue
			colors[2] += 1
		elif red[i] == 1 and green[i] == 1 and blue[i] == 0: #yellow
			colors[3] += 1
		elif red[i] == 0 and green[i] == 1 and blue[i] == 1: #cyan
			colors[4] += 1
		elif red[i] == 1 and green[i] == 0 and blue[i] == 1: #magenta
			colors[5] += 1
		elif red[i] == 1 and green[i] == 1 and blue[i] == 1: #white
			colors[6] += 1
		else:                                                #black
			colors[7] += 1
	print(' '.join(str(x) for x in colors))
led()



def led():
	T,R,G,B = list(map(int,input().split()))
	red = [0]*1000001           #we note down occurences of R,G,B in these three arrays/list
	green = [0]*1000001
	blue = [0]*1000001
	colors = [0]*8         #used to store final result
	r = 0
	rp = 0
	g = 0
	gp = 0
	b = 0
	bp = 0
	for i in range(T):     #note down frequency of occurences in Big O(n)
		if i >= R + 2*R*r and i < 2*R + 2*R*r:
			red[i] = 1
			rp += 1
			if rp%R == 0:
				r += 1
		if i >= G + 2*G*g and i < 2*G + 2*G*g:
			green[i] = 1
			gp += 1
			if gp%G == 0:
				g += 1
		if i >= B + 2*B*b and i < 2*B + 2*B*b:
			blue[i] = 1
			bp += 1
			if bp%B == 0:
				b += 1
	for i in range(T):
		if red[i] == 1 and green[i] == 0 and blue[i] == 0:   #red
			colors[0] += 1
		elif red[i] == 0 and green[i] == 1 and blue[i] == 0: #green
			colors[1] += 1
		elif red[i] == 0 and green[i] == 0 and blue[i] == 1: #blue
			colors[2] += 1
		elif red[i] == 1 and green[i] == 1 and blue[i] == 0: #yellow
			colors[3] += 1
		elif red[i] == 0 and green[i] == 1 and blue[i] == 1: #cyan
			colors[4] += 1
		elif red[i] == 1 and green[i] == 0 and blue[i] == 1: #magenta
			colors[5] += 1
		elif red[i] == 1 and green[i] == 1 and blue[i] == 1: #white
			colors[6] += 1
		else:                                                #black
			colors[7] += 1
	print(' '.join(str(x) for x in colors))
led()


from itertools import cycle, islice
colors = 'KBGCRMYW'
t, r, g, b = list(map(int, input().split()))
seq = zip(cycle(['0']*r + ['1']*r), cycle(['0']*g + ['1']*g), cycle(['0']*b + ['1']*b))
stats = dict(list(zip(colors, [0]*8)))
for s in islice(seq, 0, t):
	stats[colors[int(''.join(s), 2)]] += 1
print('%s %s %s %s %s %s %s %s' % (stats['R'], stats['G'], stats['B'], stats['Y'], stats['C'], stats['M'], stats['W'], stats['K']))


from itertools import cycle, islice
colors = {(0, 0, 0) :'K',
	(0, 0, 1) :'B',
	(0, 1, 0) :'G',
	(0, 1, 1) :'C',
	(1, 0, 0) :'R',
	(1, 0, 1) :'M',
	(1, 1, 0) :'Y',
	(1, 1, 1) :'W'}
t, r, g, b = list(map(int, input().split()))
seq = zip(cycle([0]*r + [1]*r), cycle([0]*g + [1]*g), cycle([0]*b + [1]*b))
stats = dict(list(zip(list(colors.values()), [0]*8)))
for s in islice(seq, 0, t):
    stats[colors[s]] += 1
print('%s %s %s %s %s %s %s %s' % (stats['R'], stats['G'], stats['B'], stats['Y'], stats['C'], stats['M'], stats['W'], stats['K']))



t,r,g,b=list(map(int,input().split()))
rc=(("0"*r)+("1"*r))*((t/(2*r))+1)
gc=(("0"*g)+("1"*g))*((t/(2*g))+1)
bc=(("0"*b)+("1"*b))*((t/(2*b))+1)
res=[]
for i in range(t):
	if((rc[i]+gc[i]+bc[i])=="000"):
		res.append('z')
	elif((rc[i]+gc[i]+bc[i])=="001"):
		res.append('b')
	elif((rc[i]+gc[i]+bc[i])=="010"):
		res.append('g')
	elif((rc[i]+gc[i]+bc[i])=="011"):
		res.append('c')
	elif((rc[i]+gc[i]+bc[i])=="100"):
		res.append('r')
	elif((rc[i]+gc[i]+bc[i])=="101"):
		res.append('m')
	elif((rc[i]+gc[i]+bc[i])=="110"):
		res.append('y')
	else:
		res.append('w')
print(res.count('r'),res.count('g'),res.count('b'),res.count('y'),res.count('c'),res.count('m'),res.count('w'),res.count('z'))


l=[int(x) for x in input().split()]
l1=[]
l2=[]
l3=[]
c1=0
c2=0
c3=0
for i in range(0,l[0]):
	l1.append(0)
	c1+=1
	if(c1==l[1]):
		c1=0
		d=l[1]
		while(d!=0):
			l1.append(1)
			d-=1
l11=l1[0:l[0]]
for j in range(0,l[0]):
	l2.append(0)
	c2+=1
	if(c2==l[2]):
		c2=0
		d1=l[2]
		while(d1!=0):
			l2.append(1)
			d1-=1
l21=l2[0:l[0]]
for k in range(0,l[0]):
	l3.append(0)
	c3+=1
	if(c3==l[3]):
		c3=0
		d2=l[3]
		while(d2!=0):
			l3.append(1)
			d2-=1
l31=l3[0:l[0]]
l4=[]
for m in range(0,l[0]):
	if(l11[m]==0 and l21[m]==0 and l31[m]==0):
		l4.append("black")
	elif(l11[m]==1 and l21[m]==0 and l31[m]==0):
		l4.append("red")
	elif(l11[m]==0 and l21[m]==1 and l31[m]==0):
		l4.append("green")
	elif(l11[m]==0 and l21[m]==0 and l31[m]==1):
		l4.append("blue")
	elif(l11[m]==1 and l21[m]==1 and l31[m]==0):
		l4.append("yellow")
	elif(l11[m]==1 and l21[m]==0 and l31[m]==1):
		l4.append("magenta")
	elif(l11[m]==0 and l21[m]==1 and l31[m]==1):
		l4.append("cyan")
	elif(l11[m]==1 and l21[m]==1 and l31[m]==1):
		l4.append("white")
print(l4.count("red"),l4.count("green"),l4.count("blue"),l4.count("yellow"),l4.count("cyan"),l4.count("magenta"),l4.count("white"),l4.count("black"))


usr_in = input().split(' ')
d = int(usr_in[0])
r = int(usr_in[1])
g = int(usr_in[2])
b = int(usr_in[3])
rr = r
gg = g
bb = b
rlst=[]
glst=[]
blst=[]
color_dict = {'r':0,'g':0,'b':0,'y':0,'c':0,'m':0,'w':0,'n':0}
for t in range(0,d):
	rlst.append('0')
	glst.append('0')
	blst.append('0')
for t in range(0,d):
	if r == t:
		for i in range(r,r+rr):
			if i < len(rlst):
				rlst[i] = '1'
		r = r + 2*rr
	if g == t:
		for j in range(g,g+gg):
			if j < len(glst):
				glst[j] = '1'
		g = g + 2*gg
	if b == t:
		for k in range(b,b+bb):
			if k < len(blst):
				blst[k] = '1'
		b = b + 2*bb
#print(rlst)
#print(glst)
#print(blst)
red,gr,bl,y,c,m,n,w=0,0,0,0,0,0,0,0
for l in range(0,d):
	rf = rlst[l]
	gf = glst[l]
	bf = blst[l]
	concat_flag = rf + gf + bf
	n1 = int(concat_flag,2)
	if n1 == 0:
		n = n + 1
		color_dict['n'] = n
	elif n1 == 4:
		red = red + 1
		color_dict['r'] = red
	elif n1 == 2:
		gr = gr + 1
		color_dict['g'] = gr
	elif n1 == 1:
		bl = bl + 1
		color_dict['b'] = bl
	elif n1 == 6:
		y = y + 1
		color_dict['y'] = y
	elif n1 == 3:
		c = c + 1
		color_dict['c'] = c
	elif n1 == 5:
		m = m + 1
		color_dict['m'] = m
	elif n1 == 7:
		w = w + 1
		color_dict['w'] = w
print(('%d %d %d %d %d %d %d %d'%(color_dict['r'],color_dict['g'],color_dict['b'],color_dict['y'],color_dict['c'],color_dict['m'],color_dict['w'],color_dict['n'])))