Google Algorithm Exercise.

99 views
Skip to first unread message

Seabook

unread,
Feb 9, 2012, 12:09:41 AM2/9/12
to happy-pr...@googlegroups.com
1) Given a function which produces a random integer in the range 1 to 5, write a function which produces a random integer in the range 1 to 7.

2) Write a function f(a, b) which takes two character string arguments and returns a string containing only the characters found in both strings in the order of a. Write a version which is order N-squared and one which is order N.

Happy Coding.

Thanks,
Seabook

Huanwen Qu

unread,
Feb 9, 2012, 6:21:41 PM2/9/12
to Data Structures Algorithms and Programming
The first one is easy. Generate seven random number and sumerize them,
then divide five.


don't Understand the second one.

Seabook

unread,
Feb 15, 2012, 7:31:30 AM2/15/12
to happy-pr...@googlegroups.com
The first one could construct a matrix like this
{
1,2,3,4,5,
6,7,1,2,3,
4,5,6,7,1,
2,3,4,5,6,
7,0,0,0,0
}

int x = random(5) - 1;
int y = random(5) - 1;


return matrix[x][y] == 0? recursive : matrix[x][y];
Message has been deleted
Message has been deleted

Huanwen Qu

unread,
Feb 16, 2012, 7:25:06 AM2/16/12
to Data Structures Algorithms and Programming
Not sure if this will produce perfect result.

My solution is much easier.

return round((rand5()+rand5()+rand5()+rand5()+rand5()+rand5()
+rand5())/
5);
Reply all
Reply to author
Forward
0 new messages