recursion

Creating Group for multiple columns with multiple duplicates

雨燕双飞 提交于 2021-02-11 14:41:52
问题 The below table contains details of members and their policies. We need to form a group of 2 or more members if they have at least one policy in common. Member_ID Policy 101 X1 103 Y2 104 Z1 101 Y1 102 X1 101 X3 103 Z1 101 X2 102 Y3 105 Y1 Required result: GROUP Member_ID Policy 1 101 X1 1 101 X2 1 101 X3 1 101 Y1 1 102 X1 1 102 Y3 1 105 Y1 2 103 Y2 2 103 Z1 2 104 Z1 回答1: What you describe is a graph-walking algorithm. This is complicated because you may need to traverse multiple levels. For

How can I load all child records recursively?

折月煮酒 提交于 2021-02-11 14:24:58
问题 I have this Project class: public class Project { public int Id { get; set; } public int? ParentId { get; set; } public List<Project> ChildProjects { get; set; } // more properties } This is my attempt to load all descendants of any given project: private async Task<List<Project>> LoadDescendantsOf(Project project) { project.ChildProjects = await db.Projects .Where(p => p.ParentId == project.Id) .ToListAsync(); foreach (Project childProject in project.ChildProjects) { yield return

List Recursion in Ocaml

ε祈祈猫儿з 提交于 2021-02-11 14:01:47
问题 This is what I want to achive, to return to a list with values that are below the given value with recursion : # list_below 3 [7; 1; 0; 3];; - : int list = [1; 0] # list_below 1 [-7; 1; 0; 3];; - : int list = [-7; 0] # list_below 9.0 [4.2; 3.6; 5.0; 12.8];; - : float list = [4.2; 3.6; 5.0] Here is what I wrote so far, and it does not appear to return anything. let rec list_below thresh lst = if List.hd lst > thresh then [] else List.hd lst :: list_below thresh (List.tl lst);; ;; Could you

recursion: storage of multiple values in variables

有些话、适合烂在心里 提交于 2021-02-11 14:00:52
问题 Code shows a recursive function that takes a number, say n=5, and returns an array counting down from n to 1 i.e [5,4,3,2,1]. My confusion lies right before we push the numbers/values of n to countArray . My understanding is that countup(n - 1) , will generate numbers (say n=5) 5,4,3,2,1...but I don't understand where/how they are stored. I would have thought n would end up as its last defined value, n=1, or a blank array. But that's not true and they are somehow all pushed into an array that

Find element in collection of collection elements [closed]

狂风中的少年 提交于 2021-02-11 13:28:52
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 months ago . Improve this question Good time of the day! Please tell me how to implement the following search correctly. There are collection of elments like: class Item { int itemId; List<Item> items; } How to determine exists an element with the specified itemId in one of the collections

Recursion optimization

拈花ヽ惹草 提交于 2021-02-11 13:18:18
问题 I'm trying to find a certain path through my 2d array My array could look like this: temp = [ ["placeholder", 2, 0], ["placeholder", 1, 7, 3], ["placeholder", 4, 5, 8], ["placeholder", 6, 3, 5, 2], ["placeholder", 7], ["placeholder", 3, 0], ] The inner arrays contain a placeholder followed by a variable amount of integers. These integers range in value between 0-19 (0 and 19 both included) I wanna find a path from top to bottom through these inner arrays where no number is used more than once

C recursive function to calculate Factorial

吃可爱长大的小学妹 提交于 2021-02-11 12:15:26
问题 Im just beginning to learn C programming and figured i would start out at a pretty basic problem of calculating the factorial of a number. My code outputs the correct value up until the factorial of 13 and then gives me the wrong answer for when the input is >13. My code is: #include<stdio.h> long int factorial(int); int main() { int num; long int fact; printf("Please type the number you want factoralized: "); scanf("%d",&num); fact = factorial(num); printf("%d",fact); return 0; } long int

Recursively calculate e^x with Java using MacLaurin Series

强颜欢笑 提交于 2021-02-11 10:02:55
问题 I need to write a recursive java method that will compute e^x called e(x,n) with the signature, public static double eThree(double x, long n) and it must use the MacLaurin series to compute e^x, which is the following observation: 1 + x(1 + x/2( 1 + x/3(1 + x/4(1 + ... )))) e(x,0)= 1 A call to this would return a result of 1 With some help earlier, I was able to make one that didn't require this format, but I'm not sure what I would code in order to use the format above. Thanks guys, really

Recursively calculate e^x with Java using MacLaurin Series

谁说胖子不能爱 提交于 2021-02-11 10:02:41
问题 I need to write a recursive java method that will compute e^x called e(x,n) with the signature, public static double eThree(double x, long n) and it must use the MacLaurin series to compute e^x, which is the following observation: 1 + x(1 + x/2( 1 + x/3(1 + x/4(1 + ... )))) e(x,0)= 1 A call to this would return a result of 1 With some help earlier, I was able to make one that didn't require this format, but I'm not sure what I would code in order to use the format above. Thanks guys, really

Recursively calculate e^x with Java using MacLaurin Series

╄→гoц情女王★ 提交于 2021-02-11 10:02:08
问题 I need to write a recursive java method that will compute e^x called e(x,n) with the signature, public static double eThree(double x, long n) and it must use the MacLaurin series to compute e^x, which is the following observation: 1 + x(1 + x/2( 1 + x/3(1 + x/4(1 + ... )))) e(x,0)= 1 A call to this would return a result of 1 With some help earlier, I was able to make one that didn't require this format, but I'm not sure what I would code in order to use the format above. Thanks guys, really