techie1991 26 Junior Poster in Training

If you understand list comprehensions, then this might be of some help:

>>> def numberedSquare(n):
    for j in range(n,0,-1):
        print (''.join([str(i) for i in range(j,j+n)]))


>>> numberedSquare(9)
91011121314151617
8910111213141516
789101112131415
67891011121314
5678910111213
456789101112
34567891011
2345678910
123456789
>>> numberedSquare(5)
56789
45678
34567
23456
12345
techie1991 26 Junior Poster in Training

@JeffGrigg: Can you please elaborate what are you trying to say..?! I mean are you trying to explain the concept of symmetry?

and I don't code in Java (for your advice on JUnit). I prefer C,C++ (if the concepts are deep) or Python otherwise, which has good support for testing.. Anyways I never asked for any help on tools, so you might have assumed it..

techie1991 26 Junior Poster in Training

ok, I was actually asking for some test cases (maybe my selection of words wasn't good) for which this approach may fail, and luckily I got one myself..

techie1991 26 Junior Poster in Training

you might wanna skip things like:

letters = str(encrypted) ## you have taken encrypted as input from raw_input. So it would be a string anyways.

And you can change lowercase to a set rather than a list. Checking for characters in it would become faster.

techie1991 26 Junior Poster in Training

you might wanna skip things like:

letters = str(encrypted) ## you have taken encrypted as input from raw_input. So it would be a string anyways.

And you can change lowercase to a set rather than a list. Checking for characters in it would become faster.

techie1991 26 Junior Poster in Training

you can check the limits for your system in limits.h
To get through your confusions, try to put those limits in binary form and you will yourself find that they are not clashing..

techie1991 26 Junior Poster in Training

I was trying to find a solution for checking the symmetry of a tree.
I would like to get some comments on the approach.. I am trying to do it by modifying the inorder traversal thing..
The pseudo code is:

// since the structure should be similar
string in1,in2;

func inorder (root): //normal inorder traversal
    static int i;
    if root==NULL: return;
    if (root->left!=NULL):
        in1[i++] = 'L';
        inorder(root->left);
    if (root->right!=NULL):
        in1[i++] = 'R';
        inorder(root->right);

func modified_inorder (root):

// modified inorder traversal. This one flips the traversal order from (root,left,right) to (root,right,left).

    static int i;
    if root==NULL: return;
    if (root->right!=NULL):
        in1[i++] = 'L';
        inorder(root->right);
    if (root->left!=NULL):
        in1[i++] = 'R';
        inorder(root->left);

string_compare(in1,in2); //this should provide the result by comparing the strings formed by traversals.

Now, would this work?

techie1991 26 Junior Poster in Training

If you are getting that error at cmd, then you have not installed python correctly, or most probably you haven't added python to your environment variables.
please look at: python docs

techie1991 26 Junior Poster in Training

Oh thanks, :)
Will take some time to see and understand the whole code. (Will need to remember the C things).

techie1991 26 Junior Poster in Training

It would be great if someone already knowing about it could give me a better answer. I always try to get my answers from the source code and am left dazzled by the code in C. (last time I was trying to see how long was implemented)

techie1991 26 Junior Poster in Training

def print_lol(movies):
for each in movies:
if isinstance(each,list):
print_lol(each)
else:
print(each)

>>> def print_lol(movies):
	for each in movies:
		if isinstance(each,list):
			print_lol(each)
		else:
                     print(each)

This worked for me.
I wanted to ask that if movies is not a list here ( you are checking via isinstance ), then what are you iterating through? (maybe you have strings in that list movies).

techie1991 26 Junior Poster in Training

I was looking around the time module. The time.sleep(no_of_seconds) sleeps the program for no_of_seconds seconds.
I don't think this is busy wait. It must be scheduling the process at a later time. Just curious of how this is working.! :)

techie1991 26 Junior Poster in Training

Oh, I was handling files separately.
Thanks for all the help.

techie1991 26 Junior Poster in Training

