+ 5
The subraction game is played as follows:
There is list of 'n' numbers.Tke all pairs consecutive num in the list & tke their difference.if the difference is +ve ,replace the element in list by the +ve num.else that element is unchange (last num in the list remains unchanged).The new values form the new list.game is played again & again till there will be no further change in the list. example:n=5, list:[34,56,20,90,100] round1:[34,36,20,90,100] round2:[34,16,20,90,100] round3:[18,16,20,90,100] round 4:[2,16,20,90,100] write python code for this??
5 Answers
+ 5
Thank you @kartikey
+ 5
@kartikey In your code,where it is checking for -ve number??
+ 1
@Zainab My Pleasure
+ 1
l[i+1] < l[i]: This checks if the current number is greater than next number
Hence, no need to check if difference is +ve or -ve, this makes the code shorter đ