+ 13

[ASSIGNMENT] The LED Problem

In one LED Bulb there are 3 LED lights:Red, Green and Blue. See the colour combinations: https://ibb.co/bJCpGx Red LED stays ON for R seconds Green LED stays ON for G seconds Blue LED stays ON for B seconds Similarly they stay OFF for same R, G, B seconds. Initially,the LEDs are OFF. Challenge: Given the total number of seconds T, find the number of seconds Red, Green, Blue, Yellow,Cyan,Magenta,White,Black(No Light) stays ON. SampleInput: 12 2 3 5 SampleOutput: 1 1 1 3 2 2 0 2 Ill: https://ibb.co/dkWkOc

29th Apr 2018, 11:35 AM
Vivek Sivaramakrishnan
Vivek Sivaramakrishnan - avatar
13 Answers
+ 6
My Solution: https://code.sololearn.com/cLK33a4u16jl/?ref=app P. S: Not the best answer though
29th Apr 2018, 11:44 AM
Vivek Sivaramakrishnan
Vivek Sivaramakrishnan - avatar
+ 10
Nice challenge, Vivek ! https://code.sololearn.com/cnu9XJQxO14s/?ref=app An alternative with visualisation of the cycle, using numpy arrays https://code.sololearn.com/c2MDuz3HSW4s/#py
30th Apr 2018, 12:10 AM
CĂ©pagrave
CĂ©pagrave - avatar
+ 9
Check this one liner. Also adds a clearer output. https://code.sololearn.com/c8zi5zXN8EpL
29th Apr 2018, 6:59 PM
VcC
VcC - avatar
+ 8
@VcC It looks super cool! And especially for you I reduced my code to oneliner (2 lines in fact), however now only color codes left and the code itself looks overcomplicated, but it still works for any number of LED (!) : https://code.sololearn.com/cB3DEYXbf4nf/?ref=app
29th Apr 2018, 11:14 PM
Nevfy
+ 7
This is an extended version, which can operate with any number of individual LED inside one LED bulb. However, only for 3 LEDs colors are returned by name otherwise it is a color code: https://code.sololearn.com/cSSqHowN6JYs/?ref=app Input example for 5 LED (32 different colors): 1000 2 3 5 7 4 Feel free to test it and inform me about any bugs you have found!
29th Apr 2018, 5:44 PM
Nevfy
+ 7
Hello all, here the first code that deals with time as a floating number and not as an integer. At least here time is continuos ;) Feel free to enter decimals to the time of the leds. Works for any number of leds. https://code.sololearn.com/cGgmtn40ZHv8/?ref=app
30th Apr 2018, 5:47 AM
Edward
Edward - avatar
+ 6
https://code.sololearn.com/cDjs2M26cfU1/?ref=app
29th Apr 2018, 7:34 PM
Russ
Russ - avatar
+ 3
@Nevfy Vivek Sivaramakrishnan Men, so many lines...And dont tell me about the complexity, i know :-)
29th Apr 2018, 7:00 PM
VcC
VcC - avatar
+ 1
@~ swim ~ Look into my code, I had to deal with floating precision again :) this time the answer was much simpler.
3rd May 2018, 5:50 PM
Edward
Edward - avatar