I am using codeblocks on windows machine. So, it would be better if you could tell me the linking way too on IDEs.
On linux, if i am not wrong,

gcc 2.c 1.o

would suffice.?

techie1991 26 Junior Poster in Training

Yes, you can use a call to getch() or getche() and check for the ASCII values.

techie1991 26 Junior Poster in Training

OK, so the file inclusion makes the two files lump together, and is then served to the compiler as one "translation unit".
So, is their any other way round too, to access a global variable from a file without including it? (for which static plays its role)

techie1991 26 Junior Poster in Training
#include "1.c"

This would put the whole code in that file(1.c) as it is to this file(2.c).
I understand your point, but I am confused with the statement. According to my interpretation, a global variable in a file, if declared static, should not be shown (be accessible) in other files that link to the file having the variable.
I am now more confused!! Can you please just explain the statement.

techie1991 26 Junior Poster in Training

Even after looking at a lot of books, I am not able to understand the problem in the following code:

//1.c
static int y=23;

void abc(int a){
	printf("%d\n",a);
	}
//2.c
#include<stdio.h>
#include "1.c"

int main(){
	abc(12);
	printf("\n");
	printf("%d\n",y);
	return 0;
}

I can understand that the functions abc is accessible to this file, but how is this variable y accessible here?

The static declaration, applied to an external variable or function, limits the scope of that object to the rest of the source file being compiled.
from: dennis ritchie

So, how is this static variable in 1.c printed here?? :-/

techie1991 26 Junior Poster in Training

very good answer momerath..
I must really start using these boolean operators.. :)

techie1991 26 Junior Poster in Training

I was looking at a question:
Q. Given n numbers of which all numbers are repeated (at least once) other than one. We have to find that number.

Numbers range is to 10^9, thus using count sort would do no good.!

Adding the numbers one by one to a dictionary was another option (and a good one as the complexity is O(n)). But this has high implementation requirements.!

Can someone suggest some better answer to this problem.? :-/

techie1991 26 Junior Poster in Training

I just wanted to learn to create facebook applications using python.I am new to web development of any sorts, so everything seems to be weird right now.
Here is what i acquired by google searching pages:
This is the facebook developers page:
http://developers.facebook.com/opensource/
Only one link to python..
https://github.com/facebook/python-sdk
The downloaded file contains a small amount of python files, but they are asking for another module: google.appengine amongst others.
I tried to search for some previous applied code using google code, but alas, it all made no sense to me..!
If someone has ever worked on it before, then please give me some tips on how to move..

techie1991 26 Junior Poster in Training

listening to "airplanes" by B.o.b.
Good music with some great lyrics...

techie1991 26 Junior Poster in Training

I am not using STL here because this program is to be converted to C. (after it starts functioning like I want it to). So, maybe you understand this "last century C-like approach". ;)
Anyways, I tried using your way of passing the pointer on a test program:

#include<iostream>
using namespace std;

void prnt(int * a,int i,int j){
    for(int k=0;k<i;++k)
    for(int l=0;l<j;++l)
    cout<<a[k][l];
    }

int main(){
    int a[3][4];
    for(int k=0;k<3;++k)
    for(int l=0;l<4;++l)
    a[k][l]=k*l;
    prnt(a,3,4);
	return 0;
	}

The errors include:

||In function `void prnt(int*, int, int)':|
7|error: invalid types `int[int]' for array subscript|
|In function `int main()':|
15|error: cannot convert `int (*)[4]' to `int*' for argument `1' to `void prnt(int*, int, int)'|
||=== Build finished: 2 errors, 0 warnings ===|

