I am trying to implement Connect 4 game using Min-Max as utility to find best possible move.<br><br> The game is played on a 6x7 grid, with six rows and seven columns. . The two players take turns placing pieces on the board: the red player can only place red pieces, and the green player can only place green pieces. It is best to think of the board as standing upright. We will assign a number to every row and column, as follows: columns are numbered from left to right, with numbers 1, 2, ..., 7. Rows are numbered from bottom … |
+0 forum
1 | ||

You know the Pareto Principle? The 80/20 rule? That 80% of the work gets done by 20% of the people? Or 80% of the money belongs to 20% of the people? And so on? Well it is 'recursive' inasmuch as it can be applied again to the 20% first recognised. i.e. if 20% do 80% of the work then 20% of the 20% do 80% of they work THEY do. And so on. While I can get my head around recursion generally and can fully comprehend the standard recursive algorithm for calculating factorial - I'm not smart enough to put … |
+1 forum
1 | ||

This code generates an ascii maze of up to size 30x30. If you try to generate a larger maze then you will likely run out of stack space. There is no way to increase the size of the stack in vbscript. Each cell in the maze is represented by a string of five characters such as "11110". The first four chars represent whether a wall is present ("1") or absent ("0") in the four directions "UDLR". The fifth char represents whether a cell has been visited ("1") or not ("0"). Each cell maintains its awareness of the four walls bounding … |
+0 forum
2 | ||

