Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Internship at facebook

Name: Anonymous 2012-03-18 16:46

Hi
this year i'm going to go on internship to Facebook. Has smb worked there? Any feedback?

Name: Anonymous 2012-03-18 18:10

That's cool, got any details about what you'll be doing yet?

Name: Anonymous 2012-03-18 18:45

>>1
Have you passed the technical interview yet? If not, you should be able to answer the following questions with no effort.

"Write a function sum2(n) that returns the sum of the of the binary digits in n. For example, sum2(7) should return 7."

If you, just most of /prog, requires more than 5 minutes to solve it, then I'd recommend that you take up something a tad bit easier. Like say, working a cash register at your local Target.

Name: Anonymous 2012-03-18 18:51

>>3
Correction. sum2(7) should return 3. This is because 7 in binary is 111. And the sum of 111 is 3.

Name: Anonymous 2012-03-18 18:52

>>4
looking at you and pointing at toilet and scrub brush

Name: Anonymous 2012-03-18 18:59

>>4
>>3 is a riddle. I'm still thinking about it

Name: Anonymous 2012-03-18 19:02

>>5
I can write a three line C/C++ function that would solve this problem.

Name: Anonymous 2012-03-18 19:05

>>6
To make life easier, just assume that it's a two complement machine and that the integer n is unsigned.

Name: Anonymous 2012-03-18 19:07

>>3
Write a function sum2(n) that returns the sum of the of the binary digits in n. For example, sum2(7) should return 7.
int sum2(n) {
     return n;
}

Name: Anonymous 2012-03-18 19:07

>>7
I forgot that you could probably google the answer. So I'm going to add the restriction that you can't have any kind of global and/or static variables in your solution.

Name: Anonymous 2012-03-18 19:09

>>9
Homegirl, read the corrected question.

Name: Anonymous 2012-03-18 19:13

unsigned sum2(unsigned n) {
     unsigned sum = 0;
     while (n) {
          sum += n&1;
          n >>= 1;
     }
     return sum;
}

Name: Anonymous 2012-03-18 19:27


unsigned int sum2(unsigned int n){
  unsigned int c;
  c = ((n & 0xfff) * 0x1001001001001ULL & 0x84210842108421ULL) % 0x1f;
  c += (((n & 0xfff000) >> 12) * 0x1001001001001ULL & 0x84210842108421ULL) % 0x1f;
  c += ((n >> 24) * 0x1001001001001ULL & 0x84210842108421ULL) % 0x1f;
  return c;
}

Name: Anonymous 2012-03-18 19:28

post+= >>12

兒子,你為什麼這樣一個令人失望 hat

Name: Anonymous 2012-03-18 19:31


unsigned int sum2(unsigned int n){
  unsigned int c;
  for (c = 0; n; c++) n &= n - 1;
  return c;
}

Name: Anonymous 2012-03-18 19:35

| *
so 0 isn't considered a binary digit

/prog/ ftw

Name: Anonymous 2012-03-18 21:05

>>16
>>3,4 said ``sum of the digits'' and not ``number of digits''. Zeroes do not change the value of a sum. printf("%d %d %d %d\n", sum2(6), sum2(7), sum2(8), sum2(5000)); should print 2 3 1 5 as >>12,13,15 do. Maybe >>3,4 should have given an example that wasn't all ones.

Name: Anonymous 2012-03-18 22:33

popcnt

FUCK YEAH CISC

Name: Anonymous 2012-03-18 22:36

>>18
popcunt

Name: Anonymous 2012-03-18 22:52

>>18
FUCH YEAH PowerPC IS CISC

Name: Anonymous 2012-03-19 0:04

Who would want to work for Zuckerberg?

Name: Anonymous 2012-03-19 1:37

>>3
yep, I passed interviews and now waiting for an offer. As far as I know from my recruiter interviews went well.

Name: VIPPER 2012-03-19 8:23

>>21
JEWS

Name: Anonymous 2012-03-19 8:33

>>23
VIPPER. Anti-semites also love the Zuckerberg.

Name: VIPPER 2012-03-19 10:54

>>24
But zuckberg is a semite, how can you love what you hate?

Name: Anonymous 2012-03-19 20:51

I'm not even able to program, but would this work? (python)

def sum2(n):
    answer=0
    for i in bin(n):
        if i =='1':
            answer=answer+1
    return answer

Name: Anonymous 2012-03-19 21:19

>>> from sum2 import sum2
>>> sum2(7)
7

Name: Anonymous 2012-03-19 21:58

>>25
Just as you say. Love what you hate. Hate what you love. It's all good.

Name: Anonymous 2012-03-19 21:59

>>27
use Trolls::Questions::Interview::Sum2;
print sum2(7);

Name: Anonymous 2012-03-22 3:58

bump

Name: Anonymous 2012-03-22 4:08

sum2 = lambda n : sum(int(i) for i in bin(7).lstrip('0b'))

Name: Anonymous 2012-03-22 4:16

sum2 = lambda n: 0 if n == 0 else n%2 + sum2(n/2)

Name: Anonymous 2012-03-22 5:44

slovakia my dubs

Name: Anonymous 2012-03-22 10:58

>>31
Beuargl.

Name: Anonymous 2012-03-31 3:25

bump lol

Name: Anonymous 2012-03-31 6:32

I finally got the position and now talking to their lawyer about visa, also chose team and technologies to work on. Ask questions.

Name: Anonymous 2012-03-31 6:38

what's your favorite type of pasta

Name: Anonymous 2012-03-31 7:04

>>37
spaghetti with cheese and bacon

Name: Anonymous 2012-04-04 14:06

bump?

Name: Anonymous 2012-04-05 1:58


#include <cstdio>

template <int T> struct hurf {
  static const int value = (T & 1) + hurf<T >> 1>::value;
};
template<> struct hurf<0> {
  static const int value = 0;
};

int main(int, char**) {
  printf("%d\n", hurf<7>::value );
  return 0;
}

Name: Anonymous 2012-04-05 7:35

>>40
Clearly this is the best way to count bits in C++

Name: Anonymous 2012-04-05 8:02

>>41
But... but... you can do it at compile time with zero run-time overhead! OMG OPTIMIZED

Don't change these.
Name: Email:
Entire Thread Thread List