Last active
March 16, 2016 18:44
-
-
Save SergKolo/c8659ddba71ecfc30c1d to your computer and use it in GitHub Desktop.
A recursive solution to Checkio task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # A recursive solution to https://github.com/Bryukh-Checkio-Tasks/checkio-task-stair-steps/blob/master/info/task_description.html | |
| def golf(nums,skipped): | |
| if nums: | |
| x = nums.pop(0) # grab current number | |
| if x < 0 and not skipped: # is this one negative ? | |
| print 'Skipping',x | |
| return golf(nums[0:],True) # then skip | |
| else: | |
| print 'returning',x | |
| return x+golf(nums[0:],False) # otherwise, don't skip | |
| else: return 0 # prevents returning none | |
| #numbers=[5,6,-10,-7,4] | |
| #numbers=[-11, 69, 77, -51, 23, 67, 35, 27, -25, 95] | |
| numbers=[-21, -23, -69, -67, 1, 41, 97, 49, 27] | |
| print 'numbers are' ,numbers | |
| print golf(numbers,False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment