Profile image for atusi nakamura a2c
RT @webos_goodies: ある数より大きい2の累乗の数のうち最小のものをもとめるスマートな方法ってなかったっけな。

(http://twitter.com/webos_goodies...)
Language
Python
Tags
python

ある数より大きい2の累乗の数のうち最小のものをもとめる

1 #!/usr/bin/env python 2 # coding:utf-8 3 4 def func(x): 5 pow, flg, ret = 0, 1, None 6 while flg: 7 pow += 1 8 res = 2** pow 9 if res > x: 10 ret = res 11 flg = 0 12 return ret 13 if __name__ == '__main__': 14 print func(510)

Comments