recursion

Recursively calling asynchronous function that returns a promise

我的梦境 提交于 2020-01-23 17:49:26
问题 I'm trying to recursively call AWS's SNS listEndpointsByPlatformApplication. This returns the first 100 endpoints then a token in NextToken if there are more to return (details: AWS SNS listEndpointsByPlatformApplication). Here's what I've tried: var getEndpoints = function(platformARN, token) { return new models.sequelize.Promise(function(resolve, reject) { var params = { PlatformApplicationArn: platformARNDev }; if (token != null) { params['NextToken'] = token; } sns

Too many pattern matches to write down for Quadtrees?

北慕城南 提交于 2020-01-23 17:04:38
问题 Imagine a quadtree defined as follow: data (Eq a, Show a) => QT a = C a | Q (QT a) (QT a) (QT a) (QT a) deriving (Eq, Show) bad1 = Q u u u u where u = C 255 bad2 = Q (C 0) (C 255) (Q u u u u) (C 64) where u = C 255 The constructor allows you to create not well-formed quadtrees. bad1 should be simply C 255 and bad2 is not valid too because its bottom-right quadtree (for the same reason, it should be Q (C 0) (C 255) (C 244) (C 64) . So far so good. Checking its well-formness is simply a matter

Too many pattern matches to write down for Quadtrees?

邮差的信 提交于 2020-01-23 17:04:18
问题 Imagine a quadtree defined as follow: data (Eq a, Show a) => QT a = C a | Q (QT a) (QT a) (QT a) (QT a) deriving (Eq, Show) bad1 = Q u u u u where u = C 255 bad2 = Q (C 0) (C 255) (Q u u u u) (C 64) where u = C 255 The constructor allows you to create not well-formed quadtrees. bad1 should be simply C 255 and bad2 is not valid too because its bottom-right quadtree (for the same reason, it should be Q (C 0) (C 255) (C 244) (C 64) . So far so good. Checking its well-formness is simply a matter

Find direct and indirect subclasses by scanning filesystem

微笑、不失礼 提交于 2020-01-22 17:42:10
问题 I'm having a problem in writing an algorithm to help me scan a file system and find all subclasses of a certain class. Details: I've an app that scans an external application using nio Files.walk() while retrieving I check for "extends SuperClass" while reading the file if the word exits, I add the class name in my list as follows: List<String> subclasses = new ArrayList<>(); Files.walk(appPath) .filter(p->Files.isRegularFile(p) && p.toString() .endsWith(".java")).forEach(path -> { try { List

Javascript: Find all parents for element in tree

旧巷老猫 提交于 2020-01-22 16:23:29
问题 I have the objects tree, and i can't found all parents for concrete object id. Imagine i need to add some new field to each parent for object with id = 5. Can someone help please with recursive loop through tree var tree = { id: 1, children: [ { id: 3, parentId: 1, children: [ { id: 5, parentId: 3, children: [] } ] } ] } console.log(searchTree (tree, 5)); function searchTree (tree, nodeId){ for (let i = 0; i < tree.length; i++){ if (tree[i].id == nodeId) { // it's parent console.log(tree[i]

Javascript: Find all parents for element in tree

三世轮回 提交于 2020-01-22 16:23:05
问题 I have the objects tree, and i can't found all parents for concrete object id. Imagine i need to add some new field to each parent for object with id = 5. Can someone help please with recursive loop through tree var tree = { id: 1, children: [ { id: 3, parentId: 1, children: [ { id: 5, parentId: 3, children: [] } ] } ] } console.log(searchTree (tree, 5)); function searchTree (tree, nodeId){ for (let i = 0; i < tree.length; i++){ if (tree[i].id == nodeId) { // it's parent console.log(tree[i]

Memoization functor wrapper in c++

南笙酒味 提交于 2020-01-22 14:55:51
问题 Here is a generic memoization wrapper I wrote for functions. It makes use of tuplehash. template<typename R, typename... Args> class memofunc{ typedef R (*func)(Args...); func fun_; unordered_map<tuple<Args...>, R, tuplehash::hash<tuple<Args...> > > map_; public: memofunc(func fu):fun_(fu){} R operator()(Args&&... args){ auto key = make_tuple(std::forward<Args>(args)...); auto q = map_.find(key); if(q == map_.end()){ R res = fun_(std::forward<Args>(args)...); map_.insert({key,res}); return

recursive factorial function

我的梦境 提交于 2020-01-22 09:32:09
问题 how can I combine these two functions in to one recursive function to have this result: factorial(6) 1! = 1 2! = 2 3! = 6 4! = 24 5! = 120 6! = 720 these are the codes def factorial( n ): if n <1: # base case return 1 else: return n * factorial( n - 1 ) # recursive call def fact(n): for i in range(1, n+1 ): print "%2d! = %d" % ( i, factorial( i ) ) fact(6) 1! = 1 2! = 2 3! = 6 4! = 24 5! = 120 6! = 720 as you see execution of these two gives a correct answer, I just want to make it to one

recursive factorial function

此生再无相见时 提交于 2020-01-22 09:32:07
问题 how can I combine these two functions in to one recursive function to have this result: factorial(6) 1! = 1 2! = 2 3! = 6 4! = 24 5! = 120 6! = 720 these are the codes def factorial( n ): if n <1: # base case return 1 else: return n * factorial( n - 1 ) # recursive call def fact(n): for i in range(1, n+1 ): print "%2d! = %d" % ( i, factorial( i ) ) fact(6) 1! = 1 2! = 2 3! = 6 4! = 24 5! = 120 6! = 720 as you see execution of these two gives a correct answer, I just want to make it to one

How do I get all nodes in a parent in JavaFX?

一笑奈何 提交于 2020-01-22 07:28:27
问题 In C# I found a method that was pretty sweet that allowed you to get all the descendants and all of THEIR descendants from a specified control. I'm looking for a similar method for JavaFX. I saw that the Parent class is what I want to work with since it is the class from which all Node classes that bear children are derived. This is what I have so far (and I haven't really found anything on google with searches like "JavaFX get all nodes from a scene"): public static ArrayList<Node>