recursion

recursive folder reading with java.io.File

大憨熊 提交于 2021-01-28 17:47:45
问题 Currently I create a list of sub folders with this function: % create list of all sub folders dirs = regexp(genpath(basePath),['[^;]*'],'match'); My folders contain however > 100 000 files. This function takes minutes to hours to complete. The number of folders however is only < 100. I read that java.io.File is magnitudes faster. However how can I use it to read folders recursive? jFile = java.io.File([basePath '*']); %java file object jPaths = jFile.listFiles; %java.io.File objects jNames =

recursive folder reading with java.io.File

送分小仙女□ 提交于 2021-01-28 17:45:07
问题 Currently I create a list of sub folders with this function: % create list of all sub folders dirs = regexp(genpath(basePath),['[^;]*'],'match'); My folders contain however > 100 000 files. This function takes minutes to hours to complete. The number of folders however is only < 100. I read that java.io.File is magnitudes faster. However how can I use it to read folders recursive? jFile = java.io.File([basePath '*']); %java file object jPaths = jFile.listFiles; %java.io.File objects jNames =

What is the Definition of Recursion

流过昼夜 提交于 2021-01-28 13:53:15
问题 So, we all know recursive functions, right? But what exactly is it, that makes a function recursive? I had a small discussion in the comment section of another question (Lightening effect with javascript) that kind of challenged my view of recursive functions but it also left me with a quite unsatisfying lack of proper definition. My personal definition of recursive functions so far was the following: A function is recursive if it directly or indirectly invokes itself Note: I will provide

VBScript - Retrieving a user's nested groups and getting rid of repetitions

一笑奈何 提交于 2021-01-28 12:13:47
问题 For my work, I have to write a script in VBScript that retrieves a list of ALL groups a user belongs to, including nested groups, and take out nested groups that would be repeated throughout the list (as well as indent nested groups, further indent nested groups of nested groups, etc.) I found a script that fetches the entire list of groups a user belongs to by Monimoy Sanyal on gallery.technet.microsoft.com, and tried to adapt it to my needs. Here is the script as edited by me: Option

Scheme: Is it possible to convert a list of S-expressions into a list of atoms?

*爱你&永不变心* 提交于 2021-01-28 11:26:14
问题 I am trying to convert a list of S-expressions to a plain list of atoms similar to a problem in the book The Little Schemer . My code is (as typed in Dr.Racket): > (define lat '((coffee) cup ((tea) cup) (and (hick)) cup)) > (define f (lambda (lat) (cond ((null? lat) (quote ())) ((atom? (car lat)) (cons (car lat) (f (cdr lat)))) (else (cons (f (car lat)) (f (cdr lat))))))) > (f lat) '((coffee) cup ((tea) cup) (and (hick)) cup) The above code is returning back the list the same as input list. I

Handle self-references when flattening dictionary

谁说我不能喝 提交于 2021-01-28 10:53:52
问题 Given some arbitrary dictionary mydict = { 'first': { 'second': { 'third': { 'fourth': 'the end' } } } } I've written a small routine to flatten it in the process of writing an answer to another question. def recursive_flatten(mydict): d = {} for k, v in mydict.items(): if isinstance(v, dict): for k2, v2 in recursive_flatten(v).items(): d[k + '.' + k2] = v2 else: d[k] = v return d It works, giving me what I want: new_dict = recursive_flatten(mydict) print(new_dict) {'first.second.third.fourth

Is there a reason for the child to not to print until the parent process finishes printing?

大兔子大兔子 提交于 2021-01-28 10:48:00
问题 #include <stdio.h> #include <unistd.h> int do_fork(int depth) { if (!depth) { return fork(); } int val = do_fork(depth - 1); printf("%d\n", val); return val; } int main() { int val; scanf("%d", &val); do_fork(val); } I tried this code several times, with several different values on several different machines. It doesn't matter how big the number is, I always see the pid of the child printed one next to the other with no zeros in between. Only when the pids are all printed, the child starts

C# Create HTML unordered list from List using Recursion

我与影子孤独终老i 提交于 2021-01-28 10:17:10
问题 Is it possible to output the following HTML unordered list using recursion. <ul> <li>1 <ul> <li>5 <ul> <li>8</li> <li>9</li> </ul> </li> <li>6</li> </ul> </li> <li>2</li> <li>3</li> <li>4</li> <li>7</li> </ul> Where the original data is is held in the following list List<Page> pages = new List<Page>(); pages.Add(new Page { Id = 1, pageId = 1, parentPageId = 0 }); pages.Add(new Page { Id = 2, pageId = 2, parentPageId = 0 }); pages.Add(new Page { Id = 3, pageId = 3, parentPageId = 0 }); pages

How do I find path using 2d array maze in java

我只是一个虾纸丫 提交于 2021-01-28 09:44:48
问题 B B B B B B B B O B B B S O B B O O B B B B X B B Here, S = Start Point(2,2) B = Block O = Open X = Exit I want to make a maze that will check north, west, east and south. if X is around it will return the program. If not, then check for any 'O' around the start point and pass the new start point recursively. It there is no way to go and 'X' is not found it will go back to the original start point(2,2) and check west, east and south. after the program, i got: B B B B B B B B + B B B + + B B O

How Is This Recursive Function Changing The 'history' Variable? [duplicate]

点点圈 提交于 2021-01-28 09:41:57
问题 This question already has answers here : How does this recursion work? (11 answers) Closed 25 days ago . I feel so close to figuring this out, but I can't quite understand this function.. I get how the function keeps checking for the target number and if it gets too high, it returns null and the second '||' operator is applied. What I do not understand is, once the current variable is higher than the target variable, it will start returning the history variable but without an additional (+5).