human
Recaman 's sequence | Prints first n terms of Recaman sequence.
Print first term and store it in a hash.
Print remaining terms using recursive formula ..
If arr [ i - 1 ] - i is negative or already exists ..
Driver code"
How can the above be solved in Python?
 Give me a code to recaman 's sequence and the other steps required?
assistant
#Here is code to recaman 's sequence and the other steps required.
 def recaman ( n ) :
	if ( n <= 0 ) :
		return
	print ( 0 , " , " , end = ' ' )
	s = set ( [ ] )
	s . add ( 0 )
	prev = 0
	for i in range ( 1 , n ) :
		curr = prev - i
		if ( curr < 0 or curr in s ) :
			curr = prev + i
		s . add ( curr )
		print ( curr , " , " , end = ' ' )
		prev = curr
if __name__ == ' _ _ main _ _ ' :
	n = 17
	recaman ( n )