Search Results

Search found 1553 results on 63 pages for 'tail recursion'.

Page 10/63 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • tail -f in a webbrowser

    - by compie
    I've created a Python script that monitors a logfile for changes (like tail -f) and displays it on a console. I would like to access the output of the Python script in a webbrowser. What would I need to create this? I was thinking about using Django and jQuery. Any tips or examples are greatly appreciated.

    Read the article

  • C# - Determine if class initializaion causes infinite recursion?

    - by John M
    I am working on porting a VB6 application to C# (Winforms 3.5) and while doing so I'm trying to break up the functionality into various classes (ie database class, data validation class, string manipulation class). Right now when I attempt to run the program in Debug mode the program pauses and then crashes with a StackOverFlowException. VS 2008 suggests a infinite recursion cause. I have been trying to trace what might be causing this recursion and right now my only hypothesis is that class initializations (which I do in the header(?) of each class). My thought is this: mainForm initializes classA classA initializes classB classB initializes classA .... Does this make sense or should I be looking elsewhere? UPDATE1 (a code sample): mainForm namespace john { public partial class frmLogin : Form { stringCustom sc = new sc(); stringCustom namespace john { class stringCustom { retrieveValues rv = new retrieveValues(); retrieveValues namespace john { class retrieveValues { stringCustom sc = new stringCustom();

    Read the article

  • recursion tree and binary tree cost calculation

    - by Tony
    Hi all, I've got the following recursion: T(n) = T(n/3) + T(2n/3) + O(n) The height of the tree would be log3/2 of 2. Now the recursion tree for this recurrence is not a complete binary tree. It has missing nodes lower down. This makes sense to me, however I don't understand how the following small omega notation relates to the cost of all leaves in the tree. "... the total cost of all leaves would then be Theta (n^log3/2 of 2) which, since log3/2 of 2 is a constant strictly greater then 1, is small omega(n lg n)." Can someone please help me understand how the Theta(n^log3/2 of 2) becomes small omega(n lg n)?

    Read the article

  • Getting useful emails from Hudson instead of tail of ant log

    - by Rick
    A team member of mine recently setup some Hudson continuous-integration builds for a number of our development code bases. It uses the built in ant integration configured in simple way. While, it is very helpful and I recommend it strongly, I was wondering how to get more more concise/informative/useful emails instead of just the tail of the ant build log. E.G., Don't want this: > [...truncated 36530 lines...] > [junit] Tests run: 32, Failures: 0, Errors: 0, Time elapsed: 0.002 sec ... (hundred of lines omitted) ... > [junit] Tests run: 10, Failures: 0, Errors: 0, Time elapsed: 0.001 sec > [junit] Tests FAILED > > BUILD FAILED I assume, that I could skip the build-in ant support and send the build log through a grep script, but I was hoping there was a more integrated or elegant option.

    Read the article

  • Clojure - tail recursive sieve of Eratosthenes

    - by Konrad Garus
    I have this implementation of the sieve of Eratosthenes in Clojure: (defn sieve [n] (loop [last-tried 2 sift (range 2 (inc n))] (if (or (nil? last-tried) (> last-tried n)) sift (let [filtered (filter #(or (= % last-tried) (< 0 (rem % last-tried))) sift)] (let [next-to-try (first (filter #(> % last-tried) filtered))] (recur next-to-try filtered)))))) For larger n (like 20000) it ends with stack overflow. Why doesn't tail call elimination work here? How to fix it?

    Read the article

  • What does this recursive function do?

    - by null
    What does this function do? And how do you evaluate it? How to trace it? How to understand recursive method? I just can't understand the recursion, and the exam date is coming soon, and I know in order to understand recursion, I must first understand recursion. But I just can't write a slightly complex recursive method, can anyone help me out using the simplest English words. public class BalancedStrings { public static void printBalanced(String prefix, int a, int b) { if (a > 0) printBalanced(prefix + "a", a - 1, b); if (b > 0) printBalanced(prefix + "b", a, b - 1); if (a == 0 && b == 0) System.out.println(prefix); } public static void printBalanced(int n) { if (n % 2 == 0) { printBalanced("", n / 2, n / 2); } } public static void main(String[] args) { printBalanced(4); } }

    Read the article

  • "tail -f" alternate which doesn't scroll the terminal window

    - by Jagtesh Chadha
    I want to check a file at continuous intervals for contents which keep changing. "tail -f" doesn't suffice as the file doesn't grow in size. I could use a simple while loop in bash to the same effect: while [ 1 ]; do cat /proc/acpi/battery/BAT1/state ; sleep 10; done It works, although it has the unwanted effect of scrolling my terminal window. So now I'm wondering, is there a linux/shell command that would display the output of this file without scrolling the terminal?

    Read the article

  • Recursive solution to finding patterns

    - by user2997162
    I was solving a problem on recursion which is to count the total number of consecutive 8's in a number. For example: input: 8801 output: 2 input: 801 output: 0 input: 888 output: 3 input: 88088018 output:4 I am unable to figure out the logic of passing the information to the next recursive call about whether the previous digit was an 8. I do not want the code but I need help with the logic. For an iterative solution, I could have used a flag variable, but in recursion how do I do the work which flag variable does in an iterative solution. Also, it is not a part of any assignment. This just came to my mind because I am trying to practice coding using recursion.

    Read the article

  • Class Decorators, Inheritence, super(), and maximum recursion

    - by jamstooks
    I'm trying to figure out how to use decorators on subclasses that use super(). Since my class decorator creates another subclass a decorated class seems to prevent the use of super() when it changes the className passed to super(className, self). Below is an example: def class_decorator(cls): class _DecoratedClass(cls): def __init__(self): return super(_DecoratedClass, self).__init__() return _DecoratedClass class BaseClass(object): def __init__(self): print "class: %s" % self.__class__.__name__ def print_class(self): print "class: %s" % self.__class__.__name__ bc = BaseClass().print_class() class SubClass(BaseClass): def print_class(self): super(SubClass, self).print_class() sc = SubClass().print_class() @class_decorator class SubClassAgain(BaseClass): def print_class(self): super(SubClassAgain, self).print_class() sca = SubClassAgain() # sca.print_class() # Uncomment for maximum recursion The output should be: class: BaseClass class: BaseClass class: SubClass class: SubClass class: _DecoratedClass Traceback (most recent call last): File "class_decorator_super.py", line 34, in <module> sca.print_class() File "class_decorator_super.py", line 31, in print_class super(SubClassAgain, self).print_class() ... ... RuntimeError: maximum recursion depth exceeded while calling a Python object Does anyone know of a way to not break a subclass that uses super() when using a decorator? Ideally I'd like to reuse a class from time to time and simply decorate it w/out breaking it.

    Read the article

  • Why am I unable to turn off recursion in ISC BIND?

    - by nbolton
    Here's my named.conf.options file: options { directory "/var/cache/bind"; dnssec-enable yes; auth-nxdomain no; # conform to RFC1035 listen-on-v6 { any; }; # disable recursion recursion no; }; I've tried adding allow-recursion { "none"; } before recursion but this also has no effect; I'm testing it by using nslookup on Windows, and using google.com. as the query (and it returns an IP, so I assume recursion is on). This issue occurs on two servers with similar setups.

    Read the article

  • Help me understand Inorder Traversal without using recursion

    - by vito
    I am able to understand preorder traversal without using recursion, but I'm having a hard time with inorder traversal. I just don't seem to get it, perhaps, because I haven't understood the inner working of recursion. This is what I've tried so far: def traverseInorder(node): lifo = Lifo() lifo.push(node) while True: if node is None: break if node.left is not None: lifo.push(node.left) node = node.left continue prev = node while True: if node is None: break print node.value prev = node node = lifo.pop() node = prev if node.right is not None: lifo.push(node.right) node = node.right else: break The inner while-loop just doesn't feel right. Also, some of the elements are getting printed twice; may be I can solve this by checking if that node has been printed before, but that requires another variable, which, again, doesn't feel right. Where am I going wrong? I haven't tried postorder traversal, but I guess it's similar and I will face the same conceptual blockage there, too. Thanks for your time! P.S.: Definitions of Lifo and Node: class Node: def __init__(self, value, left=None, right=None): self.value = value self.left = left self.right = right class Lifo: def __init__(self): self.lifo = () def push(self, data): self.lifo = (data, self.lifo) def pop(self): if len(self.lifo) == 0: return None ret, self.lifo = self.lifo return ret

    Read the article

  • Pascals Triangle by recursion

    - by Olpers
    Note : My Class Teacher gave me this question as an assignment... I am not asked to do it but please tell me how to do it with recursion Binomial coefficients can be calculated using Pascal's triangle: 1 n = 0 1 1 1 2 1 1 3 3 1 1 4 6 4 1 n = 4 Each new level of the triangle has 1's on the ends; the interior numbers are the sums of the two numbers above them. Task: Write a program that includes a recursive function to produce a list of binomial coefficients for the power n using the Pascal's triangle technique. For example, Input = 2 Output = 1 2 1 Input = 4 Output = 1 4 6 4 1 done this So Far but tell me how to do this with recursion... #include<stdio.h> int main() { int length,i,j,k; //Accepting length from user printf("Enter the length of pascal's triangle : "); scanf("%d",&length); //Printing the pascal's triangle for(i=1;i<=length;i++) { for(j=1;j<=length-i;j++) printf(" "); for(k=1;k<i;k++) printf("%d",k); for(k=i;k>=1;k--) printf("%d",k); printf("\n"); } return 0; }

    Read the article

  • Bash edit file and keep last 500 lines

    - by icelizard
    I am looking to create a cron job that opens a directory loops through all the logs i have created and deletes all lines but keep the last 500 for example. I was thinking of something along the lines of tail -n 500 filename filename Would this work? I also not sure how to loop through a directory in bash Thanks in advance.

    Read the article

  • "watching" a log on FreeBSD vs Linux

    - by Cory J
    On Linux systems I can watch -n1 tail /var/log/whatever.log or watch -n1 grep somestuff /var/log/whatever.log To show updates to a log every 1 seconds. On FreeBSD however, the watch command does something else entirely. Who knows a good FreeBSD command for what I'm trying to do? =)

    Read the article

  • List all files and dirs without recursion with junctions

    - by naxa
    Is there a native|portable tool that can give me an unicode (or at least system local-compatible) list of all files and directories under a path recursively, without recursing into junction points or links, in Windows? For example, the built-in dir command, as well as takeown and icacls run into an infinite loop with the Application Data directory (1). EDIT I would like to be able to get a text file or at least easy clipboard transfer as output.

    Read the article

  • Php recursion into multidimensional array

    - by dclowd9901
    I'm trying to write a script that, in its process, would need to be able to write an undefined number of nested arrays, and those arrays need to be able to have custom keys. Essentially, the script is being used to convert an HTML DOM into a multidimensional array. I'm not extremely well versed in recursion, so any pointers would be awesome.

    Read the article

  • Python class decorator and maximum recursion depth exceeded

    - by Michal Lula
    I try define class decorator. I have problem with __init__ method in decorated class. If __init__ method invokes super the RuntimeError maximum recursion depth exceeded is raised. Code example: def decorate(cls): class NewClass(cls): pass return NewClass @decorate class Foo(object): def __init__(self, *args, **kwargs): super(Foo, self).__init__(*args, **kwargs) What I doing wrong? Thanks, Michal

    Read the article

  • What are the pros and cons of using manual list iteration vs recursion through fail

    - by magus
    I come up against this all the time, and I'm never sure which way to attack it. Below are two methods for processing some season facts. What I'm trying to work out is whether to use method 1 or 2, and what are the pros and cons of each, especially large amounts of facts. methodone seems wasteful since the facts are available, why bother building a list of them (especially a large list). This must have memory implications too if the list is large enough ? And it doesn't take advantage of Prolog's natural backtracking feature. methodtwo takes advantage of backtracking to do the recursion for me, and I would guess would be much more memory efficient, but is it good programming practice generally to do this? It's arguably uglier to follow, and might there be any other side effects? One problem I can see is that each time fail is called, we lose the ability to pass anything back to the calling predicate, eg. if it was methodtwo(SeasonResults), since we continually fail the predicate on purpose. So methodtwo would need to assert facts to store state. Presumably(?) method 2 would be faster as it has no (large) list processing to do? I could imagine that if I had a list, then methodone would be the way to go.. or is that always true? Might it make sense in any conditions to assert the list to facts using methodone then process them using method two? Complete madness? But then again, I read that asserting facts is a very 'expensive' business, so list handling might be the way to go, even for large lists? Any thoughts? Or is it sometimes better to use one and not the other, depending on (what) situation? eg. for memory optimisation, use method 2, including asserting facts and, for speed use method 1? season(spring). season(summer). season(autumn). season(winter). % Season handling showseason(Season) :- atom_length(Season, LenSeason), write('Season Length is '), write(LenSeason), nl. % ------------------------------------------------------------- % Method 1 - Findall facts/iterate through the list and process each %-------------------------------------------------------------- % Iterate manually through a season list lenseason([]). lenseason([Season|MoreSeasons]) :- showseason(Season), lenseason(MoreSeasons). % Findall to build a list then iterate until all done methodone :- findall(Season, season(Season), AllSeasons), lenseason(AllSeasons), write('Done'). % ------------------------------------------------------------- % Method 2 - Use fail to force recursion %-------------------------------------------------------------- methodtwo :- % Get one season and show it season(Season), showseason(Season), % Force prolog to backtrack to find another season fail. % No more seasons, we have finished methodtwo :- write('Done').

    Read the article

  • Recursion problem in algorithm

    - by Marthin
    I'm not sure if this is the right place to post this, but the problem actually belongs to a programming assignment. Solve the recursion: T(0) = 2; T(n) = T(n-1) + 2; Solution: T(n) = 2(n+1) Could someone please show me how they got to that solution?

    Read the article

  • python recursive iteration exceeding limit for tree implementation

    - by user3698027
    I'm implementing a tree dynamically in python. I have defined a class like this... class nodeobject(): def __init__(self,presentnode=None,parent=None): self.currentNode = presentnode self.parentNode = parent self.childs = [] I have a function which gets possible childs for every node from a pool def findchildren(node, childs): # No need to write the whole function on how it gets childs Now I have a recursive function that starts with the head node (no parent) and moves down the chain recursively for every node (base case being the last node having no children) def tree(dad,children): for child in children: childobject = nodeobject(child,dad) dad.childs.append(childobject) newchilds = findchildren(child, children) if len(newchilds) == 0: lastchild = nodeobject(newchilds,childobject) childobject.childs.append(lastchild) loopchild = copy.deepcopy(lastchild) while loopchild.parentNode != None: print "last child" else: tree(childobject,newchilds) The tree formation works for certain number of inputs only. Once the pool gets bigger, it results into "MAXIMUM RECURSION DEPTH EXCEEDED" I have tried setting the recursion limit with set.recursionlimit() and it doesn't work. THe program crashes. I want to implement a stack for recursion, can someone please help, I have gone no where even after trying for a long time ?? Also, is there any other way to fix this other than stack ?

    Read the article

  • C++0x: How can I access variadic tuple members by index at runtime?

    - by nonoitall
    I have written the following basic Tuple template: template <typename... T> class Tuple; template <uintptr_t N, typename... T> struct TupleIndexer; template <typename Head, typename... Tail> class Tuple<Head, Tail...> : public Tuple<Tail...> { private: Head element; public: template <uintptr_t N> typename TupleIndexer<N, Head, Tail...>::Type& Get() { return TupleIndexer<N, Head, Tail...>::Get(*this); } uintptr_t GetCount() const { return sizeof...(Tail) + 1; } private: friend struct TupleIndexer<0, Head, Tail...>; }; template <> class Tuple<> { public: uintptr_t GetCount() const { return 0; } }; template <typename Head, typename... Tail> struct TupleIndexer<0, Head, Tail...> { typedef Head& Type; static Type Get(Tuple<Head, Tail...>& tuple) { return tuple.element; } }; template <uintptr_t N, typename Head, typename... Tail> struct TupleIndexer<N, Head, Tail...> { typedef typename TupleIndexer<N - 1, Tail...>::Type Type; static Type Get(Tuple<Head, Tail...>& tuple) { return TupleIndexer<N - 1, Tail...>::Get(*(Tuple<Tail...>*) &tuple); } }; It works just fine, and I can access elements in array-like fashion by using tuple.Get<Index() - but I can only do that if I know the index at compile-time. However, I need to access elements in the tuple by index at runtime, and I won't know at compile-time which index needs to be accessed. Example: int chosenIndex = getUserInput(); cout << "The option you chose was: " << tuple.Get(chosenIndex) << endl; What's the best way to do this?

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >