+/foobar
google programming puzzles
git clone https://git.julia.blue/+/foobar
2e1d345
master
1def fib (): 2prev = 0 3current = 1 4while True : 5yield current 6temp = prev + current 7prev = current 8current = temp 9 10 11def powersof2 (): 12current = 1 13while True : 14yield current 15current *= 2 16 17 18def countGuards (tot ,func ): 19guards = 0 20for i in func (): 21tot -= i 22if tot < 0 : 23if func == powersof2 : 24tot += i 25if tot >= i / 2 + i / 4 : 26guards += 1 27break 28guards += 1 29return guards 30 31 32def answer (total_lambs ): 33return countGuards (total_lambs ,fib )- countGuards (total_lambs ,powersof2 ) 34 35 36import sys 37answer (int (sys .argv [1 ])) 38 39# print "".join(["._-^@|X"[answer(i)] for i in range(int(sys.argv[1]))])