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)
>>> numberedSquare(5)

@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..

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..

you might wanna skip things like:
[CODE]letters = str(encrypted) ## you have taken encrypted as input from raw_input. So it would be a string anyways.[/CODE]

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

you might wanna skip things like:
[CODE]letters = str(encrypted) ## you have taken encrypted as input from raw_input. So it would be a string anyways.[/CODE]

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

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';
if (root->right!=NULL):
in1[i++] = 'R';

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';
if (root->left!=NULL):
    in1[i++] = 'R';

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


Now, would this work?

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: [URL="http://docs.python.org/using/windows.html"]python docs[/URL]

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

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)

[QUOTE]def print_lol(movies):
for each in movies:
if isinstance(each,list):
[CODE]>>> def print_lol(movies):
for each in movies:
if isinstance(each,list):

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.! :)

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

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,
[CODE]gcc 2.c 1.o[/CODE]
would suffice.?

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

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)

[CODE]#include "1.c"[/CODE]
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:

static int y=23;

void abc(int a){


include "1.c"

int main(){
return 0;

I can understand that the functions abc is accessible to this file, but how is this variable y accessible here?
[QUOTE]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[/QUOTE]
So, how is this static variable in 1.c printed here?? :-/

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:
Only one link to python..
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..

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

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:
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)

int main(){
int a[3][4];
for(int k=0;k<3;++k)
for(int l=0;l<4;++l)
return 0;
The errors include:
[CODE]||In function `void prnt(int
, int, int)':|
7|error: invalid types int[int]' for array subscript| |In functionint main()':|
15|error: cannot convert int (*)[4]' toint' for argument 1' tovoid 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.

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){
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;
for(int j=1;j<n;++j){
if( (f1[j-1]+a[0][j]) <= (f2[j-1]+t[1][j-1]+a[0][j]) ){
if( (f2[j-1]+a[1][j]) <= (f1[j-1]+t[0][j-1]+a[1][j]) ){
if( (f1[n-1]+x[0]) <= (f2[n-1]+x[1]) ){

int main(){
cout<<"This program gives the fastest way through a factory of n machines..\n";
cout<<"Enter number of machines.. ";
/int n,i;
int a[2][n],t[2][n-1],e[2],x[2];
cout<<"Enter the entry times..\n1. ";
cout<<"2. ";
cout<<"Enter the exit times..\n1. ";
cout<<"2. ";
cout<<"Enter the station times of row 1:\n";
for(i=0;i<n;++i) cin>>a[0][i];
cout<<"Enter the station times of row ...

while (b=false)[/QUOTE]
You are using the assignment operator here. This would assign the value false to b and continue in the loop.
Rather try an use:
//code to be used

Rather use this code:

[CODE]bool b;
cin>>birth; //remember to put in ';'
while (b!=false)
cout<<"Please Enter a positive value (a digit):"<<endl;

maybe you are getting confused with your very own variables...
Take it like this:
you firstly initialize the variables with.:
[CODE]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)
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=A1A1; // Value of A changes to AA=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

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

@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 [URL="http://www.cplusplus.com/reference/iostream/manipulators/"]cpluscplus[/URL] and [URL="http://www.cplusplus.com/reference/iostream/manipulators/boolalpha/"]cplusplus/boolalpha [/URL]which says that these are stream manipulators..
And yes, can anyone please tell how are keywords implemented. Like, these stream manipulators are implemented like..
[CODE]ios_base& boolalpha ( ios_base& str );[/CODE]
Please try to keep the language simple, cause I have not yet studied compiler design but was just curious to know..

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...

@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..

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...