由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Epic 店面被考到coding的题目。。。(面经)
相关主题
Google面试回来讨论一道经典题
发个Yahoo onsite面经,攒人品,求bless!! executive committee用rand5()产生rand7()
random numbersAmazon On-site 面经+求bless,快两周了还没消息。
Groupon面筋。。。。从rand5 求rand7
请教一道面试题问问一道关于概率的题
如果给随即函数rand[1,5] 如何产生rand[1,7]yelp 面经
问个随机数的问题给一个 [0, 1]区间上的 uniform distribution
看不懂careercup上一题的答案今天的G电面面经
相关话题的讨论汇总
话题: rand1话题: rand话题: epic话题: rand8话题: rand5
进入JobHunting版参与讨论
1 (共1页)
p****z
发帖数: 55
1
我看了一下所有的epic面经,没有人被考过coding的题目。。。为什么被考了一个!!!
经典的面经就不提了,大家都很雷同,我就说个coding的题目吧!
题目:
一个random输出1-5的函数,怎么可以改成输出1-8?
p****y
发帖数: 405
2
Epic is which company?
p****z
发帖数: 55
3

跟我第一次听到这个名字的时候感觉一样!我进去工作过,不知道。。。大概是一个医
疗软件公司!

【在 p****y 的大作中提到】
: Epic is which company?
k****n
发帖数: 1334
4
这个也是老题了,四年前这里讨论的火热

!!

【在 p****z 的大作中提到】
: 我看了一下所有的epic面经,没有人被考过coding的题目。。。为什么被考了一个!!!
: 经典的面经就不提了,大家都很雷同,我就说个coding的题目吧!
: 题目:
: 一个random输出1-5的函数,怎么可以改成输出1-8?

c********t
发帖数: 5706
5
round ( f()/5 *8)?

!!

【在 p****z 的大作中提到】
: 我看了一下所有的epic面经,没有人被考过coding的题目。。。为什么被考了一个!!!
: 经典的面经就不提了,大家都很雷同,我就说个coding的题目吧!
: 题目:
: 一个random输出1-5的函数,怎么可以改成输出1-8?

p****y
发帖数: 405
6
why use round? Just f()/5*8?

【在 c********t 的大作中提到】
: round ( f()/5 *8)?
:
: !!

a********m
发帖数: 15480
7
老题了。
f()输出整数。

【在 c********t 的大作中提到】
: round ( f()/5 *8)?
:
: !!

c********t
发帖数: 5706
8
要整数啊

【在 p****y 的大作中提到】
: why use round? Just f()/5*8?
c********t
发帖数: 5706
9
又想想,不对啊,没法得到7,就更谈不上 RANDOM了,求解

【在 a********m 的大作中提到】
: 老题了。
: f()输出整数。

r*******y
发帖数: 1081
10
sampling rejection?

!!

【在 p****z 的大作中提到】
: 我看了一下所有的epic面经,没有人被考过coding的题目。。。为什么被考了一个!!!
: 经典的面经就不提了,大家都很雷同,我就说个coding的题目吧!
: 题目:
: 一个random输出1-5的函数,怎么可以改成输出1-8?

相关主题
如果给随即函数rand[1,5] 如何产生rand[1,7]讨论一道经典题
问个随机数的问题用rand5()产生rand7()
看不懂careercup上一题的答案Amazon On-site 面经+求bless,快两周了还没消息。
进入JobHunting版参与讨论
g*****i
发帖数: 2162
11
好像经典书里有,答案是不是(f()*5+f())%8+1
q*****9
发帖数: 85
12
int rand8(){
int tmp = 0;
if((tmp=rand5()+rand5()+rand5()+...rand5())<=5)//eight
return 1;
else if(tmp<=10)
return 2;
......
}
p*****y
发帖数: 1386
13
给了你几分钟考虑?这个要马上说答案还是很难啊!

!!

【在 p****z 的大作中提到】
: 我看了一下所有的epic面经,没有人被考过coding的题目。。。为什么被考了一个!!!
: 经典的面经就不提了,大家都很雷同,我就说个coding的题目吧!
: 题目:
: 一个random输出1-5的函数,怎么可以改成输出1-8?

t******h
发帖数: 37
14
a little bit off, 5f+f has 25 possiblities, need to remove 1

【在 g*****i 的大作中提到】
: 好像经典书里有,答案是不是(f()*5+f())%8+1
p*****y
发帖数: 1386
15
恩,f()*5+f()以后remove 6 or 30就行了

【在 t******h 的大作中提到】
: a little bit off, 5f+f has 25 possiblities, need to remove 1
t******h
发帖数: 37
16
yeah
saw another funny solution today, having a 5x5 matrix fillup with (1-8)*
3times, 0*1time
then
r1_8=0
while (r1_8==0)
r1_8 = matrix[rand(5)-1][rand(5)-1];

【在 p*****y 的大作中提到】
: 恩,f()*5+f()以后remove 6 or 30就行了
g*****i
发帖数: 2162
17
原来如此,只要生成的不是目标的公倍数,就要检查下头尾,去掉一些余数一样的.

【在 t******h 的大作中提到】
: a little bit off, 5f+f has 25 possiblities, need to remove 1
c****p
发帖数: 6474
18
这个是错的

【在 q*****9 的大作中提到】
: int rand8(){
: int tmp = 0;
: if((tmp=rand5()+rand5()+rand5()+...rand5())<=5)//eight
: return 1;
: else if(tmp<=10)
: return 2;
: ......
: }

p****y
发帖数: 405
19
怎么remove啊?就是如果生成的是30把它忽略?那得重复运行?

【在 p*****y 的大作中提到】
: 恩,f()*5+f()以后remove 6 or 30就行了
w******g
发帖数: 313
20
随到1,2,3,4就看奇偶,随到5重新扔,这样概率是1/2.三个一组就生成1/8的概率发
生器。

!!

【在 p****z 的大作中提到】
: 我看了一下所有的epic面经,没有人被考过coding的题目。。。为什么被考了一个!!!
: 经典的面经就不提了,大家都很雷同,我就说个coding的题目吧!
: 题目:
: 一个random输出1-5的函数,怎么可以改成输出1-8?

相关主题
从rand5 求rand7给一个 [0, 1]区间上的 uniform distribution
问问一道关于概率的题今天的G电面面经
yelp 面经MS, GOOGLE, FACEBOOK面经
进入JobHunting版参与讨论
g*****k
发帖数: 623
21
right, so if it is real radom, you might get infite loop

【在 p****y 的大作中提到】
: 怎么remove啊?就是如果生成的是30把它忽略?那得重复运行?
t******h
发帖数: 37
22
typo? if it is NOT real random...

【在 g*****k 的大作中提到】
: right, so if it is real radom, you might get infite loop
t******h
发帖数: 37
23
yeah,
it's easy mistake
rand(5)*7+rand(5) distributes different than rand(5)+rand(5)+...(
rand5) //8times

【在 c****p 的大作中提到】
: 这个是错的
m********l
发帖数: 4394
24
不能 f() + f() % 8 吗?
他们没要求uniform distribution啊
=====
我想Epic就是要这个答案。
快, 易懂。 有Bug就让以后的人来改。

!!

【在 p****z 的大作中提到】
: 我看了一下所有的epic面经,没有人被考过coding的题目。。。为什么被考了一个!!!
: 经典的面经就不提了,大家都很雷同,我就说个coding的题目吧!
: 题目:
: 一个random输出1-5的函数,怎么可以改成输出1-8?

t******h
发帖数: 37
25
even if they don't ask, you won't risk that...

【在 m********l 的大作中提到】
: 不能 f() + f() % 8 吗?
: 他们没要求uniform distribution啊
: =====
: 我想Epic就是要这个答案。
: 快, 易懂。 有Bug就让以后的人来改。
:
: !!

m********l
发帖数: 4394
26
你太高估了Epic了,呵呵
好, Uniform 大概可以
f() + f() + ... + f() eight times % 8 + 1

【在 t******h 的大作中提到】
: even if they don't ask, you won't risk that...
t******h
发帖数: 37
27
check my previous post, f()+f() eight times is NOT evenly distributed
you can use 7*f()+f()...

【在 m********l 的大作中提到】
: 你太高估了Epic了,呵呵
: 好, Uniform 大概可以
: f() + f() + ... + f() eight times % 8 + 1

m********l
发帖数: 4394
28
good point.
how about this:
int rand1()
{
int i = (f() - 1)/ 2;
if (i > 1)
return rand1();
return i;
}
rand8 =
rand1() + rand1() + ... + rand1() seven times + 1

【在 t******h 的大作中提到】
: check my previous post, f()+f() eight times is NOT evenly distributed
: you can use 7*f()+f()...

p****z
发帖数: 55
29

随便说了一个,他好像也没care我的答案到底怎么样。。。

【在 p*****y 的大作中提到】
: 给了你几分钟考虑?这个要马上说答案还是很难啊!
:
: !!

q******8
发帖数: 848
30
这还不经典
相关主题
面经amazon, epic, bloomberg, gs, macquarie发个Yahoo onsite面经,攒人品,求bless!! executive committee
发我的第一次电话面试random numbers
Google面试回来Groupon面筋。。。。
进入JobHunting版参与讨论
R****i
发帖数: 104
31

You will get a Gaussian distribution if you add several f()s together.

【在 m********l 的大作中提到】
: 你太高估了Epic了,呵呵
: 好, Uniform 大概可以
: f() + f() + ... + f() eight times % 8 + 1

m********l
发帖数: 4394
32
yes...
then:
int rand1()
{
int i = (f() - 1)/ 2;
if (i > 1)
return rand1();
return i;
}
rand8 = 1^rand1() + 2^rand1() + 4^rand1() + 1
can someone double check it?

【在 R****i 的大作中提到】
:
: You will get a Gaussian distribution if you add several f()s together.

h*****n
发帖数: 61
33
do you mean rand8 = 1*rand1() + 2*rand1() + 4*rand1() + 1 ?

【在 m********l 的大作中提到】
: yes...
: then:
: int rand1()
: {
: int i = (f() - 1)/ 2;
: if (i > 1)
: return rand1();
: return i;
: }
: rand8 = 1^rand1() + 2^rand1() + 4^rand1() + 1

m********l
发帖数: 4394
34
no, i meant "power"
^ = ** = pow()

【在 h*****n 的大作中提到】
: do you mean rand8 = 1*rand1() + 2*rand1() + 4*rand1() + 1 ?
m********l
发帖数: 4394
35
对, 是乘
rand() + 2 * rand() + 4 * rand() + 1

【在 m********l 的大作中提到】
: no, i meant "power"
: ^ = ** = pow()

1 (共1页)
进入JobHunting版参与讨论
相关主题
今天的G电面面经请教一道面试题
MS, GOOGLE, FACEBOOK面经如果给随即函数rand[1,5] 如何产生rand[1,7]
面经amazon, epic, bloomberg, gs, macquarie问个随机数的问题
发我的第一次电话面试看不懂careercup上一题的答案
Google面试回来讨论一道经典题
发个Yahoo onsite面经,攒人品,求bless!! executive committee用rand5()产生rand7()
random numbersAmazon On-site 面经+求bless,快两周了还没消息。
Groupon面筋。。。。从rand5 求rand7
相关话题的讨论汇总
话题: rand1话题: rand话题: epic话题: rand8话题: rand5