News for hackers. Stuff that matters.
Re:The ancient world before computers had stacks or heaps by jameshart on Thursday April 04, 2024 @08:36AM (#39929621)
There’s an easy way to figure out if recursion is fine for your usecase

   def isRecursionOk(problem)
       for (subProblem in (breakDownIntoSubProblems(problem))
           if ! isRecursionOk(subProblem) return false
       return true
Re:The ancient world before computers had stacks or heaps by hughdbrown on Thursday April 04, 2024 @11:52AM (#39931985)
This code terminates only if all child-problems eventually are found not to have subproblems. So either it has infinite subproblems or it returns true. So recursion is good for a use case unless the problem decomposes into infinite subproblems, but in that case this test function never returns false.

Makes more sense to do it as breadth-first with only one return value:

   from collections import deque
   def isRecursionOk(problem):
       q = deque(problem)
       while q:
           problem = q.popleft()
           q.append(list(breakDownIntoSubProblems(problem)))
       return true
Re:The ancient world before computers had stacks or heaps by Joel_Mckay on Thursday April 04, 2024 @11:53AM (#39931997)
"kernel: Out of memory: Kill process 9163 (Insulin-pump-task) score 511 or sacrifice child"

There are safer hobbies available like snake juggling =)