recursion

Recursion greatest common divisor in MIPS

心已入冬 提交于 2019-12-24 19:32:58
问题 In MIPS, I am trying to calculates the greatest common divisor (GCD) of pairs of positive integer numbers using the Euclidean algorithm. For example, the GCD of 6 and 9 is 3, while the GCD of 10 and 25 is 5. The C code is something like this uint32_t m_w = 50000; uint32_t m_z = 60000; uint32_t hcf(uint32_t n1, uint32_t n2) { if (n2 != 0) return hcf(n2, n1%n2); else return n1; } And I am writing the MIPS program and I am not sure how to use n1 % n2. And this is my first time to do the

python recursive function returning none instead of string

和自甴很熟 提交于 2019-12-24 19:28:48
问题 The below python function prints value using print function but is returning none if made to return string value. can anyone help me on how to return a string value from this below function. csv_full_list = ['mycsv_0', 'mycsv_1'] def create_csv_name(comm, index): global csv_full_list if comm + '_' + str(index) in csv_full_list: index += 1 # increment index by 1 create_csv_name(comm, index=index) else: print '%s_%i' % (comm, index) return '%s_%i' % (comm, index) print(create_csv_name('mycsv',

Factorial Recursive

情到浓时终转凉″ 提交于 2019-12-24 18:52:29
问题 I'm trying to write an algorithm to calculate the factorial of a number using recursive function. This is my code : #include <stdio.h> #include <conio.h> #include <iostream> using namespace std; int factorial(int n) { cin >> n; if (n == 1) return 1; return n*factorial(n - 1); } int main() { int n = 0; cout<<"Enter a number:"; cout << factorial(n); return 0; } It does nothing and I don't know why, it only lets me to give the number, but it's not calculating. 回答1: Inside the factorial function

What the the variables in following program stores?

。_饼干妹妹 提交于 2019-12-24 18:23:33
问题 total_item([],0). total_item([_|Rest],N) :- total_item(Rest,C), N is C+1. This program takes an array as input and count the total number of item in that list. But I am not getting what exactly variable N and C stores. Any explanation would be appreciate. Thank you 回答1: Read it backwards: total_item([], 0). total_item maps 0 to [] ( relates the two). total_item([_ | Rest], N) :- total_item( Rest, C ), N is C + 1 . with C mapped to Rest , C+1 is mapped to [_ | Rest] -- the list one element

Getting CSV values from Javascript object

╄→гoц情女王★ 提交于 2019-12-24 17:52:30
问题 I am trying to convert Javascript object to CSV and store it in to a file.. I have a demo: http://jsbin.com/atewix/8/edit What I want to do is If I give the entity values "Time" or "News" inside function findProps() , It should return CSV in the format: "http://www.testingmyurl.com", Time, Dec 9, 2012 or "http://www.testingmyurl.com",News, Germany,Election "http://www.testingmyurl.com",News,Egypt, Revolution with the current format it returns only individual values and that too as [object

Recusively trying to find file within folder using keyword (VBA-Access)

血红的双手。 提交于 2019-12-24 17:40:23
问题 I am creating an vba-access application with a drop down box Combo_History that gives the user the ability to launch a .pdf file from a sub-folder within a main folder called "Scanned Work Orders (Archives)". What I am trying to do is use a certain number called an "M" number(M number because every number starts with an M ex: M765196) to find this file without using a specific sub folder here is what i have so far: Dim fso, oFolder, oSubfolder, oFile, queue As Collection Set fso =

Sass mixin recursion; @include loop

妖精的绣舞 提交于 2019-12-24 16:23:05
问题 Does anyone know if it's possible to revert Sass's functionality, to prevent the "bug-fix" 1 that was implemented to prevent @include recursion? The message is: Syntax error: An @include loop has been found: <mixin-name> includes itself This was "fixed" 1 in 3.0.5, and I'd prefer not to ( read: I can't ) downgrade that far. I unfortunately don't know enough Ruby to go sifting through the source, and while I'm making time to change that, it doesn't help me now. So, is it possible 2 to revert

Number of ways to fill a nxm grid

南楼画角 提交于 2019-12-24 15:31:37
问题 I encountered the following problem in my programming book which I could not solve: Given a nxm grid, write a recursive algorithm to find the number of ways that this grid could be filled by 3x1 and 1x3 blocks. My logic for 3 x M grids: Find the number of block combinations that could be used to fill side M of the grid. I do not know how to change the logic to solve the question above. Could someone please advise? Thanks. 回答1: Let position be the upper left corner, and thereafter the first

Breaking block into quadrants

百般思念 提交于 2019-12-24 15:22:20
问题 So lets say I have a block that is 10x10, my goal is the break this into quadrants and then once I have done that, go back to the first quadrant and break and into four quadrants, go to the second quadrants and break that into four quadrants and so on until they are all broken and then go back to the first and repeat it for the new set of blocks. So essentially I want to break a block into 4 pieces and break each new block into four pieces and keep going with this pattern. This is the code I

Yield return deferred iteration problems

不想你离开。 提交于 2019-12-24 15:19:06
问题 I know that yield return takes advantage of lazy loading but I'm wondering if I might be misusing the iterator or quite possibly need a refactor. My recursive iterator method returns all the ancestors of a given PageNode including the pageNode itself. public class PageNodeIterator { //properties and constructor left out for brevity public IEnumerable<IPageNode> ancestorsOf(IPageNode pageNode) { if(pageNode == null) throw new ArgumentNullException(("pageNode")); if (pageNode.url !=