Advertisement
Guest User

solve_sum.py

a guest
May 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. def solve(sum):
  2.     sum_left = sum
  3.     func_h_r = []
  4.     for i in range(1,sum_left):
  5.         sum_left = sum_left - i
  6.         func_h_r.append(i)
  7.         if sum_left>=i:
  8.             continue
  9.         else:
  10.             break
  11.     h=len(func_h_r)
  12.     while sum_left>0:
  13.         i-=1
  14.         sum_left=sum_left-i
  15.         func_h_r.append(i)
  16.         if sum_left==0:
  17.             n_h_r=len(func_h_r)
  18.             break
  19.         elif sum_left<0:
  20.             n_h_r=-1
  21.         else:
  22.             continue
  23.     return print(func_h_r)
  24.  
  25. solve(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement