human
Count ways to reach the nth stair using step 1 , 2 or 3 | A recursive function used by countWays.
declaring three variables and holding the ways for first three stairs.
d = 0 fourth variable.
starting from 4 as already counted for 3 stairs.
Driver program to test above functions"
Solution in Python:
 ... Write me a code to count ways to reach the nth stair using step 1 , 2 or 3 and the other steps required?
assistant
#Here is code to count ways to reach the nth stair using step 1 , 2 or 3 and the other steps required.
 def countWays ( n ) :
	a = 1
	b = 2
	c = 4
	if ( n == 0 or n == 1 or n == 2 ) :
		return n
	if ( n == 3 ) :
		return c
	for i in range ( 4 , n + 1 ) :
		d = c + b + a
		a = b
		b = c
		c = d
	return d
n = 4
print ( countWays ( n ) )