I have long running program that I want to keep responsive. The algorithm is recursive, so sometimes even the sub-tasks in longer running calls can be longer than shorter whole runs. I have tried to make it to use yield but only ended up with list full of generators in various levels of recursive list structure (list also multilevel hier...
I recently learned about Recursive Common Table Expressions (CTE's) while looking for a way to build a certain view of some data. After taking a while to write out how the first iteration of my query would work, I turned it into a CTE to watch the whole thing play out. I was surprised to see that grouping didn't work, so I just replaced ...
Hi, Im very stuck. If i have an object which contains a lot of information, different vectors and strings and ints and so on, and in a class i have a collection on those objects, how can i recursivley print the objects information?
Its ahrd for me to post what i have done in terms of workings as the data being used is work data and im ...
Why this query is completed with error ?
;with tempData as
(
select 32 as col1, char(32) as col2
union all
select col1+1, char(col1+1) from tempData
)
select * from tempData
...
I'm trying to write a function that returns a memoized recursive function in Clojure, but I'm having trouble making the recursive function see its own memoized bindings. Is this because there is no var created? Also, why can't I use memoize on the local binding created with let?
This slightly unusual Fibonacci sequence maker that starts...
This function is a CLisp function, this is part of a homework problem, but which is supposed to be written in this different format (the second function).
(defun range (m M) (cond
((> m M) '() )
((= m M) '() )
((< m M) (cons m (range (+ m 1) M ) ) )
)
)
(define (range m M) (cond
((> m M) '() )
((= m M) '() )
((< m M) (co...
rec_fn = lambda: 10==11 or rec_fn()
rec_fn()
I am new to Python and trying to understand how lambda expressions work. Can somebody explain how this recursion is working? I am able to understand that 10==11 will be 'false' and that's how rec_fn will be called again and again recursively.
But what I am not able to get is this seemingly ...
I've been thinking about how type inference works in the following OCaml program:
let rec f x = (g x) + 5
and g x = f (x + 5);;
Granted, the program is quite useless (looping forever), but what about the types?
OCaml says:
val f : int -> int = <fun>
val g : int -> int = <fun>
This would exactly be my intuition, but how does the typ...
Hello,
I have a weird, random problem. Here's a sample of my problematic code. It's purpose is to create a jQuery jCarousel control over a list of ul/li elements. But I need the elements inside to be vertically centered, so I'm calculating a padding-top for each of them once the picture they contain is loaded.
<script type="text/javasc...
This question is largely driven by curiosity, as I do have a working query (it just takes a little longer than I would like).
I have a table with 4 million rows. The only index on this table is an auto-increment BigInt ID. The query is looking for distinct values in one of the columns, but only going back 1 day. Unfortunately, the Re...
How would you code a program in Prolog to print numbers from 1 to 10 using recursion?
I've tried the following but it doesn't work, can you tell me why?
print_numbers(10) :- write(10).
print_numbers(X) :- write(X),nl,X is X + 1, print_numbers(X).
...
Hi,
I have to read in a file that contains a number of coordinates. The file is structured in the following way:
X1/Y1,X2/Y2,X3/Y3,X4/Y4
Where X and Y are positive integers. To solve this problem I want to use a regex (I think this is in general a good idea because of minimal refactoring when the pattern changes).
Therefore I have d...
So, I have a template string with X amount of tokens in it. Hypothetically it could look like this:
template = "render=@layer0@-@layer1@-@layer2@-@layer3@-@layer4@"
The tokens, obviously, take the form of @tokenname@. In this hypothetical case it has five tokens. Each token has a different set of possible values. For example:
token0V...
Let's say we have a User Model that has many Posts.
The Posts Model has many Categories
The Posts Model also has many Comments.
How do we find dynamically, the relationships that the User Model has?
The idea is to make an admin backend to a site, where I can have one function, that when passed a model, can retrieve all data related t...
I read a few other articles on here that looked similar, but didn't quite answer my problem. I've been given a question for an assignment to assign every node in a binary tree its respective depth. I just can't quite get it.
For reference this is my code:
struct treeNode {
int item;
int depth;
treeNode *left;
treeNode *right...
The Problem
I need to write a simple software that, giving certain constraints, appends to a list a series of files.
The user could choose between two "types" of directory: one with a * wildcard meaning it should also explore subdirectories and the classic one without wildcards that just get files present in that directory.
What I'm doi...
Many languages (such as python) have a set maximum recursion depth. I realize you can change that depth, or simply not write recursive functions altogether, but if you do write a recursive function and you hit that maximum recursion depth, how would you prepare for and handle that?
...
Hello,
first i must admit that i'm not very familiar with sql server's recursive CTE's but i think this is the best approach.
I have a table tabData. Its PK is named idData and there is a self referencing FK fiData.
So fiData references the parent record and SELECT * FROM tabData WHERE idData=fiData returns all data of the parent. T...
I was trying to write recursion function,to find factorial of a number.
int factorial(int input,int *answer)
{
if ( input ==0 )
{
return 0;
}
*answer = *answer * input;
factorial(input -1, answer);
}
What will you say about this function? Is it tai...
Hello, I am running into a little pickle. For class I have an assignment (below), I came up with a solution but I keep getting an error, that says;
"'factorial' : recursive on all control paths, function will cause runtime stack overflow;"
If someone could help me, I've been working on this for about an hour and I'm stumped!
Assi...