title: Finding switches by divisors
body: <p>There are N switches (from 1 to N) and also N bulbs (from 1 to N).</p>
  
  <p>the switch is can be pressed only once and it can turn ON/OFF the bulb.
  a switch can turn ON/OFF more than 1 bulbs.</p>
  
  <p>For example: 
  The switch number 12 can turn ON/OFF the bulbs <code>{1, 2, 3, 4, 6, 12}</code>
  (because <code>{1, 2, 3, 4, 6, 12}</code> are the divisors of 12)</p>
  
  <p>So we have a function main(N,setON)</p>
  
  <ul>
  <li>N is the number of lights</li>
  <li>SetOn is set of bulbs that are from the beginning are ON</li>
  </ul>
  
  <p>The function must return list of switches that are served to turn ON all the bulbs</p>
  
  <p>For example given, <code>N=6</code> and <code>setON = {2,4}</code>, return the list <code>[2,5,6]</code></p>
  
  <ul>
  <li>after pressed the button 2 will light on <code>{1,4}</code> bulbs</li>
  <li>after pressed the button 5 will light on <code>{4,5}</code> bulbs</li>
  <li>after pressed the button 6 will light on <code>{1,2,3,4,5,6}</code> bulbs</li>
  </ul>
  
  <hr>
  
  <p>I started this question but I'm out of ideas how to solve this.
  I did it in way that I call a function divisors that finds for each number the divisors and after it returns a list of divisors of number N and then I run a loop for each list to see where it turns ON or OFF and put the number of the switch to a new list.
  But I actually don't get the result that I want, and I'm out of ideas.</p>
  
  <p>I would like to here your suggestions, I'm not requesting of you solve my problem, just give me a hint :) or if you want correct me.</p>
  
  <pre><code>import math
  def main(N, setON):
      newList= []
      acces = set(range(1,N+1))
      turnOFF = set()
      for number in range(N,1,-1):
          divs = divisors(number)                    
          for i in divs:
              if i in setON:
                  turnOFF.add(i)
                  setON.remove(i)
              else:
                  setON.add(i)
                  if i in turnOFF:
                      turnOFF.remove(i)
          newList.append(divs[-1])
          if len(setON) == N-1:
              print(newList)
  
  
  def divisors(n):
      divs = [x for x in range(1, int(math.sqrt(n))+1) if n % x == 0]
      opps = [int(n/x) for x in divs]
      return list(set(divs + opps))
  
  
  N=6
  setON={2,4}
  main(N, setON)
  </code></pre>
  
  <p>It gives me [6, 5, 4]</p>