Job interview

>job interview
>white board walks in
>asked to sum all primes under two million

is /g/ leaking? is this the new fizzbuzz?

wtf lol

>prime interview
>job number walks in
>asks me to sum two million white;paojdsfhga;jlksdfhg;akj ghurrdurr i'm choking on a million dicks

I /g/post on /g/, and /pol/post on /pol. Please consider doing the same.

>job interview
>white board walks in
>realized im in the parallel world where people are white boards

i got the job btw

Besides the memes, is this something you can do in a white board?

>sum all primes under two million

[code]


accepted
your answer is 142913828922 but how?

I just changed your algorithm a little bit:

public static void main(String[] args) {

BigInteger sum = new BigInteger("2");
boolean isPrime = true;
for (int i=3; i

literally trivial

stupid frogposter

>java

FUCKING KILL YOURSELF

You should be able to do this in less than 3 minutes.

#include
#include

int main(){
std::vector composite;
composite.resize(2000000);
unsigned long long sum=0;
for(size_t i = 2; i

Sanjay? Rajeesh?

How did you know? Did copying pasting code from Stackoverflow into production give it away?

for(int i = 0; 2 million;){
if (i is not divisible by any smaller integers){sum += number;}

this code is horrendous

because what? bit vectors?

>job interview
>asked to show all non-trivial zeros of the riemann zeta function have real part equal to 1/2
>need to do it in O(nlogn) time

I just asked Wolframalpha.

The answer is 142913828922

You could estimate this by hand if you really wanted

There are around 149,000 primes less than 2 million
The sum of the first 149,000 primes is about 132325727548

This undershoots the real number by about 7%

i personally like it. A lot of sci/math would beinteresting with a programming aspect to it. The R/Python chart thread the other day was great

#ORIGINAL CODE DO NOT STEAL
#COPYRIGHT ANONYMOUS DISTRIBUTED EXCLUSIVELY ON /g/
#IF FOUND ELSEWHERE CONTACT ADMIN@Veeky Forums.ORG
from math import sqrt
from time import time
max_n = 2000000

def find_primes(n):
primes = [True]*(n+1)
for i in range(2, int(sqrt(n))+1):
if primes[i]:
for j in range(i**2, n+1, i):
primes[j] = False
return primes

def sum_primes(max_n):
primes = find_primes(max_n)
psum = 0
for i in range(2,max_n+1):
if primes[i]:
psum += i
return psum

niggers = time()
print(sum_primes(max_n))
print(time()-niggers)

what code quality do they want?
do they want some sort of mod sifting or do they just want some lazy isPrime() stuff

I know r is not really great for this stuff but here is my approach, it takes about 12 minutes for 2million, can somebody help me find a better way?

####Prime Number stuff
primegen=function(v){
return(
sapply(
v,function(z){sum(z/1:z==z%/%1:z)})==2)
}

##number until we are checking
nmax

>whiteboard interview
>prime walks in
>asks me to sum all the jobs under two million

>sum(primes(2000000))

one line in matlab.

[code]
int size = 2000000;
long sum = 0;

int[] primes = {2,3,5,7};

boolean[] isPrime = new boolean[size];
Arrays.fill(isPrime, true);

for(int i = 0; i < primes.length; i++){
for(int j = primes[i]*2; j < size; j+=primes[i]){
isPrime[j] = false;
}
}

for(int k = 2; k < size; k++){
if(isPrime[k] == true){
sum += k;
}
}
[/code]
Tried to actually do the sieve by hand. It can find all the primes but the sum is 457143142877. Anyone know why?

It's strange - while I do coding for a living, after reading OPs post, I didn't even think of that being a coding questions. I thought they wanted a mathematically motivated estimate.
I.e. using the prime number theorem

As a coding question, isn't this the same as asking for the implementation of a function
isPrime : Nat -> Bool
?

Julia:

using Primes
x=0
for i=1:2000000
if isprime(i)
x=x+i
end
end
print(x)

It also runs quite fast in under 0.5 seconds.

It honestly surprises me how awful matlab is at this.

x=0;

for i=1:2000000
if isprime(i)==true
x=x+i;
end
end
disp(x)

takes about 50 seconds, what are these people doing?

>Stage 1 of job interview
>It's a one way interview through webcam
>I'm given 30 seconds to read a question, 3 minutes to answer
>It's all behavioral questions
>Without another person being part of the conversation it's awkward as hell
>No way to tell when I've said enough, end up rambling even though I'm trying not to
>The entire time I have to look at my stupid fucking face getting all autistic

God that was awful. Also did it last Friday and I haven't heard back yet. I really hope they didn't screen me out based on a fucking one way interview, that's bullshit.

Honestly the way employers treat job seekers today is unreal. I've put in like 23 job applications so far, and only gotten a response of any kind from 3. If these people treated clients the way they treated job applicants they'd be out of business in a week.

>but you're a programmer you should be comfortable alone in front of a computer

desu I didn't think it would be so fucking weird when I first got the email about the video interview, but the real experience was a shit show. You don't realize how much of an interview involves rapport with another human being, reading body language, etc, until it's taken away.

Overall I found it to be a really dehumanizing experience. Like it was too much of a burden for someone to have a 30 minute phone call with me instead.

I could see the one way video thing working if you were given the questions ahead of time, given time to formulate coherent answers rather than having to do it on the fly, and allowed multiple takes. But surprise questions with a single take is bullshit.

Also people have been complaining about this interview system on the company's Glassdoor for at least two years. They don't give a single shit.

>prime number
>all job boards under two million walk in
>asked to sum white interview

wait, so at this interview you're given a question in text for and are recorded for the employing to see and you don't see anyone from their side?

jesuschristhowhorrifying.golang

>sum all primes under two million
thats straight out of project Euler

No J?
>+/ i.@x:&.(p:^:_1) 1e6

>+/ sum
>i. i.n is the list 0,1,2,...,n-1
>@ compose
>x: convert to extended precision
>&. under; f&.g x is (ginverse f g)
>p: p: n is the n-th prime
>^:_1 inverse; p:^:_1 n is pi(n), the number of primes less than n

[math]\texttt{Total[Map[Prime, Range[PrimePi[2*^6]]]]}[/math]

>^:_1 inverse; p:^:_1 n is pi(n), the number of primes less than n
Is this symbolic or does it calculate the inverse on the fly? If the latter, how?

p:^:_1 is the Fixed Power dyad ^: applied to p: and _1, (which is how you write -1 in J)

u^:n, or ^: applied to u and n means apply u, n times, so ^:_1 means apply the Inverse or 'Obverse' of u. (you can even use infinity _ in it, n^:_ means apply n infinite amount of times, whcih it translates to apply n till the value converges)

The Obverse can be explicitly defined for a verb like u, and i think its explicitly defined for primitives like p:, but it can automatically calculate it for some user defined functions by reversing the order and inverting the used verbs (if possible)., but for something like the prime function its probably explicitly defined.

...

>it can automatically calculate it for some user defined functions by reversing the order and inverting the used verbs
Do you have an example of this? I can't imagine that being applicable outside of very constrained cases.

GSU ai = new GSU();
ai->solve("Help anons problem @

A text question pops up on screen. You have 30 seconds to think about the question, then one shot at recording your answer in a 3 minute window. No human interaction whatsoever.

>They don't give a single shit.

Because all employers use the same process to thin out the herd because universities are churning out more graduates than there are jobs every year.

Welcome to the New World Order, kid. Get used to it.

ITT all the people not using Julia to do this
kys

Engineer + matlab:
sum(primes(1e6))

STOP FORCING THIS MEME

They ask impossible questions to see how you handle stress and impossible questions, to see how you react. If you take out pen and paper and start writing down all the primes under 2 million, they will stop you.

>If you take out pen and paper and start writing down all the primes under 2 million, they will stop you.

Go on...

What happens next?

What happens if you actually do start writing down all the primes under 2 million?

you get the job

*unzip*

long result = 0;
for(int i = 0; i < 2000000; ++i) {
send_mail([email protected], "hi is " + to_string(i) + " a prime? thx");
string answer = receive_mail();
if(answer.find("yes") != string::npos) result += i;
}
cout

I cant think of any example, but any one to one function should be invertable, so any function built up of functions that have an inverse (most primitives), although some dont have true inverses, but use as close to an inverse as it can get, thus why its called an Obverse.

example {. y gives you the first element of an array y, obviously a true inverse doesn't exist but is obverse is ,: y which gives you an array with rank 1 more than y, with y its only item. so letting (a b c) mean an array {.(a b c) = a, but its inverse ,: a = (a) which isn't the original list, but as close as it can get with the available data.

you guys are all idiots. You can do this with pen and paper (and calculator i guess if your a brainlett) in less than 5 minutes.

If you know the prime counting formula [math] \pi(x) = \frac{x}{\ln x} [/math] you can easily manipulate it to get [math] SumPrimesUnder(x) = \frac{x^2}{2 \ln x} [/math].

for x = 2 000 000 the real sum is 1.42e11 and the above formula gives1.37e11.

kek

kek

Let me refactor your code

i = (sum of all prime numbers below 2 millon)
print(i)

Dumb ass

Your algorithm is retarded. Not only did you not use a sieve, but you did in the most retarded and inefficient possible way.

nice bait bro

>Counter primes under hundred and sum
>Multiply sum by 20000^3
>?????
>Profit

IF I SEE THAT FUCKING WHITE BOARD ONE MORE TIME...

>Hey guys lets go to Mars
>Yeah! I can get us within 7% of Mars!
>Uh wtf no you retard we have to get on Mars

is this the fastest implementation in python?

python is so fucking slow there isnt even a fastest implementation.

Did you misquote? It is a sieve and unlike many others who are blindly sieving and them summing, the sum is calculated inside the sieve saving an extra iteration of the list.

>142913828922
>1.533087968826294

def find_n_sum_primes(n):
primes = [True]*(n+1)
sum=0;
for i in range(2, int(sqrt(n))+1):
if primes[i]:
sum+=i
for j in range(i**2, n+1, i):
primes[j] = False
for i in range(int(sqrt(n))+1,max_n+1):
if primes[i]:
sum += i
return sum

niggers = time()
print(find_n_sum_primes(max_n))
print(time()-niggers)

>142913828922
>1.1510660648345947

>is /g/ leaking?
That explains the catheter thread we were treated to earlier.

it would be very painful

--------u---
------uu---
----u--u---
---u---u---
-uuuuuu-
--------u--
--------u--
--------u--
--------u---