Advertisement
Guest User

jolly_numbers.py2

a guest
Jan 31st, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. '''
  2.     Jolly
  3.     Not jolly
  4.     Python vs 2.7.9
  5. '''
  6.  
  7. import sys
  8. test_cases = open(sys.argv[1], 'r')
  9. for test in test_cases:
  10.     # ignore test if it is an empty line
  11.     # 'test' represents the test case, do something with it
  12.     # ...
  13.     # ...
  14.     nums = map(int , test.split())
  15.     abs_diff = []
  16.     if len(nums)==1:
  17.         print "Jolly"
  18.     else:
  19.         for i in range(len(nums)-1):
  20.             abs_diff.append(abs(nums[i]-nums[i+1]))
  21.     #print abs_diff
  22.             res = True
  23.         for i in range(1,len(nums)):
  24.             if i in abs_diff:
  25.                 res = res and True
  26.             else:
  27.                 res = res and False
  28.         if res:
  29.             print "Jolly"
  30.         else:
  31.             print "Not jolly"
  32. test_cases.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement