I am currently learning Recursion with Micheal.T.Goodrich's &quot;Algorithm and DataStructure with Python&quot;. The author suggests a better approach to computing the nth Fibonacci number using recursion without the space complexity of the usual approach. But I just can't wrap my head around the intuition of the program. Can someone explain this:  Normal Recursive function to find nth Fibonacci number  def Fibonacci(n):     if n &lt; = 1:        return (n)     else:        return Fibonacci(n - 1) + Fibonacci (n - 2)           Optimized solution:  def Fibonnaci(n):     if n &lt;= 1:        return (n, 0)     else:        (a, b) = Fibonacci(n - 1)        return (a+b, a)  Can someone help me in understanding the optimized solution?
I had originally coded the program wrongly. Instead of returning the Fibonacci numbers between a range (ie. startNumber 1, endNumber 20 should = only those numbers between 1 &amp; 20), I have written for the program to display all Fibonacci numbers between a range (ie. startNumber 1, endNumber 20 displays = First 20 Fibonacci numbers). I thought I had a sure-fire code. I also do not see why this is happening.  startNumber = int(raw_input("Enter the start number here ")) endNumber = int(raw_input("Enter the end number here "))  def fib(n):     if n &lt; 2:         return n     return fib(n-2) + fib(n-1)  print map(fib, range(startNumber, endNumber))   Someone pointed out in my Part II (which was closed for being a duplicate - ) that I need to pass the startNumber and endNumber through a generator using a while loop. Can someone please point me in the direction on how to do this? Any help is welcome.    I'm a learning programmer and I've run into a bit of a jumble. I am asked to write a program that will compute and display Fibonacci's Sequence by a user inputted start number and end number (ie. startNumber = 20 endNumber = 100 and it will display only the numbers between that range). The trick is to use it inclusively (which I do not know how to do in Python? - I'm assuming this means to use an inclusive range?).  What I have so far is no actual coding but rather:   Write Fib sequence formula to infinite Display startNumber to endNumber only from Fib sequence.   I have no idea where to start and I am asking for ideas or insight into how to write this. I also have tried to write the Fib sequence forumla but I get lost on that as well.
Even when /tmp has no file called something, searching for it with find will return 0:    $ find /tmp -name something    $ echo $?   0   How can I get a non-zero exit status when find does not find anything? How can I better optimize my tables and a LEFT JOIN query to find items that don't yet exist in the right table? I have two tables that represent a list of urls and their related word indexes. Here are the table definitions for reference.  desc urllist; +-------+---------------------+------+-----+---------+----------------+ | Field | Type                | Null | Key | Default | Extra          | +-------+---------------------+------+-----+---------+----------------+ | id    | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment | | url   | text                | NO   |     | NULL    |                | +-------+---------------------+------+-----+---------+----------------+   and  desc wordlocation; +----------+---------------------+------+-----+---------+-------+ | Field    | Type                | Null | Key | Default | Extra | +----------+---------------------+------+-----+---------+-------+ | urlid    | bigint(20) unsigned | NO   |     | NULL    |       | | wordid   | bigint(20) unsigned | NO   |     | NULL    |       | | location | int(10) unsigned    | NO   |     | NULL    |       | +----------+---------------------+------+-----+---------+-------+   The software app is a web spider. It crawls a list of urls, extracts those urls, and inserts these into the urllist table. Then, an indexer checks to see what urls have not yet been indexed, and then proceeds to index said urls.  Here is the query I am using to find items in the left table (urllist) that have not yet been indexed in the right table (wordlocation). This query is as suggested on the :  select * from urllist ul  left join wordlocation wl on ul.id = wl.urlid  where wl.urlid IS NULL;   As of this writing my test database has only 600 indexed urls, and the wordlocation table has 1.3 million rows.  However, my CPU is at 100%, and the longest I've waited to see if the query would complete is a half hour (which, it never did by the way).  To be thorough, here is the explanation of the query:  explain select * from urllist ul left join wordlocation wl on ul.id = wl.urlid where wl.urlid IS NULL; +----+-------------+-------+------+---------------+------+---------+------+---------+-------------------------+ | id | select_type | table | type | possible_keys | key  | key_len | ref  | rows    | Extra                   | +----+-------------+-------+------+---------------+------+---------+------+---------+-------------------------+ |  1 | SIMPLE      | ul    | ALL  | NULL          | NULL | NULL    | NULL |   50364 |                         | |  1 | SIMPLE      | wl    | ALL  | NULL          | NULL | NULL    | NULL | 1351371 | Using where; Not exists | +----+-------------+-------+------+---------------+------+---------+------+---------+-------------------------+   I need this query to finish in seconds, not minutes. Also, I'm worried about scalability. I have 40,000 unique urls that are waiting to be added to the index, so how do I take that into consideration with my table and query design? 400,000 urls?  Just a couple notes about my decisions on the current table structure.  I have no intention of stopping at 400,000 urls, but perhaps bigint(20) is a bit overzealous?   Url as text is for more practical reasons. I index a lot of Asian and other foreign language domains which do not appear as their equivalent Kanji or other characters in the database and frequently take more than 255 characters.  I'm using MySQL. I'm definitely open to suggestions as to better table and query design. Please let me know if I can provide more information. TeXShop and Mac preview crashing when opening latex/beamer built pdfs After updating to Sierra 10.12.4 last week, TeXShop crashes:   when opening an existing .tex document that has a pdf associated to it immediately after compiling a new document, i.e. as soon as a pdf is created.   Furthermore, preview crashes opening almost any pdf that has been created with TeXShop. There is virtually nothing on the internet about it, and the only solution seems to be a complete reinstall of MacOSX (so as to reinstall the supposedly broken preview), which I'd like to avoid if at all possible.  Someone else has described a similar issue, but has not received any responses ().  I would be very grateful for some help, as I can neither produce work, nor look at any at the moment. Many thanks! Is there a way to make IE8 honour opacity on an `:before` pseudo element? I'm trying to simulate a media key press using a custom shortcut.  So far, I've been able to achieve the simulation I need using the command:  xdotool key XF86AudioPlay   It works perfectly, it pauses or starts the music player every time it is run.  The problem comes when trying to run it as a shortcut.  First I tried to run an alias with a custom shortcut, but it did not work.  As explained on :     The commands run by keyboard bindings are not parsed via a shell. Your best bet is to create a directory bin in your homedir.   Next I created the suggested script and named it simplay:  #!/bin/sh xdotool key XF86AudioPlay   It is located inside a bin folder which is part of the PATH, this works fine and can be run from any location.  When trying to create the Custom Shortcut, I was unable to get it to execute, the configuration is the following:  Name: test Command: simplay  Shortcut: Ctrl+Alt+R   After searching a bit more I found another way to execute the shortcut:  gnome-terminal -e simplay   I tried it on a terminal and noticed that when executing it it would rapidly open a new terminal window, execute the child process, pausing the music and immediately close the window.  I changed the command on the shortcut and when hitting it I noticed the same behavior opening a terminal and immediately being closed but this time the child process did not pause the music, which makes me think that the script has been called on all my previous attempts but it is somehow not being able to execute.  How can I solve this problem according to your knowledge? Show that every prime $p>3$ is either of the form $6n+1$ or of the form $6n+5$ Show that every prime $p&gt;3$ is either of the form $6n+1$ or of the form $6n+5$, where $n=0,1,2, \dots$ Object not visible in render I have a model which you can see here (camera perspective).    In the second image, you can see how the render turned out.    I'm at my wit's end trying to figure our why it's not showing up in the render. If anyone needs more information, just ask and I'll get it to you. I've already checked the normals and they're not the cause. Prove that $(n-1)! \equiv -1 \pmod{n}$ iff $n$ is prime [Wilson's Theorem] How can I show that $(n-1)!\equiv-1 \pmod{n}$ if and only if $n$ is prime? Thanks. How does temperature relate to the kinetic energy of molecules? In ideal gas model,  is the measure of average kinetic energy of the gas molecules. If by some means the gas particles are accelerated to a very high speed in one direction, KE certainly increased, can we say the gas becomes hotter? Do we need to distinguish the random vibration KE and KE in one direction?  Furthermore, if we accelerate a block of metal with ultrasonic vibrator so that the metal is vibrating in very high speed with cyclic motion, can we say the metal is hot when it is moving but suddenly become much cooler when the vibration stop? What year is the series "Chilling Adventures of Sabrina" supposedly set in? Almost everything in Greendale seems to be vintage 1960's (cars, movies, dress). I assume it is to reflect the original comic book, but I swear I saw Ambrose using a laptop computer in the first episode. Was this just to make it more topical? Or is it some kind of alternate reality? How to animate only the camera? So  i have a scene with a few objects, and a water simulation in the scene. However I want to animate the camera turning around in the scene, while the water simulation is frozen in time. So something like a time freeze effect. But when ever I try to render an animation it renders the water simulation too. I just need one frame of the water simulation. Is there a way to do this? Interior of closure of open set in topological space If $U$ is an open set in a topological space, is it true that $U$ is the interior of the closure of itself?   If $U$ is open, it must be the interior of itself. But is it the interior of the closure of itself? In the closure, we include all points $x$ such that any open set containing $x$ also contains a point in $U$. In the interior of the closure, we take the union of all open sets contained in the closure. I am trying to run a buffer tool as part of script that I will both use as a standalone script and import into ArcToolbox. I'm just wondering, if I use GetParameterAsText for the buffer distance, how do I set the linear units? E.g. I want it preset so they only have to type 300 and the script takes that to be meters? Here is what I have so far:  # Buffer the Thames feature class to create the Flood Risk Area in_features = "Thames" out_feature_class = "Flood_R_A" # Run the Buffer Tool arcpy.Buffer_analysis (in_features, out_feature_class, arcpy.GetParameterAsText(5),    "FULL", "ROUND", "ALL", "") What is the opposite of "preaching to the choir"? Calculating the expected values of the min/max of 2 random variables On Mac, are there keyboard shortcuts to create a new Space? Or at least any way to automate this process with keyboard shortcuts? I want to not have to use the mouse to create Spaces. I want to use the keyboard for that. Most efficient way to convert an HTMLCollection to an Array Is there a more efficient way to convert an HTMLCollection to an Array, other than iterating through the contents of said collection and manually pushing each item into an array? Calling C/C++ from Python? What would be the quickest way to construct a Python binding to a C or C++ library?  (I am using Windows if this matters.) Sort lines based on a variable-width number at a fixed position Exeception on After Insert, Record is read only I'm writing a trigger for new opportunity products to populate  a field Product_Category__c (on opportunity lineitem) getting the value from Product_Category_new__c (on Product).  This is my trigger:  trigger SetProductCategory on OpportunityLineItem (after insert) {      for (OpportunityLineItem opplineitem: Trigger.new) {                    opplineitem.Product_Category__c =  opplineitem.PricebookEntry.Product2.Product_Category_new__c;     }      }   I get this error message:     execution of AfterInsert caused by: System.FinalException: Record is read-only   I have tried with before insert;in this case there aren't errors but the value Product category it's not saved on Opportunity Line item.  I have found that:  In a after insert trigger is not allowed change field using trigger.new  Please can you suggest a solution for this? i would like to copy the value Product category (Product) on Product Category (Opportunity Product)  after the insert of the new opportunity products.  Thanks in advantage for any advice.  Br