So, can you please be more clear with your approach on pointers as I have never been too comfortable with these dangerous pointers.. :(
Any help would seem good.

And yes, The methods you stated seem to be for arrays, but I am asking for multidimensional arrays. So, please try to stick to the area of concern...

techie1991 26 Junior Poster in Training

I was trying to code the assembly line sheduling problem using the dynamic programming approach. I have coded the program but i am facing problem with the 2-dimensional arrays I am using. For testing purpose, I wanted to initialize the array, but I was not able to get it. Moreover, as most of the arrays I am using are dynamically allocated, They were not getting passed to functions.
Though I have made the program working with some tricks but I would really appreciate if someone helps me improve it.

#include<iostream>
using namespace std;

//Had to make much of the variables global so
//as to sought out the problem of functions.

int n=6,i;
int a[2][6],t[2][6-1],e[2],x[2];
int f1[6],f2[6],l[2][6],fe,le;


void prnt_statns(){//int f1[],int f2[],int l[][],int fe,int le,int n){
    int i=le;
    cout<<"line "<<i<<" station "<<n<<"\n";
    for(int j=n-1;j>0;--j){
        i=l[i-1][j];
        cout<<"line "<<i<<" station "<<j<<"\n";
        }
    }

void fast_way(){//int a[][n],int t[][n],int e[],int x[],int n){
    //int f1[n],f2[n],l[2][n],fe,le;
    f1[0]=e[0]+a[0][0];
    f2[0]=e[1]+a[1][0];
    for(int j=1;j<n;++j){
        if( (f1[j-1]+a[0][j]) <= (f2[j-1]+t[1][j-1]+a[0][j]) ){
            f1[j]=f1[j-1]+a[0][j];
            l[0][j]=1;
            }
        else{
            f1[j]=f2[j-1]+t[1][j-1]+a[0][j];
            l[0][j]=2;
            }
        if( (f2[j-1]+a[1][j]) <= (f1[j-1]+t[0][j-1]+a[1][j]) ){
            f2[j]=f2[j-1]+a[1][j];
            l[1][j]=2;
            }
        else{
            f2[j]=f1[j-1]+t[0][j-1]+a[1][j];
            l[1][j]=1;
            }
        }
    if( (f1[n-1]+x[0]) <= (f2[n-1]+x[1]) ){
        fe=f1[n-1]+x[0];
        le=1;
        }
    else{
        fe=f2[n-1]+x[1];
        le=2;
        }
    prnt_statns();//f1,f2,l,fe,le,n);
    }

int main(){
    cout<<"This program gives the fastest way through a factory of n machines..\n";
    cout<<"Enter number of machines.. ";
    /*int n,i;
    n=6;//cin>>n;
    int a[2][n],t[2][n-1],e[2],x[2];
    */
    cout<<"Enter the entry times..\n1. ";
    e[0]=2;//cin>>e[0];
    cout<<"2. ";
    e[1]=4;//cin>>e[1];
    cout<<"Enter the exit times..\n1. ";
    x[0]=3;//cin>>x[0];
    cout<<"2. ";
    x[1]=2;//cin>>x[1];
	cout<<"Enter the station times of row 1:\n";
	//a[0][]={7,9,3,4,8,4};//
	for(i=0;i<n;++i) cin>>a[0][i];
	cout<<"Enter the station times …
techie1991 26 Junior Poster in Training

while (b=false)

You are using the assignment operator here. This would assign the value false to b and continue in the loop.
Rather try an use:

while(b==false){
//code to be used
}

Rather use this code:

bool b;
cin>>birth;  //remember to put in ';'
b=isdigit(birth);
while (b!=false)
{
cout<<"Please Enter a positive value (a digit):"<<endl;
     cin>>birth;
     b=isdigit(birth);
}
techie1991 26 Junior Poster in Training

maybe you are getting confused with your very own variables...
Take it like this:
you firstly initialize the variables with.:

int X=1, Y=2, Z=3, A=4, B=5, C=6, A1=7, A2=8, A3=9;

Then you call a function F with arguments: (X, Y, Z, A, B, C) or (1,2,3,4,5,6)
Fine..
Now the function is called like (arguments X,Y,Z by value and arguments A,B,C by reference). If you are clear with difference between call by value and call by reference then follow..

//In your function, value pointed to by &A is now given by A1

void F2(int X, int Y, int Z, int&A1, int& A2, int&A3)
{
     X=X+5; //no matter to X as called by value
     A1=A1*A1;     // Value of A changes to A*A=4*4=16
     A2=(Y + Z)/2; // Value of B changes to (2+3)/2=5/2=2
     A3= (Y-Z)/2;  // Value of C changes to (2-3)/2=-1/2=0
     return;
}

And as your main() function's values of A1,A2,A3 are not manipulated in any ways, they remain the same..

techie1991 26 Junior Poster in Training

@rpdm: sorry, but actually at that time I could not at all understand what were these 'boolalpha' and 'noboolalpha'.. now some google search has shown me cpluscplus and cplusplus/boolalpha which says that these are stream manipulators..
And yes, can anyone please tell how are keywords implemented. Like, these stream manipulators are implemented like..

ios_base& boolalpha ( ios_base& str );

Please try to keep the language simple, cause I have not yet studied compiler design but was just curious to know..

techie1991 26 Junior Poster in Training

Sorry, but can you please explain your program cause at my system it is not working for any of +,- or *. The program is not using the operator anywhere...

techie1991 26 Junior Poster in Training

@rpdm Don't get offensive/angry!! I was just pointing to some loop holes you were having in your program.. I believe that is what we are here for, helping each other..?
@mods maybe this thread is going off the topic, I would request you for it's closure..

techie1991 26 Junior Poster in Training

Ok, so I was correct that they are defined using preprocessor #define. ;)
So, I assume there ain't any solution to getting the input as "true" and making the program think it to be 1 except than using strings...

techie1991 26 Junior Poster in Training

Read the rules. I did just enough of the assignment to help chalson without giving him something he can turn in for homework credit.

If your was motive as this, then try not to feed in code here, give out just the pseudo code,.. if you really want it so.

The algorithm doesn't change for floats.

Who said to you that the algo was wrong..!?

I guess you didn't know that falling off main returns 0 automatically.

Sorry, but i know that. But you must also know that, writing "return 0" at the end of the program is useful when making large programs.

techie1991 26 Junior Poster in Training

The last time I was making a program, I wanted to input from user a boolean answer (to save space ;)) An input of 0/1 works good (0-false) and (1-true), but if the user inputs the boolean values as "true" and "false", it comes out to be an error.
So, are there any ways of doing so.?
I believe, that the strings "true" and "false" are defines using #define in the header files because of which the input is creating an error. Am i correct.?

techie1991 26 Junior Poster in Training

@rpdm read my post again, it's the implementation of the same algo.
And remember:
1. chalson wanted to get the numbers as input, so you won't require the time() and srand() and the inclusion of header files <cstdlib> and <ctime>
2. The values required are float, not integers.
3. your main() should return a value.

rpdm commented: All bad points. Thanks for assuming I'm an idiot. +0
techie1991 26 Junior Poster in Training

Check in the error. It usually gives the line number to look around for mistakes. If that does not work then you can post a better overview of your program..

techie1991 26 Junior Poster in Training

The best way would be to calculate it during the process of input.

float s=0,l=0,x;
for(int i=0;i<20;++i){
cin>>x;
if(x>l) l=x;
if(x<s) s=x;
}
/* Use the values */

Or after taking the input in an array, go through it and get the smallest and largest values.

float s=0,l=0,a[20];
/* input the array */
for (int i=0;i<19;++i) {
if(x>l) l=x;
if(x<s) s=x;
}
/* Use the values */
techie1991 26 Junior Poster in Training

Actually, the float type doesn't support modulus operator. That is why your program is giving an error. It is because the float numbers are stored in memory in two parts, mantissa and exponent.
Now, if you understand the concept of pointers than try to understand this.
When we call a function by value, we call it like

func(a,b)

. This passes to the function the values pointed to by these variables 'a' and 'b'.This creates a temporary image of these values in the memory somewhere for the function to work upon and thus the original variables are not affected at all.
But when we call a function by reference, we call it like

func(&a,&b)

. Where '&a' and '&b' refer to the address of the variables stored in the memory. So, we pass to the function, the address values of the same variables. This unlike previously, makes the function operate on the same variables using their addresses. (NO temporary variables are made).
Hope you understood.!;):)

