recursion

recursively generate filepaths from object properties

风格不统一 提交于 2019-12-24 00:35:03
问题 I am using node.js and as a side project i am creating a module that reads a .json file ,parse it then create directory structure based on object properties & object values . Object properties (keys) would be the path to itself/to files & object values would be the list of files for that path i have tried to recurse downwards through the object but i dont know how i extract the path from the inner-most object of each object Also object would be dynamic as would be created by the user. var

Simple java recursion, unpredictable program behavior

我是研究僧i 提交于 2019-12-24 00:13:42
问题 Trivial program to calculate compound interest, I = P(1+n)^y. public class Interest { public static void main(String[] args){ double sum = calculate(1000,10,3); System.out.println(sum); //sanity check, using non-recursive formula: double amt = 1000*(Math.pow(1 + 0.1, 3)); System.out.println(amt); } public static double calculate(double initialAmount, double interest, int years){ double yearly = initialAmount + initialAmount*(interest/100); System.out.println("calculate is called with P = " +

Find path in tree by direct path

北城以北 提交于 2019-12-23 23:27:12
问题 I have similiary problem like here: JavaScript: Find all parents for element in tree recursive But I don't find path by name but by direct path . const path = ["name1", "name4", "name5"]; const data = [ { 'name': 'name1', 'tree': [ {'name': 'name2'}, {'name': 'name3'}, { 'name': 'name4', 'tree': [ {'name': 'name5'}, {'name': 'name6'} ] }, {'name': 'name7'} ] }, { 'name': 'name8', 'tree': [ {'name': 'name9'} ] } ]; It returns every possible path or nothing. When path is too short, it returns

Recursive search of file/folder structure

做~自己de王妃 提交于 2019-12-23 23:13:03
问题 I am trying to build a recursive search function for a web service that returns a list of files and folders. I created the two methods so they act as recursive search, it first goes and gets the top level contents, then it adds any files to the fileList, and any sub folders to the subFoldersList. We pass in the access level (in our case root) and then the path which you want the information for. If any folders were found it then removes the top folder because it has begun the search for that

Prolog - Operation inside findall

旧时模样 提交于 2019-12-23 22:11:21
问题 Using a findall in Prolog how can I perform operations inside the goal without affecting backtracking? The following example explains what I'm trying to achieve: value('M1', 11, 3). value('M2', 11, 3). connection('M1',1, 'A', 'B'). connection('M1',1, 'B', 'C'). connection('M1',2, 'C', 'D'). connection('M1',2, 'D', 'E'). connection('M2',1, 'D', 'F'). run :- bbR('C',[(0,'X',['A'])],_,_). run2 :- bbR2('C',[(0,['A'])],_,_). bbR(Destination,[(Cost,_,[Destination|T])|_],Result,Cost):- reverse(

Object nested property access

坚强是说给别人听的谎言 提交于 2019-12-23 21:54:58
问题 I'm trying to write a function that adds an accessor for each nested property in an object. To make this a bit clearer, given object o , and a string representing a path, I should be able to access the property at that path as a named property: var o = { child1: "foo", child2: { child1: "bar", child2: 1 child3: { child1: "baz" } } }; addAccessors(o); o["child2.child1"]; // "bar" o["child2.child2"]; // 1 o["child2.child3.child1"]; // "baz" Note that the names won't always be as uniform. Here

How to follow recursion systematically?

橙三吉。 提交于 2019-12-23 21:45:00
问题 Well, I have many 'C language' tests that involve finding the output of a given function,moreover, I need to explain precisely what's the purpose of it. Some of them are recursive functions. And when I meet recursion, I always struggle on finding how to follow it schematically , and even if I do succeed, sometimes I might not understand what is the purpose of the recursive function . Here are 2 pieces of code: Main #include <stdio.h> #include <conio.h> int f2(int *a, int n, int x); int main()

Process JSON to create the hierarchical relationship

自闭症网瘾萝莉.ら 提交于 2019-12-23 20:26:08
问题 I am sorry if I am asking a foolish question but this is something which is troubling me and I am not able to find the best solution of it yet. I have a JSON Data which look like this: { "my_data": [ { "name": "bugs_db", "type": "database", "children": [ { "name": "oss", "type": "ui" }, { "name": "dashboard", "type": "ui" }, { "name": "dev-dash", "type": "ui" } ] }, { "name": "oss", "type": "ui", "children": [ { "name": "active-directory", "type": "nfs" }, { "name": "passive-directory", "type

Fortran recursion segmentation faults

江枫思渺然 提交于 2019-12-23 19:59:21
问题 I have to design and implement a Fortran routine to determine the size of clusters on a square lattice, and it seemed extremely convenient to code the subroutine recursively. However, whenever my lattice size grows beyond a certain value (around 200/side), the subroutine consistently segfaults. Here's my cluster-detection routine: RECURSIVE SUBROUTINE growCluster(lattice, adj, idx, area) INTEGER, INTENT(INOUT) :: lattice(:), area INTEGER, INTENT(IN) :: adj(:,:), idx lattice(idx) = -1 area =

Broken recurssive instantiation checks

雨燕双飞 提交于 2019-12-23 19:14:12
问题 I notice that QML has some unspecified problem with the following - when a delegate tries to instantiate an object that contains it (the delegate that is). Consider this trivial tree builder example: // Object.qml Row { property int c : 0 Rectangle { width: 50 height: 50 color: "red" border.color: "black" MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton onClicked: { if (mouse.button === Qt.LeftButton) c++ else if (c) c-- } } } List { model: c } } // List.qml