recursion

SQL Server Trigger for recursive delete on a cascade

狂风中的少年 提交于 2020-02-24 09:07:19
问题 I have a table which contains a tree like structure It takes the form of: -nodeID,fkID,parentNode (parentNode is NULL if it is the root and the nodeID of its parent if it is a child) (fkID is NULL if it is not the root) the fkID is a FK which when deleted in another table cascades its delete to this table. This cascading delete only however references the root node. There is another constraint put on the database in which a root node cannot be deleted unless its children are deleted first.

Increasing stack size in browsers

你离开我真会死。 提交于 2020-02-23 10:44:21
问题 Short question: I have a javascript that goes very deep in recursion. How can I increase the stack size so that I can execute it (something like "ulimit -s unlimited" in Unix systems)? Long story: I have to draw a graph and I use Cytoscape JS (http://js.cytoscape.org/) coupled with the Dagre layout extension (https://github.com/cytoscape/cytoscape.js-dagre). The drawing algorithm goes deep in the recursion and I end up getting "Uncaught RangeError: Maximum call stack size exceeded" in Chrome

Increasing stack size in browsers

允我心安 提交于 2020-02-23 10:43:28
问题 Short question: I have a javascript that goes very deep in recursion. How can I increase the stack size so that I can execute it (something like "ulimit -s unlimited" in Unix systems)? Long story: I have to draw a graph and I use Cytoscape JS (http://js.cytoscape.org/) coupled with the Dagre layout extension (https://github.com/cytoscape/cytoscape.js-dagre). The drawing algorithm goes deep in the recursion and I end up getting "Uncaught RangeError: Maximum call stack size exceeded" in Chrome

Using print() inside recursive functions in Python3

一笑奈何 提交于 2020-02-23 09:33:46
问题 I am following the book Introduction to Computing Using Python, by Ljubomir Perkovic, and I am having trouble with one of the examples in recursion section of the book. The code is as follows: def pattern(n): 'prints the nth pattern' if n == 0: # base case print(0, end=' ') else: #recursive step: n > 0 pattern(n-1) # print n-1st pattern print(n, end=' ') # print n pattern(n-1) # print n-1st pattern For, say, pattern(1) , the output should be 0 1 0 , and it should be displayed horizontally.

How to find sum of even numbers in a list using recursion?

心不动则不痛 提交于 2020-02-23 05:46:07
问题 def sum_evens_2d(xss): i = 0 counter = 0 while (i < len(xss)): if(xss[i]%2 == 0): counter += xss[i] i= i+1 else: i = i+1 return(counter) I am trying to find the sum of the evens in the list xss . My restrictions are that I can not use sum() , but recursion only. 回答1: Just tested this one out, it should work: def even_sum(a): if not a: return 0 n = 0 if a[n] % 2 == 0: return even_sum(a[1:]) + a[n] else: return even_sum(a[1:]) # will output 154 print even_sum([1, 2, 3, 4, 5, 6, 7, 8, 23, 55, 45

MySql sql recursive loop

岁酱吖の 提交于 2020-02-22 23:41:36
问题 I am building a navigation menu from a list of pages. The table is like this: Table name: pages id | type | parent | name ------------------------------- 1, 1, null, root1 2, 1, null, root2 3, 2, 2, home 4, 2, 3, child 5, 2, 4, sub_child 6, 3, 5, sub_sub_child type: 1 = root page / site 2 = page 3 = ... My problem is that from any page, I have to find the root page. I have a column parent that refers to the parent page, except for the root pages. I can have multiple root pages in the table,

wget hangs with -r and -O -

坚强是说给别人听的谎言 提交于 2020-02-22 06:03:11
问题 This is a VERY strange wget behavior. I'm on debian 7.2. wget -r -O - www.blankwebsite.com hangs forever. And I mean it hangs , it isn't searching through the internet, I can verify it with a strace . If I do this: while read R do wget -r -O - www.blankwebsite.com done < smallfile with smallfile containing a single line, the command exits in a few seconds. I tried also with wget -r -O - localhost/test.html with an empty test.html file, same results. To me, it sounds like a bug. Everything

Recursive query in PostgreSQL. SELECT *

限于喜欢 提交于 2020-02-21 10:46:06
问题 I have recursive query to retrieve all children of a given person WITH RECURSIVE recursetree(id, parent_id) AS ( SELECT id, parent_id FROM tree WHERE parent_id = 0 UNION SELECT t.id, t.parent_id FROM tree t JOIN recursetree rt ON rt.id = t.parent_id ) SELECT * FROM recursetree; As you can see, I'm specifying list of columns to be retrieved. But I want to use SELECT * (I have really many columns in real table, and they can be changed in future). Is there some way to get ALL columns without

Recursive query in PostgreSQL. SELECT *

我们两清 提交于 2020-02-21 10:39:31
问题 I have recursive query to retrieve all children of a given person WITH RECURSIVE recursetree(id, parent_id) AS ( SELECT id, parent_id FROM tree WHERE parent_id = 0 UNION SELECT t.id, t.parent_id FROM tree t JOIN recursetree rt ON rt.id = t.parent_id ) SELECT * FROM recursetree; As you can see, I'm specifying list of columns to be retrieved. But I want to use SELECT * (I have really many columns in real table, and they can be changed in future). Is there some way to get ALL columns without

List folders at or below a given depth in Powershell

梦想与她 提交于 2020-02-20 21:37:19
问题 I have a directory which contains a lot of folders. I want to list all folder (path) that go deeper than 2 levels. So in below case folder 1 & 2. Directory/folder1 Directory/folder1/test1/test/testsub Directory/folder1/test2 Directory/folder1/test3 Directory/folder2/blablabla/bla/1 Directory/folder3/test Directory/folder4/test Directory/folder5/test I was trying the following: $Depth = 3 $Path = "." $Levels = "\*" * $Depth $Folder = Get-Item $Path $FolderFullName = $Folder.FullName Resolve