forked from adityabisoi/ds-algo-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.py
40 lines (27 loc) · 883 Bytes
/
solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/python
import math
import os
import random
import re
import sys
# Complete the utopianTree function below.
def utopianTree(n):
height = 1 # Initial height of tree is 1
#For Loop to traverse over n growth cycles.
for period in range(1,n+1):
#For Spring growth cycle , height is doubled.
if period % 2 == 1 :
height = height*2
#For Summer growth cycle , height is increased by one.
else:
height = height + 1
#Return the height of Tree after N growth cycles.
return height
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(raw_input())
for t_itr in xrange(t):
n = int(raw_input())
result = utopianTree(n)
fptr.write(str(result) + '\n')
fptr.close()