Hi, I have created a function that searches for a category in a category tree object and returns all the paths for it as an array of strings, please advice how I can improve it ? the result im getting now is : ["vehicles",["cars","mercedes"],["trucks","mercedes"],["motorcycles","BMW"]] i need it in one dimesional array like this : ["vehicles","cars","mercedes","trucks","mercedes","motorcycles","BMW"] here is also a plunker url for the same code im trying t solve : [Click Here](http://plnkr.co/edit/JOH63BuL55HgEtEYnVjd?p=preview) thanks in advance, please advice. var categories = {category:"vehicles",children:[ {category:"cars",children:[{category:"mercedes",children:[]}]}, {category:"trucks",children:[{category:"mercedes",children:[]}]}, {category:"motorcycles",children:[{category:"BMW",children:[]}]} ]}; function getnodes(nodes) { var arr=[]; if (!nodes.children.length) return nodes.category; else{ arr.push(nodes.category); for(var i =0 ; … |
+0 forum
1 | ||

Hie,I have Merge Sort Program .It's giving correct output but when checked through debugger it gives different values everytime.I also tried doing it manually but I am not getting the actual output. I will not ask now for complete program explanation. I just want to know the value over here.This is the half program. #include<stdio.h> int main() { int i,low,high,n,a[10]; printf("how many elements"); scanf("%d",&n); printf("\nEnter the elements"); for(i=0;i<n;i++) scanf("%d",&a[i]); low=0; high=n-1; msort(a,low,high); printf("The sorted array is "); for(i=0;i<n;i++) printf("\n%d",a[i]); return 0; } msort(int a[],int low,int high) { int mid; if(low<high) { mid=(low+high)/2; msort(a,low,mid); // values are correct here msort(a,mid+1,high); // … |
+0 forum
1 | ||

Below is my code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> using namespace std; ///////////////////////////////////////////////////////////////////////// /* // struct Edge // Represent one edge in the graph. Fields contain // two vertex numbers and a weight. */ struct Edge { int vertex_1, vertex_2, weight; }; //////////////////////////////////////////////////////////////////////// /* // struct Graph // Represents a weighted graph. Fields contain the # of vertices, // edges,an array of edges, along with it's physical size. */ struct Graph { // V-> Number of vertices, E-> Number of edges int V, E; // graph is represented as an array of edges. Since the graph is … |
+0 forum
6 | ||

Good evening everyone, Does any one have a reference/videos/tutorials on how to use recursion effecitely in C++? v/r |
+0 forum
3 | ||

Good morning everyone, The library will be home, 0800 till 2100. I've been working on trying my loops in my hailstone sequence into recursions. It seem recursion can easrier to do, instead of creating loops. I say seem, because now I have come to halt on my progress. The halt is in the form of my sequence_Max function: /* //sequence_Max(int n) //Returns the largest value in the //hailstone sequence starting at 'n'. */ int sequence_Max(int n) { //Variable Declaration. int max = n, temp = n; while (temp > 1) { temp = next(temp); if(temp > max) { max = … |
+0 forum
29 | ||

Hello , I have this code: #include <iostream> #include <cstdio> #include <cstdlib> using namespace std; void message(int numbers) { cout << "Entry to function #" << numbers << endl; if ( numbers > 0 ) { cout << "This is a recursive function." << endl; message( numbers-1 ); } cout << "Exit from function #" << numbers << endl; } int main() { message(4); return 0; } and the output is : Entry to function #4 This is a recursive function. Entry to function #3 This is a recursive function. Entry to function #2 This is a recursive function. Entry … |
+0 forum
8 | ||

Hi every one, I had implemented Karatsuba algorithm in C++, but I have been stuck for 2 days. First problem is the function give incorrect answer, second problem is it oftens crash when run (runtime error). I try to debug but cannot understand how it's not work. I hope someone will help me out. I test all related functions of this function, everything work fine except Karatsuba function (I call it *kmulrun*). I implement big integers in base 10^4 (so the product of to digits will fit well in *int* type, for maximum performance), I implement all core functions by … |
+0 forum
0 | ||

Hello, I've been working at this code from a couple angles, I've had two people I've known to help me, but even with their help it hasn't worked. The question I have relates to CodeLab: Write the definition of a function named printStarBucks that receives a non-negative integer n and prints a line consisting of N asterisks followed by N dollars signs. So, if the function received 5 it would print: *****$$$$$ and if received 3 it would print ***$$$ The function must not use a loop of any kind (for, while, do-while) to accomplish its job. The function should … |
+0 forum
2 | ||

When recursion won't do, then memoizaton will. |
+0 forum
4 | ||

Hello ! I have a task that is difficult for me to handle. The task is: Create recursive function that can be generate a string of length N (N <= 100), formed by the letters 'A', 'B' and 'C' and does not containing two identical adjacent substring. For example: enter for N = 6 and the program should generate such a string in which no one else to repeated substrings: ABACAB. Wrong strings are: **AA**BACA - because 'A' is to 'A'; A**BCBC**A - as 'BC' is to 'BC' and **ABCABC** is also wrong because 'ABC' is to 'ABC'. I made … |
+0 forum
2 | ||

One of the more common functions in any language is conversion of an integer to a string. This implementation, which demonstrates not only the common function activation record format but also a simple recursive function, was written in response to a recent question in which the OP posted an incomplete implementation; this should show how such a function could be written for the MIPS processor. |
+0 forum
1 | ||

Hi all, I was just playing around with some ideas about optimizing a core piece of my library: the run-time type identification system (RTTI). What does that have to do with compile-time string concatenation? Well, the whole point of the RTTI is to provide information on the type of objects, and a string representation of that name is a pretty central part of that (as well as a hash value). Type names are made of identifiers, which are names that are known at compile-time, and could thus be compile-time string literals (that means things like `"Hello world!"`). The problem is, … |
+6 forum
6 | ||

Hi guys, I wrote the following code: public static boolean match(int[] a , int[] pattern) { //need to use the overloaded method, in order to work with the static method. return match(a,pattern,0,0); } /** This is an overloaded method that match between a pattern to a given string (as an array)*/ private boolean match(int[] a, int[] pattern, i, j ) { if(j==pattern.length) return true; if( (i==a.length) && (j!=pattern.length) ) return false; switch(pattern[j]){ case 1: if( (a[i]/10)==0 ) return match(a, pattern, i+1, j+1); return match(a, pattern, i+1, j); break; case 2: if( ( (a[i]/10)==0 ) && ( (a[i]/100)==0) ) return match(a, … |
+0 forum
33 | ||

I [saw interesting problem](http://www.daniweb.com/software-development/legacy-languages/threads/478323/prolog) of generating spiral of numbers and realized I could reuse [my code for rotation](http://www.daniweb.com/software-development/python/code/371536/rotate-sequences-left-or-right) I posted earlier. |
+3 forum
0 | ||

Hi, I am making program that finds solution how to put 12 knights(horses) to chess board that every square is dominated or engaged by other knight. Look at my code: #include <stdio.h> #include <stdlib.h> #include <stdbool.h> //(*******************************************************************************) void addNulls(char L[][9], int N[], int M[]) { int i,j,g; for (i=1 ; i<9 ; i++) for (j=1 ; j<9 ; j++) if (L[i][j]!='K') L[i][j]='0'; for (i=1 ; i <9 ; i++) for (j=1 ; j <9; j++) if (L[i][j]=='K') for (g=1 ; g <9; g++) if (i+N[g]>0&&i+N[g]<9 && j+M[g]>0 && j+M[g]<9 && L[i+N[g]][ j+M[g]] == '0') L[i+N[g]][ j+M[g]] = '*'; } //(*******************************************************************************) … |
+0 forum
2 | ||

Hi I have to write program that finds a solution how to put 12 knights to a 8x8 chess board that every square would be dominated by one of the 12 knights. Do you have any suggestions from where I can start? |
+0 forum
3 | ||

How's the result to this 7? void foo(int i){ if(i>1){foo(i/2);foo(i/2);}cout<<"#"<<endl;} |
-1 forum
2 | ||

i have a c code for printing all permutation of string. I have a problem in understanding ,how recursion work in for loop and how backtracking is used in this code. Another question is that how stack work in recursion under for loop. my code--> # include <stdio.h> void swap (char *x, char *y) { char temp; temp = *x; *x = *y; *y = temp; } void permute(char *a, int i, int n) { int j; if (i == n) printf("%s\n", a); else { for (j = i; j <= n; j++) { swap((a+i), (a+j)); permute(a, i+1, n); swap((a+i), … |
+0 forum
1 | ||

def isPrime(num,div=2): if(num==div): return True elif(num % div == 0): return False else: return isPrime(num,div+1) |
+0 forum
2 | ||

In most modern languages, there are two fundamental approaches to repeating an action: either *iteration*, in which an action is placed inside a special-purpose structure which causes the action to be repeated, or *recursion*, in which a general-purpose function calls itself (or another function which in turn calls the earlier function). Which is to be used depends on the nature of the problem at hand, and to a great degree, the language being used. Some languages, especially Lisp and the various functional languages, strongly favor recursion; but most other languages, including C++, focus almost entirely on iteration. As a result, … |
+1 forum
26 | ||

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, … |
+4 forum
6 | ||

Hey everyone, I really need help in solving a problem that I have to use recursion for. I have a list of paper objects. Each paper object has its own author(s) objects. Each author object knows which paper(s) objects they belong to. I have to build a scholarly neighborhood for these authors. The user can select an author and specify the "width" of the neighborhood that they wish to view. The width of this neighborhood goes as follows: If they enter "0" the neighborhood will consist of only the author that they selected. If they enter "1" the neighborhood will … |
+0 forum
4 | ||

This is just a piece of code I've found over the Internet, and I'm trying to understand why the output is 3 1 1 2 1 1 2 3. Could anyone explain using a stack representation or something else, I am really stuck on this one. #include <iostream> using namespace std; void ex233(int n) { if (n <= 0) return; cout << n << endl; ex233(n-2); ex233(n-1); cout << n << endl; } int main() { ex233(3); return 0; } I did read about recursion but I didn't find any good examples on how recursion works when the function is … |
+0 forum
4 | ||

#include <iostream> using namespace std; int f(int i) { if(i == 1) { return (1); } else { return 2*f(i-1); } } int main() { cout << f(5) << endl; //<--- I don't understand why this is 16. return 0; } I am having trouble understanding why f(5) = 16 when I run the program. i = 5 // 2(4) = 8 i = 4 // 2(3) = 6 i = 3 // 2(2) = 4 i = 2 // 1 these don't add to 16. I would really appreciate some guidance. |
+0 forum
2 | ||

Hi. I was wondering how I could replace objects in a list without using a single loop. Here's what I have in terms of algorithm; but, I don't know how to implement.: replace(List list, oldObject, newObject) 1. if the first element in list is not null 2 if the old Object == (the object in list) 3 new object replaces old Object 4 replace(list, oldObject, newObject) Ps. I know the == is not allowed when comparing objects, its just pseduo code I don't know how to traverse through the list without a for loop. Could I use iterator? |
+0 forum
2 | ||

Hey guys I had an assignment to recursively write the Towers of Hanoi then test it. I did not have too much of an issue getting the program written But I am not sure what the book means by test the efficiency do they want the number of moves my program makes, or do they want the time it takes to run. And how do I get either one? help is appreciated [CODE] import TerminalIO.KeyboardReader; public class towers { public static void main(String[] args) { KeyboardReader reader = new KeyboardReader(); int numberofRings = reader.readInt("Enter number of Rings: "); move (numberofRings, … |
+0 forum
10 | ||

Im trying to add Total function and isMono functions to this code. Did total already Need help with function ismono which returns whether a tree is mono (all the elements are unique aka no element appears more than one time) or not. Please this is the original program #ifndef T_H #define T_H #include <iostream> #include <iomanip> using namespace std; struct tnode { int info ; int count; tnode * right, *left; }; tnode * insert(int target,tnode * t); tnode * makenode(int x); tnode * tsearch(int x,tnode * t); void inorder(tnode * t); int height(tnode * t); int count(tnode * t) … |
+0 forum
2 |

The End.