|
|
#1 (permalink) |
|
TestMagic Guru-in-Training
![]() ![]() ![]() Join Date: Oct 2003
Location: Albania
Posts: 534
![]() |
Can you find out what do this functions do? Can you prove it? Don't worry about parameter passing methods, just what happens inside the function
Code:
1.
f(x,y)
{
x:=x+y
y:=x-y
x:=x-y
}
2. what's returned?
f(y,z)
{
x:=1
while z>0 do
x:=x*y
z:=z-1
return (x)
}
3. what's returned?
f(y,z)
{
x:=1
while z>0 do
if x is odd then x:=x*y
z:= floor(z/2)
y:=y^2
return (x)
}
4. what's returned?
f(y,z)
{
x:=0
while z>0 do
x:=x+y*(z mod 2)
y:=2y
z:=floor(z/2)
return (x)
}
Enjoyy!!!!!!!!! AlbaLed |
|
|
|
|
|
#2 (permalink) |
|
Within my grasp!
![]() ![]() Join Date: Oct 2003
Posts: 137
![]() |
1) Swapping
2) y power z 3) This is my guess y (even) then x = y^(2^(|_ lg n _| + 1) - 1) y = odd then x = y. 4) Convert the z value to its binary equivalent. Start from right side as y then move left as 2.y further left as y.2^2 ans so on. Each time you encounter a one in the binary multiply by its equivalent y factor and add it to the sum. e.g 1 1 1 1 2.2.2.y 2.2.y 2.y y This gives me another idea to state the same thing. Write down the expression for converting a binary number represented by z to its equivalent decimal number. Then instead of multiplying by 2^i at the places multiply it by y.2^i. Nice one. Jaideep |
|
|
|
|
|
#6 (permalink) |
|
TestMagic Guru-in-Training
![]() ![]() ![]() Join Date: Oct 2003
Location: Albania
Posts: 534
![]() |
Answers are
1. swaping 2. x power y typo on 3, sorry Code:
f(y,z)
{
x:=1
while z>0 do
if z is odd then x:=x*y
z:= floor(z/2)
y:=y^2
return (x)
}
4. y*z Good job jaideep and crackit AlbaLed |
|
|
|
|
|
#8 (permalink) |
|
Trying to make mom and pop proud
Join Date: Oct 2003
Posts: 14
![]() |
#2.
Let's say z:=5 z:= 5 ( >0) x := 1*y z:=5-1 = 4 z:=4 ( >0) x ..> 1*y*y z:=4-1 = 3 z:=3 ( >0) x ..> 1*y*y*y z:=3-1 = 2 z:=2 ( >0) x ..> 1*y*y*y*y z:=2-1 = 1 z:=1 ( >0) x ..> 1*y*y*y*y*y z:=1-1 = 0 z:=0 not >0 OUT x = y^z (not x^y) |
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Contact TestMagic TestMagic Forums Archive
Link to TestMagic
TestMagic Locations
Legal
Privacy
Partner Sites:
GMAT Sentence Correction
SAT 2400
Content Relevant URLs by vBSEO 3.0.0
Copyright © 1998-2008 TestMagic
Ad Management by RedTyger