recursion

Joi deep nested recursive array of alternative objects validation

时光总嘲笑我的痴心妄想 提交于 2021-02-11 18:18:12
问题 I have following json I am trying to validate using @hapi/Joi 16+. It largely works up to 3 levels. But after that it wouldn't validate the alternative files . folder schema get validated fine. I am hoping for optimised solution that would validate deep nested array. In here ONLY folders suppose to have optional children . Files schema should NOT have children . Hence I am using alternatives. const data = [{ id: '1', //UUID type: 'folder', children: [{ id: '2', //UUID type: 'folder', children

Getting depth-first traversal insted of breadth first in T-SQL

限于喜欢 提交于 2021-02-11 16:55:55
问题 I have the following T-SQL function: https://gist.github.com/cwattengard/11365802 This returns data in a breadth-first traversal. Is there a simple way to make this function return its data in a depth-first traversal? I have a treeview-component that excpects this (legacy system). I already have a similar stored procedure that returns the tree in a depth-first traversal, but it's using cursors and is really slow. (6-7 seconds as opposed to this function that takes less than a second on the

python - list variable not storing proper result in recursion

删除回忆录丶 提交于 2021-02-11 16:10:09
问题 I am trying to store all possible parenthesisation of a list through recursion. Example: printRange(0,3) Answer will be [[0],[1], [2]], [[0], [1, 2]], [[0, 1], [2]], [[0, 1, 2]] I could get a right answer when i tried to print it in side the function.When i try to store the result and print it after i am not getting the desired result. The code is as follows: res=[] def printRange(st,size,cans=[]): if(st==size): res.append([]+cans) print cans l=[] for i in range(st,size): l.append(i) tmp=[]

python - list variable not storing proper result in recursion

你离开我真会死。 提交于 2021-02-11 16:09:27
问题 I am trying to store all possible parenthesisation of a list through recursion. Example: printRange(0,3) Answer will be [[0],[1], [2]], [[0], [1, 2]], [[0, 1], [2]], [[0, 1, 2]] I could get a right answer when i tried to print it in side the function.When i try to store the result and print it after i am not getting the desired result. The code is as follows: res=[] def printRange(st,size,cans=[]): if(st==size): res.append([]+cans) print cans l=[] for i in range(st,size): l.append(i) tmp=[]

Nesting hierarchical data into an array - PHP (Codeigniter)

丶灬走出姿态 提交于 2021-02-11 15:39:29
问题 I have been trying to solve this for while but its been a little difficult. the thing is, am trying nest the data from the table bellow into an array in the order by which they are related. +-----+------+------------+ | uid | name | supermember| +-----+------+------------+ | 1 | A | 0 | | 2 | B | 1 | | 3 | C | 1 | | 4 | D | 2 | | 5 | E | 3 | | 7 | G | 3 | | 9 | H | 4 | | 10 | I | 4 | | 11 | J | 7 | +-----+------+------------+ Here is what i have done: public function getDataAsBinaryTree($id)

Nesting hierarchical data into an array - PHP (Codeigniter)

蓝咒 提交于 2021-02-11 15:38:38
问题 I have been trying to solve this for while but its been a little difficult. the thing is, am trying nest the data from the table bellow into an array in the order by which they are related. +-----+------+------------+ | uid | name | supermember| +-----+------+------------+ | 1 | A | 0 | | 2 | B | 1 | | 3 | C | 1 | | 4 | D | 2 | | 5 | E | 3 | | 7 | G | 3 | | 9 | H | 4 | | 10 | I | 4 | | 11 | J | 7 | +-----+------+------------+ Here is what i have done: public function getDataAsBinaryTree($id)

Is there a more optimal solution to this money change problem?

旧巷老猫 提交于 2021-02-11 15:13:18
问题 I was asked to create a method that would: Return a Change object or null if there was no possible change The "machine" has unlimited bills of: 2, 5 and 10 The Change object must return the most minimal amount of bills possible This was a question asked in codingame.com and wanted to investigate further on it. Here's the code: package com; class Change { long coin2 = 0, bill5 = 0, bill10 = 0; } public class Test { static Change c = new Change(); public static void main(String[] args) { Change

Is there a more optimal solution to this money change problem?

耗尽温柔 提交于 2021-02-11 15:12:01
问题 I was asked to create a method that would: Return a Change object or null if there was no possible change The "machine" has unlimited bills of: 2, 5 and 10 The Change object must return the most minimal amount of bills possible This was a question asked in codingame.com and wanted to investigate further on it. Here's the code: package com; class Change { long coin2 = 0, bill5 = 0, bill10 = 0; } public class Test { static Change c = new Change(); public static void main(String[] args) { Change

Issue vectorizing a recursive function that is used in iterative scheme to calculate Numpy array

假如想象 提交于 2021-02-11 15:07:46
问题 I have the following recursive function, def subspaceiterate(A,V,v,j): if j == 0: return v else: v_jm1 = V[:,j-1] v_jm1 = np.reshape(v_jm1,(np.size(V,axis=0),1)) v = v - np.matmul(v_jm1.T,np.matmul(A,v_jm1)) j = j - 1 subspaceiterate(A,V,v,j) A is an mxm matrix whose eigenvalues and eigenvectors I want to compute using an iterative method, V is an mxm matrix that stores my initial guess for the eigenvectors of A , v_j is a particular column of V , and j is an index that I descend and use to

Issue vectorizing a recursive function that is used in iterative scheme to calculate Numpy array

醉酒当歌 提交于 2021-02-11 15:06:29
问题 I have the following recursive function, def subspaceiterate(A,V,v,j): if j == 0: return v else: v_jm1 = V[:,j-1] v_jm1 = np.reshape(v_jm1,(np.size(V,axis=0),1)) v = v - np.matmul(v_jm1.T,np.matmul(A,v_jm1)) j = j - 1 subspaceiterate(A,V,v,j) A is an mxm matrix whose eigenvalues and eigenvectors I want to compute using an iterative method, V is an mxm matrix that stores my initial guess for the eigenvectors of A , v_j is a particular column of V , and j is an index that I descend and use to