Advertisement
DanielKoehler

Untitled

Nov 8th, 2013
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. import cProfile
  2. # def lights(): return["".join(["-" if (len(set(x for x in range(1,buttonNo + 1) if lightNo%x == 0))%2 == 0) else "*" for lightNo in range(1,51)]) for buttonNo in range(1,51)]
  3. # def xlights(): return["".join(["-" if (len(set(x for x in xrange(1,buttonNo + 1) if lightNo%x == 0))%2 == 0) else "*" for lightNo in xrange(1,51)]) for buttonNo in xrange(1,51)]
  4.  
  5. # print cProfile.run('lights()')
  6. # print cProfile.run('xlights()')
  7.  
  8. def iain():
  9.     output = "-" * 50
  10.     for x in range(1,51):
  11.         output = "".join([output[i-1] if (i%x!=0) else "-" if output[i-1] == "*" else "*" for i in xrange(1,51)])
  12.         print output
  13. def dan():    
  14.     output = list("-" * 50)
  15.     for x in xrange(1,51):
  16.         for i in xrange(1,51):
  17.             if i % x == 0:
  18.                 output[i-1] = "*" if output[i-1] == "-" else "-"
  19.         print "".join(output)
  20.  
  21. def last():
  22.     return["".join(["*" if (50 >= x and float(x**.5).is_integer()) else "-" for x in xrange(1,51)])]
  23.  
  24. def testIain():
  25.     for i in xrange(100):
  26.         iain()
  27.  
  28. def testDan():
  29.     for i in xrange(100):
  30.         dan()
  31.  
  32. def testLast():
  33.     for i in xrange(100):
  34.         last()
  35.  
  36. cProfile.run('testDan()')
  37. cProfile.run('testIain()')
  38. # cProfile.run('testLast()')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement