A********3 发帖数: 45 | 1 1. Write a function that takes an array of five integers, each of which
is between 1 and 10, and returns the number of combinations of those
integers that sum to 15. For example, calling the function with the array [
1, 2, 3, 4, 5] should return 1, while calling it with [5, 5, 10, 2, 3]
should return 4 (5 + 10, 5 + 10, 5 + 5 + 2 + 3, 10 + 2 + 3). You may assume
that the input has already been validated. Show how you would test this
function.
2. Write a function to shuffle a deck of 52 c | v*****t 发帖数: 127 | 2 第一个回溯剪枝吧
第二个shuffle就用knuth好了。测试只有大量的shuffle很多次,然后看统计结果,比如每个位置上每张牌的等概率分布,位置上的相关性有些不太好测(比如说,你的shuffle算法很差,每次就是rotate一位),算一算不同位置上牌的相关性?或者就是每次算个inversion数来看看分布的情况,或者算算针对某一张牌看看他出现在哪些位置是否有随机性。反正就不停的想一些测试结果可以反映随机性的,估计面试官也不会是专门搞蒙特卡洛的。
第三个就完全不懂了。。。
[
assume
would
【在 A********3 的大作中提到】 : 1. Write a function that takes an array of five integers, each of which : is between 1 and 10, and returns the number of combinations of those : integers that sum to 15. For example, calling the function with the array [ : 1, 2, 3, 4, 5] should return 1, while calling it with [5, 5, 10, 2, 3] : should return 4 (5 + 10, 5 + 10, 5 + 5 + 2 + 3, 10 + 2 + 3). You may assume : that the input has already been validated. Show how you would test this : function. : 2. Write a function to shuffle a deck of 52 c
| A********3 发帖数: 45 | 3 谢谢variant,顶上去,看看有没有对第三题有点想法地。 |
|