Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 exam problem

Author  Topic 

ace333
Starting Member

11 Posts

Posted - 2005-09-20 : 13:06:40
What initial values of a and c are required such that the final values of a and b are:


a = 32
b = 4



int a,b,c

a = ?
b = 0
c = ?

for( b=0; a<12; b++ )
{
a = (a+a) * c;
}


I know its not the area but i'm hoping someone has an idea

SamC
White Water Yakist

3467 Posts

Posted - 2005-09-20 : 13:20:58
If you want help with home exams, you should post it as a puzzler in the Yak Corral so it doesn't appear to be schoolwork.
Go to Top of Page

ace333
Starting Member

11 Posts

Posted - 2005-09-20 : 13:23:04
no its not school work, its a sample of an exam question given in an interview, what is the yak corral (will google it)
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-09-20 : 13:25:31
The Yak Corral is another forum here on SQL Team.

Here's a list of all the forums.

http://sqlteam.com/Forums/default.asp
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-09-20 : 13:29:23
Since you *say* it isn't homework, here's my hack:

b=0; a = 2ca
b=1; a = 2c(2ca)
b=N; a = (2c)^(N+1)*a

Final condition: b=4, a=32
32 = (2c)^5 * a = 32 * c^5 * a

Looks like there are many initial conditions, so long as a = 1/(c^5), it'll work, such as c=a=1.
Go to Top of Page

ace333
Starting Member

11 Posts

Posted - 2005-09-20 : 13:41:52
what language is that and what is the ^ mean. I dont understand ur answer......
i have to come up with numerical values for a and c......
and its not homework,,,,,, its annoying ...this is going to bug me all night
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-09-20 : 13:52:09
Sam - you need to reread the code in the question... it doesn't execute when b=4... it last executes with b=3.

ace - my guess is a=-4 and c=-1. Although, I think that Sam is correct in that any number of solutions could be true assuming non-integers could be used.

edit:
also a=.5 & c=2 works...

Corey

Co-worker on The Wizard of Oz "...those three midgets that came out and danced, the freaked me out when I was little. But they are ok now."
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-09-20 : 14:51:02
quote:
Originally posted by ace333

what language is that and what is the ^ mean. I dont understand ur answer......

the language is math, and ^ means ** (raised to the power)
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-09-20 : 14:56:37
quote:
Originally posted by Seventhnight

Sam - you need to reread the code in the question... it doesn't execute when b=4... it last executes with b=3.


OK, OK. The final value of b is 4, but the loop exit condition is a>=12, so that changes a few things...

We must satisfy the condition a*c**(4+1) = 1, and when b=3, a<12, and when b=4, a>=12

So... what are a and c initial values?
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2005-09-20 : 15:26:38
42



-ec
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-09-20 : 16:06:33
i still stand that integer wise:

a=-4 & b=-1

or with rationals:
a=.5 & b = 2
or
a=.0625 & b = 4
etc...

Corey

Co-worker on The Wizard of Oz "...those three midgets that came out and danced, the freaked me out when I was little. But they are ok now."
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-09-20 : 16:08:05
quote:
Originally posted by eyechart

42

The answer to everything?

I don't think this one has a solution that meets the initial and final conditions.
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-09-20 : 16:16:08
Sam... are you ignoring me I've posted 3 different solutions...

Corey

Co-worker on The Wizard of Oz "...those three midgets that came out and danced, the freaked me out when I was little. But they are ok now."
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-09-20 : 16:21:32
quote:
Originally posted by Seventhnight

i still stand that integer wise:

a=-4 & b=-1

or with rationals:
a=.5 & b = 2
or
a=.0625 & b = 4

I read the problem as:

Initial conditions: b=0, a, c are to be determined
Final conditions: b=4, a=32, c can be calculated from the initial conditions
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-09-20 : 16:25:50
quote:
Originally posted by Seventhnight

Sam... are you ignoring me I've posted 3 different solutions...

Sorry, I wasn't giving enought notice to your earlier posts.

I don't see a working solution. To get to 32, the loop would exit at b=3.
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-09-20 : 16:28:13
okay okay... so i mis-typed:

a=-1 & c=-1

or with rationals:
a=.5 & c=2
or
a=.0625 & c=4
...

i even think that the rational solutions could both be positive or negative...

Corey

Co-worker on The Wizard of Oz "...those three midgets that came out and danced, the freaked me out when I was little. But they are ok now."
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-09-20 : 16:31:20
a=-1, c=-1 works...
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-09-20 : 16:31:44
Hey! Fix your thumbnail image. I miss the entertainment.
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-09-20 : 16:32:36
a=.5, c=2 gives a=512 when b=4
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-09-20 : 16:37:15
sorry.. i was under the mis-guided impression that the b would increment, but that the a would force it to not continue.

so i ran it as a javascript function...
and
a=2 & c=-1 works.


<html>
<script>
a=2;c=-1;
b=0;

for( b=0; a<12; b++ )
{a = (a+a) * c;}

alert("a:" + a + " b:" + b)
</script>
<body>
</body>
</html>


Corey

Co-worker on The Wizard of Oz "...those three midgets that came out and danced, the freaked me out when I was little. But they are ok now."
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-09-20 : 16:40:33
also
a=.125 & c=2


Corey

Co-worker on The Wizard of Oz "...those three midgets that came out and danced, the freaked me out when I was little. But they are ok now."
Go to Top of Page
    Next Page

- Advertisement -