So I actually posted this in the C# section, but despite peoples best efforts, all all the help there, the problem is still not solved. Background: Im making a game in xna/c# (Who isnt these days). For collision detection, I though I would use rectangles and lists. My thought process was: 1. Load collision map file 2. Parse file, where there is a 1, create a rectangle and add to list 3. In the player class, iterate through the list of rectangles (I called the list 'badTiles') 4. If the player intersects one of the rectangles, prevent them from moving, …

Member Avatar
Member Avatar
+0 forum 3

Following up on a discussion on [this thread](http://www.daniweb.com/software-development/cpp/threads/470519/looping-using-recursion/), I did some tests on the performance of recursion vs. iteration, and some interesting things happened, so I thought I would share the results. I'm gonna structure this a bit like a lab-report, because that's really the best way to put it. But I hope the discussion can continue on additional ideas or insight into the performance issues that are discussed here, or if you disagree with my analysis. ## Experimental Method ## So, I took Schol-R-LEA's coin-combination example as a test case, and timed the execution of three different versions: recursive, …

Member Avatar
Member Avatar
+4 forum 6

hi all, how to do multiplication matrix with iteration and stop iteration if value >= 5? $data = array( array(1,-0.52836), array(-0.52836,1,), ); for ($i=0;$i<count($data);$i++) { for ($j=0;$j<count($data[$i]);$j++) { $R2[$i][$j] = (($data[$i][0]*$data[0][$j])+($data[$i][1]*$data[1][$j])); } } echo "<pre>"; print_r($R2); echo "</pre>"; result: 1.279164732 -1.056721269 -1.056721269 1.318545629 how to do nested loop from process above until the result: iteration 1: $data * $data = 1.279164732 -1.056721269 -1.056721269 1.318545629 iteration 2: $R2 * $R2 = 2.752922251 -2.703440873 -2.703440873 2.752921564 iteration 3: result($R2 * $R2) * $R2= 6.378224523 -6.367216988 -6.367216988 6.378222905 loop break because value array >= 5 please help me :3

Member Avatar
Member Avatar
+0 forum 1

Hello, First of all some background. My friend and I are having a bit of a competition over theoretically infinite number storage. We have agreed that the first person with a working arbitrary precision integer library with the theoretical ability to store an infinitely large number (IE: if the hard drive was big enough it would fill it up with the number) shall win. My plan has been to use .int files with the following format: 1-bit : Sign (1=positive, 0=negative) 31-bits : data (0=END) data-bits : base 256 little endian number info max FNAME_MAX-bits : next File (to be …

Member Avatar
Member Avatar
+0 forum 6

Hello all, I am trying to get a bunch of sub-keys and values from the registry in vb 2010 and i remember in vb6 this was quite easy. Can anyone share code to help? Or a link where I can go? I've been searching for nearly 8 hours on line and can't find anything I can use. The microsoft sites don't really help and most of the articles I find are for vb 7, or vb 6. Any help would be appreciated. ./x86

Member Avatar
Member Avatar
+0 forum 7

I'm currently making a DLL with a collection of code snippets that I find myself commonly using. I have made a search functin that checks if one string is inside of another string. I have also added a vector choice in the case that I want to search many strings. In the header: static DATAEDITING_API bool Contains(std::string target, std::string source); static DATAEDITING_API bool Contains(std::string target, std::vector<std::string> source); static DATAEDITING_API bool Contains(std::string target, std::string source, bool sensitive); static DATAEDITING_API bool Contains(std::string target, std::vector<std::string> source, bool sensitive); Now the problem is that the following code snippet always returns true. The Contains(std::string, std::string, …

Member Avatar
Member Avatar
+0 forum 4

alright so my exact problem is that when I attempt to visit a url stored in a text file I get the error "URLError: <urlopen error no host given>" This is strange because if I type in the urls myself they work fine(opener.open("site.com")) The lines of code causing the error look something like this for site in test.txt: opener = urllib2.build_opener() opener.addheaders = [('User-agent', 'Mozilla/5.0')] home = opener.open(site)

Member Avatar
Member Avatar
+0 forum 10

Hi Everyone! I'm a user of Turbo C++ and my professor gave me an activity to make a Fibonacci sequence. No I already have the Code for it and it is working. The only problem is. I don't know how the FOrmula Works. I will show you the Code below: #include<stdio.h> #include<conio.h> int x, num, f0 = 0, f1 = 1, fibo; main() { clrscr(); printf("Enter a number: "); scanf("%i",&num); for (x=0;x<num;x++) { //fibo means fibonacci. fibo = f0+f1, f0=f1, f1=fibo; printf(" %i",fibo); } getch(); } IF you can just tell me how this FOrmula works: **fibo = f0+f1, f0=f1, …

Member Avatar
Member Avatar
+0 forum 6

Hi, everyone! This is my first post ever here in Daniweb. I experienced a problem in printing the sorted array of 5 numbers, as the following code only prints the first iteration of the loop, and it does not print the array input. Here's the code: section .data i db 0 ; Value to be incremented question db 'Enter a number: ' ; Prompt questionLen equ $-question newLine db 10, 10, 0 ; New blank line newLineLen equ $-newLine section .bss num resb 5 ; Array of size 5 counter resb 1 ; Value to be incremented counter2 resb 1 …

Member Avatar
+0 forum 0

HI Could yu please tell me how to get previous values from current iteration in the below example : public void parseDtoCollection(Collection dtos) contains list of dtos in private AssetClassVersion createNewAssetClassVersion(AssetDTO dto) method i am iterating but i want to get to get previous itearation values in current iteration if the dto.assetClassId is same then i want to append like previous matchedstring value + current matchedstring value public void parseDtoCollection(Collection dtos) { for (Iterator i = dtos.iterator(); i.hasNext();) { AssetDTO dto = (AssetDTO) i.next(); AssetClass assetClass = findAssetClass(dto.assetClassId); AssetClassVersion assetClassVersion = createNewAssetClassVersion(dto); assetClass.addVersion(assetClassVersion); if (dto.id > 0) { InformationAsset infoAsset …

Member Avatar
Member Avatar
+0 forum 6

If I have an arraylist of arrays (each item in the arraylist is itself a one-dimensional array), how can I iterate over each element of each array contained in the arraylist?

Member Avatar
Member Avatar
+0 forum 4

Hello there, submissiontime length finishtime remainingtime 1031 17:11 574.1025391 MB 1050 17:30 1 1326 22:06 536.0175781 MB 1343 22:23 2 2721 45:21:00 608.1279297 MB 2741 45:41:00 3 32 0:32 575.8115234 MB 51 0:51 4 1161 19:21 652.6259766 MB 1182 19:42 5 937 15:37 288.7597656 MB 946 15:46 6 3087 51:27:00 912.9931641 MB 3117 51:57:00 7 I'm trying to read this Excel (CSV) file and display the elements, I'm only interested in displaying the elements with title above, (1st, 3rd, 5th and 7th coloumns), I managed to do this but, the final line is duplicated and starts by 0 when I …

Member Avatar
Member Avatar
+0 forum 4

I have a listbox filled with different items. For each item in the list it will visit a site in the web browser, the user using the software fills out text on the page, then it moves down the list. How can I make it so it iterates down the list to an item, waits for the user to enter the data and for them to click a button on the GUI of the program, then continue the iteration again doing the previous things of stopping continuing?

Member Avatar
Member Avatar
+0 forum 2

Good evening im seeking help with this program, it is in a loop that ends if a negative number is entered, I am trying to get the largest number entered in the do while loop, ive tried creating a temporal variable (temp), but I dont know where to go from there, Help please, And to make it more FUN I cant use ARRAYS!!... but still pleeeeeeeese HELP! [CODE] do{ System.out.println(" Enter a number "); ingreso = leer.nextInt(); i++; //EFFORTS TO TRY TO GET THE LARGEST NUM: sum = sum + ingreso; temp = ingreso; if(may > temp){ System.out.println("The largest number …

Member Avatar
Member Avatar
+0 forum 1

Hi I come from Python background and learning C++. In one of my programs, I need to have one key with multiple values and both being strings. for e.g. [CODE] "str1" ---> "value of str1" "str2" ---> "value of str2" "str1" ---> "value of str1 1" "str1" ---> "value of str1 2" [/CODE] I think I need something like this: [CODE] map<string, vector<string> > mymap [/CODE] My question is how do I iterate and insert? Thanks and sorry for n00b question

Member Avatar
Member Avatar
+0 forum 6

I have the following code for shell sort (recursive) given in the question where t[ ] is an array to be sorted, n=no of elements initially. h is any large no initially,say h>n. [CODE]void shell_rec(int t[],int n,int h) { int aux,i; if(h<=0) return; if(n>h) { shell_rec(t,n-h,h); if(t[n]<t[n-h]) { aux=t[n]; i=n; for(i=n;i>=h && aux<t[i-h];i=i-h) t[i]=t[i-h]; t[i]=aux; } } shell_rec(t,n,h/3); }[/CODE] removing tail recursion i get: [CODE]void shell_rec(int t[],int n,int h) { int aux,i; int j; for(j=h;j>0;j=j/3) { if(n>j) { shell_rec(t,n-j,j); if(t[n]<t[n-j]) { aux=t[n]; i=n; for(i=n;i>=j && aux<t[i-j];i=i-j) t[i]=t[i-j]; t[i]=aux; } } } }[/CODE] now i want to remove the recursion using …

Member Avatar
Member Avatar
+0 forum 6

I have no idea what went wrong with my most recent code, but I suspect it has something to do with the following so I'll start there. Did I do something wrong in this? [CODE]cards=['1','1','1','1','2','2','2','2','3','3','3','3','4','4','4','4','5','5','5','5','6','6','6','6','7','7','7','7','8','8','8','8','9','9','9','9','A','A','A','A','K','K','K','K','J','J','J','J','Q','Q','Q','Q'] import random random.shuffle(cards) h1=[] for card in cards[1:7]: h1.append(card) cards.remove(card)[/CODE]

Member Avatar
Member Avatar
+0 forum 15

this is the output of the program. Enter num1: 2 Enter num2: 2 Enter number of iteration: 2 1=1.5 final answer=2.5 we are assigned to do the program . it's really difficult .

Member Avatar
Member Avatar
+0 forum 2

Hi, I created a Python script using pyPDF that automatically merges all the PDFs in a folder and puts them into an output folder and rename them automatically as per the folder's name. What I want to do now is for the script to search for sub-directories, process all the PDF files in them and create an output in the sub-directory and give it the same name as the sub=dir. I have been trying to use the os.path.walk() function but I can't get the hang of it or understand it. This is my current code: [CODE]#---------------------------------------------------------------------------------------------- # Name: pdfMerger # …

Member Avatar
Member Avatar
+0 forum 10

Hi there, I'm currently working on a small broject which is about providing flexible download service. Basically, I read the info from a csv file and put it in the futurelist, then depending on the length of the file I will put it either in currentlist or delayedlist and after that I want to clear the current elements from the future list, so that when I finish iterating through the futurelist it will be empty. when I use this code It will not work and jams, I will appreciate it if somebody helped me in this cout << "Contents: "; …

Member Avatar
Member Avatar
+0 forum 2

I find C# very well suited for doing math and all sorts of calculations, so here is an example. Just start a Console application and fill in the code. Have fun! The code also shows a use of delegates and some Console functions. If you don't know what the Newton-Raphson iteration method is, you can look it up [url=http://en.wikipedia.org/wiki/Newton%27s_method]here[/url] There is much to be improved in my code: Could have asked the user for input, instead of hardcoding some values. Could have made a Forms app out of it. Etc.

Member Avatar
+0 forum 0

Hey everyone, I have to manipulate two functions RECURSIVELY, strlen and strcpy. I was able to code the strlen: [CODE]int length(char* str){ if(str == NULL){ return 0; }else{ return length(str, 0); } } int length(char* str, int l){ int len=0; if(str[l]){ len = length(str,l+1); } else { return l; } return len; }[/CODE] But I am having a lot of trouble with even beginning the strcpy function: [CODE]char copy(char* old_str, char* new_str){ if(old_str == NULL){ cout << "Could not copy, string is empty\n"; return -1; }else{ } }[/CODE] Here is my input on Strcpy: - The base case can return …

Member Avatar
Member Avatar
+0 forum 7

Hi. This should be very easy for you guys, but I still can't get it visualized in my mind. Here's what I'm trying to do: [CODE] if (flag) for (i = 0; i < 10; i++) {LARGE_BLOCK_OF_CODE (that visits an array in order)} else for (i = 9; i >= 0; i--) {LARGE_BLOCK_OF_CODE (that visits an array in REVERSE order)} [/CODE] The problem is that this block of code cannot be placed in a function, and I don't want to copy/paste it twice. Is there any way I can do that in this manner: [CODE] if (flag) loop = for …

Member Avatar
Member Avatar
+0 forum 5

i need help with the following: make a program that gets the summation of a given number e.g. 4+3+2+1 implement it using both iteration and recursion ex. enter a positive number: 4 the sum is 10.

Member Avatar
Member Avatar
+0 forum 9

i need help with the following: make a program that would display the nth of the fibonnaci sequence. 1 1 2 3 5 8 13 21 34 55 ... n implement it using both iteration and recursion.

Member Avatar
Member Avatar
+0 forum 5

hi guys! please help me understand anything about recursion and iteration ways of coding. :) (maybe some overview, details or something) thank u. we haven't had any further discussion about this. ;p but our teacher gave an exercise that goes like this: make a program that gets the summation of a given number e.g. 4+3+2+1 implement it using both iteration and recursion ex. enter a positive number: 4 the sum is 10. make a program that would display the nth of the fibonnaci sequence. 1 1 2 3 5 8 13 21 34 55 ... n implement it using both …

Member Avatar
Member Avatar
+0 forum 5

I need to iterate through an array, starting with the first element, in chunks of, say, 5, then break off and do something else with the array, then go back to where I left off. I'm confused about how the array counter, using next, or current etc. would work. How can I reset the current counter to be where it was before it was potentially messed about with some other operation? I'm not sure if I've explained that well. So, say I want to start at an element of an array that isn't the beginning, (with a stored key) then …

Member Avatar
Member Avatar
+0 forum 3

Hi guys I'm trying to finish my assignment, I stuck in a weird situation. I'm trying to create a pointer a linkedlist. This linkedlist contains pointer to a user-defined objects (City) and I'm trying to add City to this linkedlist and then iterate through the linked list to find and modify them. Here is my City.h source code: [CODE] #include "List.h" #include <iostream> #include <string> class City { private: std::string name; List<City*> *nextCities; bool visited; public: City(std::string); void setNextCity(City c); bool isVisited(); void setVisited(); std::string getName(); City* getNextUnvisitedCity(); }; City::City(std::string _name) { name = _name; visited = false; nextCities = …

Member Avatar
Member Avatar
+0 forum 2

Ok.. so I just started python (just = 3 hours ago). I have basic input and output set. Hell I even understand slicing and stuff (OMG SUBSTRINGS SO MUCH EASIER ON PYTHON :O ) but Im finding it not so easy to understand how to use for loops (silly me. I know -.-) So I was hoping if someone could explain to me how they work in python and what's what in the syntax. Cheers. EDIT: Also, how can I just declare a variable and use it later? for example, like in java: [CODE=java] int a; //lines of codes... probably …

Member Avatar
Member Avatar
+0 forum 4

Hello everybody, For the last 2 days im trying to deal with a treeview. What i want to do is to copy the structure from one tree to another. I know there are other ways to do this, but the way i want is to iterate through any node-of any depth-. Im using Telerik's GridView. The code below is the work that i've done so far, but when i run it it throws an Exception saying:"[B][I]The collection has changed. The iteration may not be executed[/I][/B]". Im first calling the [B][I]CopyTree()[/I][/B] function: [CODE] public void CopyTree(RadTreeView trv) { NodesArr = new …

Member Avatar
Member Avatar
+0 forum 3

The End.