recursion

Async Await Recursion in .NET 4.8 causes StackoverflowException (not in .Net Core 3.1!)

半世苍凉 提交于 2020-04-10 14:48:27
问题 Why does the following code cause a StackOverflowException in .Net4.8 with only a 17-depth recursion? However this does not happen in NetCore 3.1 (I can set the count to 10_000 and it still works) class Program { static async Task Main(string[] args) { try { await TestAsync(17); } catch(Exception e) { Console.WriteLine("Exception caught: " + e); } } static async Task TestAsync(int count) { await Task.Run(() => { if (count <= 0) throw new Exception("ex"); }); Console.WriteLine(count); await

Python - using a shared variable in a recursive function

流过昼夜 提交于 2020-04-08 09:42:07
问题 I'm using a recursive function to sort a list in Python, and I want to keep track of the number of sorts/merges as the function continues. However, when I declare/initialize the variable inside the function, it becomes a local variable inside each successive call of the function. If I declare the variable outside the function, the function thinks it doesn't exist (i.e. has no access to it). How can I share this value across different calls of the function? I tried to use the "global" variable

python - recursively deleting dict keys?

|▌冷眼眸甩不掉的悲伤 提交于 2020-04-08 07:09:11
问题 I'm using Python 2.7 with plistlib to import a .plist in a nested dict/array form, then look for a particular key and delete it wherever I see it. When it comes to the actual files we're working with in the office, I already know where to find the values -- but I wrote my script with the idea that I didn't, in the hopes that I wouldn't have to make changes in the future if the file structure changes or we need to do likewise to other similar files. Unfortunately I seem to be trying to modify

python - recursively deleting dict keys?

大城市里の小女人 提交于 2020-04-08 07:07:12
问题 I'm using Python 2.7 with plistlib to import a .plist in a nested dict/array form, then look for a particular key and delete it wherever I see it. When it comes to the actual files we're working with in the office, I already know where to find the values -- but I wrote my script with the idea that I didn't, in the hopes that I wouldn't have to make changes in the future if the file structure changes or we need to do likewise to other similar files. Unfortunately I seem to be trying to modify

Prolog: Splitting a number into a sequence of increasing integers

南楼画角 提交于 2020-04-07 07:08:08
问题 After doing some Prolog in uni and doing some exercises I decided to go along somewhat further although I got to admit I don't understand recursion that well, I get the concept and idea but how to code it, is still a question for me. So that's why I was curious if anyone knows how to help tackle this problem. The idea is given a number e.g. 45, check whether it is possible to make a list starting with 1 going n+1 into the list and if the sum of the list is the same as the given number. So for

Prolog: Splitting a number into a sequence of increasing integers

你离开我真会死。 提交于 2020-04-07 07:07:30
问题 After doing some Prolog in uni and doing some exercises I decided to go along somewhat further although I got to admit I don't understand recursion that well, I get the concept and idea but how to code it, is still a question for me. So that's why I was curious if anyone knows how to help tackle this problem. The idea is given a number e.g. 45, check whether it is possible to make a list starting with 1 going n+1 into the list and if the sum of the list is the same as the given number. So for

How to obtain a master structure for a json file?

懵懂的女人 提交于 2020-04-07 01:21:47
问题 I have a JSON file as follows: [ { "dog": "lmn", "tiger": [ { "bengoltiger": { "height": { "x": 4 } }, "indiantiger": { "paw": "a", "foor": "b" } }, { "bengoltiger": { "width": { "a": 8 } }, "indiantiger": { "b": 3 } } ] }, { "dog": "pqr", "tiger": [ { "bengoltiger": { "width": { "m": 3 } }, "indiantiger": { "paw": "a", "foor": "b" } }, { "bengoltiger": { "height": { "n": 8 } }, "indiantiger": { "b": 3 } } ], "lion": 90 } ] I want to transform this to obtain all possible properties of any

Recursively look for files with a specific extension

旧城冷巷雨未停 提交于 2020-03-30 05:07:33
问题 I'm trying to find all files with a specific extension in a directory and its subdirectories with my bash (Latest Ubuntu LTS Release). This is what's written in a script file: #!/bin/bash directory="/home/flip/Desktop" suffix="in" browsefolders () for i in "$1"/*; do echo "dir :$directory" echo "filename: $i" # echo ${i#*.} extension=`echo "$i" | cut -d'.' -f2` echo "Erweiterung $extension" if [ -f "$i" ]; then if [ $extension == $suffix ]; then echo "$i ends with $in" else echo "$i does NOT

How scheme code usually deal with cycles in list processing recursive functions?

自作多情 提交于 2020-03-28 06:39:48
问题 My question was marked as duplicate, and closed How to deal with cycles in recursive functions in scheme? I'm asking again: I have this code: (define x (list 1 2 3)) (set-cdr! (cddr x) x) (define (list? x) (and (pair? x) (or (null? (cdr x)) (list? (cdr x))))) (display (list? x)) (newline) and function list? freezes when it find cycle (because it's infinite loop). How scheme code usually work with cycles like that? I'm not asking how to detect cycles. I'm asking: how this is done in scheme

Trouble implementing a recursive call in C

℡╲_俬逩灬. 提交于 2020-03-28 03:30:21
问题 So I'm I've been working with C for the very first time, and I think I'm having trouble using recursion. For instance, to return a value for a recursive call in C#, I might use return methodRecursiveCall(parameter) . In C, I have this statement, which is a part of a roman numeral converter: int convert(char *s) { int val = 0; int index = 0; int length = strlen(s); while (length >1) { if (s[index] == 'I') { if(s[index + 1] == 'V' || s[index + 1] == 'X' || s[index + 1] == 'C' || s[index + 1] ==