recursion

Recursive graph traversal: how to generate and return all paths?

一个人想着一个人 提交于 2020-01-06 13:59:10
问题 Here is my code right now: hasht= {"A":["B", "D", "E"], "B":["C"], "C":["D", "E"], "D":["C", "E"], "E":["B"]} paths=[] def recusive(start, finish, val): if start==finish and val!=1: return start else: for i in hasht[start]: path= start+ recusive(i,finish,2) paths.append(path) print (recusive("C","C",1)) print paths Desired output: [CDC, CDEBC, CEBC] I am trying to generate a table like the one above, but I am running into a problem where the string and the array are not being concatenated.

user control controling containing form

∥☆過路亽.° 提交于 2020-01-06 12:43:28
问题 I am using vb.net winforms to create an application which contains a user control, I am also authoring the user control. The user control is named activate1 The form containing the usercontrol (and other content) is named form1 currently I am trying to enable a button on form1 when a maskedtextbox on activate1 is completed I attempted to do this by: Private Sub MaskedTextBox1_TextChanged(sender As Object, e As EventArgs) Handles MaskedTextBox1.TextChanged If MaskedTextBox1.Text.Count = 34

How to recursively build a tree of unknown depth in R

点点圈 提交于 2020-01-06 11:10:56
问题 I am trying to store scraped media comment data obtained via RSelenium, XML and JSON into a tree using Christoph Gluc's data.tree package in R. The problem I am facing is that I do not know beforehand the depth of the tree because of the way some of the comments are posted. The primary site is Disqus where people commenting might comment on the article, reply to other people's comments with yet other people replying to comments directly. Thus the depth of the comments is not known. My data is

javascript parse tree

天大地大妈咪最大 提交于 2020-01-06 10:54:08
问题 i'm writing a plugin in jquery to be a file manager i build my folder structure in php i call that php file using ajax and i return something like this {"1":[],"css":{"admin":[],"tabs":{"skin1":{"images":[]},"skin10":{"images":[]},"skin11":{"images":[]},"skin12":{"images":[]},"skin2":[],"skin3":{"images":[]},"skin4":{"images":[]},"skin5":{"images":[]},"skin6":{"images":[]},"skin7":{"images":[]},"skin8":{"images":[]},"skin9":{"images":[]}}},"img":{"admin":[],"filemanager":[],"icons":[]},"js":{

Recursive Fibonacci Function (With Negative Numbers)

给你一囗甜甜゛ 提交于 2020-01-06 09:16:16
问题 I am able to write a recursive Fibonacci function for all numbers greater than 0, but the function is completely incorrect for anything negative. Any idea how to implement this in c++? int fibonacci(int n){ if(n == 0)return 0; if(n == 1)return 1; return fibonacci(n - 1) + fibonacci(n - 2); } 回答1: According to wikipedia, http://en.wikipedia.org/wiki/Generalizations_of_Fibonacci_numbers, the recursive function for negative numbers is different than for possitive numbers. For possitive: n_2 = n

Recursive Fibonacci Function (With Negative Numbers)

点点圈 提交于 2020-01-06 09:10:08
问题 I am able to write a recursive Fibonacci function for all numbers greater than 0, but the function is completely incorrect for anything negative. Any idea how to implement this in c++? int fibonacci(int n){ if(n == 0)return 0; if(n == 1)return 1; return fibonacci(n - 1) + fibonacci(n - 2); } 回答1: According to wikipedia, http://en.wikipedia.org/wiki/Generalizations_of_Fibonacci_numbers, the recursive function for negative numbers is different than for possitive numbers. For possitive: n_2 = n

what can I do to optimize the following function or some other thing to reduce memory consumption?

别说谁变了你拦得住时间么 提交于 2020-01-06 09:06:05
问题 I am working on business directory sort of thing, and need to show recursive parents of categories at category listing. I am using following function for that: public function get_recursive_parents($category_id){ $categories = array(); $res = $this->db->from('categories')->where('cat_id',$category_id)->get()->row_array(); $cat_id = $res['parent_id']; $categories[] = $res; while($cat_id){ $res = $this->db->from('categories')->where('cat_id',$cat_id)->get()->row_array(); $categories[] = $res;

Comparing Objects and Pulling Out Deep Diff

点点圈 提交于 2020-01-06 08:35:06
问题 In my Node/MongoDB back-end I am doing some post-processing to generate notes when something changes in a record. So the first step is to get a pre and post update version of the record. Then I want to compare the two to identify the part of the record that changed. The solution I have below works - but it returns the root level property containing the change. I need something more granular than this - as I have an array -- "history", embedded within the root level element, also an array --

My recursive mutex vs pthread_mutex_t (type: recursive) (repost, push)

≯℡__Kan透↙ 提交于 2020-01-06 08:21:21
问题 I was wondering if I could make a recursive mutex type on my own with a PTHREAD_MUTEX_ERRORCHECK mutex, this is the result: typedef struct { pthread_mutex_t mutex; uint32_t deadlocks; } pthread_recursivemutex_t; int pthread_recursivemutex_init(pthread_recursivemutex_t *mutex) { int ret; pthread_mutexattr_t attr; mutex->deadlocks = 0; ret = pthread_mutexattr_init(&attr); if (ret != 0) { return ret; } (void)pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); ret = pthread_mutex_init(

Appending a List and Recursion (Hamming Distance) - Python 3

五迷三道 提交于 2020-01-06 08:14:24
问题 I'm supposed to write a program that takes a string of binary code and a number, and outputs all the strings within that hamming distance of the original string. I have a function that does everything, but in the output there are lists within lists. I understand why this is - the function is recursive, and sometimes it will return a list of possible values. The problem is, I don't know how to change it so it outputs complete strings. For example, for a string of "0000" and hamming distance "2