• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

sum of odd and even  RSS feed

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Would like to ask.
How do I combine these two functions:


AND


 
Marshal
Posts: 64172
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same as you would for any recursion: use 1 and 2 for your base case. In Java® I would writeYou will of course get an “infinite” recursion if i ≤ 0
 
Vadim Melders
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In java it is more clear and understandable for me...
I just started python in uni, getting used to it...
Question is - in python
 
Vadim Melders
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

wrong for odd
 
Sheriff
Posts: 21719
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Same as you would for any recursion: use 1 and 2 for your base case. In Java® I would writeYou will of course get an “infinite” recursion if i ≤ 0


The quotes around infinite are correct, because it would definitely end because of overflow. The method will be recursively called until the argument becomes Integer.MIN_VALUE or Integer.MIN_VALUE + 1. When you subtract 2 from that it will overflow to Integer.MAX_VALUE - 1 or Integer.MAX_VALUE respectively.

Of course you'll run into a StackOverflowError long before it even gets there.
 
Greenhorn
Posts: 26
Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vadim,

In addition to the other ways of hitting some limit, Python also has a builtin recursion default limit of 1000.  It can be changed by using sys.setrecursionlimit() if desired. However, for most Python programs, hitting that limit (or one of the others) means that the algorithm can be improved to avoid hitting any of these limits.  🙂
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!