techie1991 26 Junior Poster in Training

To those, who got confused like me initially, python is now implementing int as long and thus you can find it as..
python3.x\Objects\longobject

techie1991 26 Junior Poster in Training

For the course: You can read:
The schaum series, (I myself read it)
Data structures with C, yashwant kanetkar or
Data structures, Rajni Jindal.
I too am a student at Delhi College of Engineering, and I assure it that these books would be enough for anything asked in exams. And if you want to go deep, then their is no end to learning data structures.. ;)

techie1991 26 Junior Poster in Training

Maybe I used the wrong word "portability":$. Actually I wanted to say that if you want to create a project that is to be used by different coders following different languages, than you can always go for the json module. Just a piece of knowledge I had and I wanted to share. I didn't know about the speed problem. :-O
And if anyone wants to see the languages supported by json: json.org

techie1991 26 Junior Poster in Training

Ok, that was also a really good method, but I have never myself implemented hash tables in C/C++ (except dictionaries in python). So, I could not understand at first look the ContainsKey() function of C# you used.:$
Now, I hope the post is marked "solved" cause I don't think that the algorithm complexity can go any way lower than this.:)

techie1991 26 Junior Poster in Training

Absolutely...So this proves that the question can easily be solved in less than O(n^2). As said before, Even if the array is not sorted, we can sort it using any of the many available algorithms to bring down the complexity to atleast O(n*logn).

