Hello , I found this puzzle :

``````typedef struct {
int dd[ 5 ];
int tx;
} node;

node * A = new node[ 10000 ];

for ( int i = 0; i < 100000; i++ ) {
for ( int j = 0; j < A[ i ].tx; j++ ) {
int b = A[ i ].dd[ j ];
a[ i ] = a[ i ] + q[ b ];
}
}
``````

which says to find any errors ( if any) and solve it! Without any other information or data.

I can see two things here:

1) The size of the node A is 10000 but the first loop goes until 100000.So , this is wrong right?

2) The "dd" has size 5 ,so the second loop must go until 5 ,hence A[ i ].tx = 5 ,right?

I can't solve though..

Tahnks!

The size of the node A is 10000 but the first loop goes until 100000.So , this is wrong right?

Correct.

The "dd" has size 5 ,so the second loop must go until 5, hence A[ i ].tx = 5, right?

No; `tx` could be any …

The code does not suppose to be compiled.You must solve it without compiling.

Ah, I see.

any other ideas about how to solve this

You should definitely look at all of the variables and verify that they exist. For example, what is `q`?

Does "solve it" …

## All 7 Replies

The size of the node A is 10000 but the first loop goes until 100000.So , this is wrong right?

Correct.

The "dd" has size 5 ,so the second loop must go until 5, hence A[ i ].tx = 5, right?

No; `tx` could be any int value, and the loop should go from 0 to 4.

Look at variable names. Do they all exist?

Have you tried actually compiling this? I imagine that would tell you quite a bit.

No; tx could be any int value, and the loop should go from 0 to 4.

Sorry , I meant until 4,ok.

The code does not suppose to be compiled.You must solve it without compiling.
But , even that , yes ,I tried to compile it but I didn't succeed in solving this..

So,if you have any other ideas about how to solve this,I will appreciate.

Thank you

The code does not suppose to be compiled.You must solve it without compiling.

Ah, I see.

any other ideas about how to solve this

You should definitely look at all of the variables and verify that they exist. For example, what is `q`?

Does "solve it" mean figure out what it's supposed to be doing?

It does not explain what is q.
Probably ,just an integer array?

By solve it , yes ,probably what this code does ,what the values of a will be?

So,I guess the puzzle lacks of info?

So,I guess the puzzle lacks of info?

I think so. You could go through it line by line, adding comments that describe what the code does, but I don't think there's enough there to tell you what it's actually intended to do beyond "mush numbers around", especially given the mysterious undefined `a` and `q`.

Ok , thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.