techie1991 26 Junior Poster in Training

Use either a pickled dictionary as said by Beat_Slayer or if you want portability, use json module of python. (JavaScript Object Notation)

techie1991 26 Junior Poster in Training

If this was an interview question, you could have assumed the array to be sorted. (I did assume many things in my interviews and cleared most of the rounds).
Now, if the array is sorted, use a for loop with a search algorithm (binary search). The worst case would come down to O(n*logn).
A sort can also be performed in the starting, if the array is not assumed to be sorted. Use quicksort with average performance of O(n*logn) so that the overall complexity remains O(n*logn).
Hope this answers you a bit..

techie1991 26 Junior Poster in Training

This seems to be your homework,.. Help yourself, use the karnaugh maps,.. it would be really easy..
If you want to know about K-maps, check at: Wikipedia

techie1991 26 Junior Poster in Training

Thank you all for such a good welcome. The stay up to this date has been really good and educative, hope this continues... Thank you all once again..!!

techie1991 26 Junior Poster in Training

I listen to music whenever I can, be it browsing, coding or anything else... soothes me down!!
Currently listening:
In the shadows by resmus

techie1991 26 Junior Poster in Training

Go to Project -> Project Options -> Compiler -> C++ Compiler and set "Turn off all access checking option" to No.

So, this is actually the problem of the compiler, nothing less on my code.. right..?
If that is the case, then why is it not set as "NO" by default..

techie1991 26 Junior Poster in Training

This may be quite a late introduction, but better late then never.
I am having great fun at this forum. See me at C, C++ and python forums... got to learn a lot..

techie1991 26 Junior Poster in Training

I have just started writing C code in dev-c++. The programs are running fine, but each C program shows me the following warning:

[Warning] command line option "-fno-access-control" is valid for C++/ObjC++ but not for C

The test program I used was:

#include<stdio.h>
int main(){
system("pause");
return 0;
}

After searching a lot all I could find was:

-fno-access-control Do not obey access control semantics

Can anyone please explain, what is this all about?
Thanks..

techie1991 26 Junior Poster in Training

OK, sorry, now I understood, actually I was asking that why was the char pointer acquiring 4 bytes even when it was not pointing to anything.. but now I understood the pointer is storing the address which requires those 4 bytes.. Hope I am correct..!!