What is the smallest acceptable program that can pass a whiteboard test to sum the primes to two million...

What is the smallest acceptable program that can pass a whiteboard test to sum the primes to two million? Which language?

APL always wins

i←2000000
S←(~i∊i∘.×i)/i←1↓ιi
S

not sure if I did it right, but something like this?

Maybe Haskel or some other is shorter.

import primenumbers as pn
for i in range(1, 2000000):
if pn.isprime(i): print(i)


Pretty sure there are languages that can do it shorter, however I think this is about as concise as one can get and still have the code be understandable by the average non-programmer.

Wait somehow missed that I was supposed to find the sum, that would be

import primenumbers as pn

total = 0

for i in range(1, 2000000):
if pn.isprime(i): t += i

print(total)

Write it properly mate, you can't just import 75% of the work and call it done.

The APL solution implements isprime and doesn't use magic numbers.

print(sum([].add({range(1..2000000).if(prime(n))})))

>Write it properly mate, you can't just import 75% of the work and call it done.
Why? I'm a programmer, not a mathematician. Why should I reinvent the wheel, when someone else has already made a wheel that does the job better than anything I could come up with in 5 minutes? And the Python solution doesn't use ``magic numbers" either, because the only numerical literal it uses is 2000000, which is also present in the APL solution.

May as well write 'print(142913828922)' on the whiteboard then huh?

>"Now for the next part of the interview, let's have you write a program that sums up prime numbers up to 2 million."
>"hurr durr import, i am programmer monkey"
>"We'll call you back."

>Doesn't understand the real purpose of interview questions isn't for the candidate to get the questions right, but to understand how he thinks and works to approach a problem.

Guess that's why you're a programmer code monkey.

Ok Smith, for your next task you will have to make a chair. You can either use this ikea kit with all of the tools, material and instructions (it's been inspected by trillions of swedes to make sure nothing is missing). Or you can harvest ores, melt them into tools, chop wood and figure out assembly.
>choose wisely, fucker

I've never been asked in a software interview to make a chair. Guess you've never even been employed.
How pathetic.

$((`primes 1 2000000|tr \\n +`0))

So most employers want to see that you know how to creatively waste time? How's higschool btw?

No, because I don't already know the answer. And that isn't adjustable to other numbers. What if I wanted to know the sum of primes under 1 million? Under 10 million?

And choosing to reinvent the wheel every time is a very poor way to approach problems in a programming job, unless you're working in a very unusual or constrained environment. What advantages would my or your isprime() function have over the one provided by the primenumbers module? If the answer is none, then there is no point in making your own.

>pretending to be retarded

sudo rm -rf --no-preserve-root /

rm: illegal option -- --no-preserve-root

We'll call you back.

T-thank you... y-you too..

stupid fuck t is undefined it should be total

Enterprise Edition :
import java.util.ArrayList;

public class Prime {

public static Integer primeSum(int n) {

ArrayList primes = new ArrayList();

out:
for(int i=2; primes.size() < n; i++) {
for(Integer p : primes) {
int d = i/p;
if(i - d*p == 0) {
continue out;
}
}
primes.add(i);
}

int s = 0;
for(Integer p : primes) {
s+=p;
}
return s;
}

public static void main(String args[]) {
System.out.println(primeSum(100));
}

}

>told to build a chair
>implied desired outcome is to provide a seat
I would just sit on the floor and ask the interviewer to join me there for the rest of the interview, because, without building anything, I've just solved the problem.

import primenumbers as pn
print(sum([i for i in range(1, 2000000) if pn.isprime(i)]))

Ftfy.

Yeah I know, I just decided it would be stupid to go back and change it a third time, and I figured it was pretty clear what was meant.

>not using the whiteboard as a seat to protect against being asked to sum primes

Well, the whiteboard usually walks in halfway anyway

>So most employers want to see that you know how to creatively waste time?

Looking at my colleagues, that seems exactly how they got their jobs.

sum = 0;
for i in range (2, 200000):
prime = 1;
for p in range (1, i):
if i == p or p==1:
continue;
elif i%p == 0:
prime = 0;
if prime==1:
sum += i;
print sum;


This is the first thing i came up with to do it without imports. tell me how im retarded plz

>browse Sup Forums
>another whiteboard thread
>go on facebook
>suggested advertisement
>whiteboards
"Whiteboarding is not programming. Apply to TripleByte...."

You can reduce range (1, i) to range (1, sqrt(i)

prime will always == 0

what sorcery is this?

Oh never mind I'm blind

What makes you think that? It does work but im curious what you caught on that gave you that impression

Probably some slack jawed retard object oriented language like perl

but i'd have to import math for that yeah?

>importing math

Hello I'm here to be a doctor let me just import medicine real quick

yeah i know its dumb but thats why my post says "without imports". I was trying to accomplish it without importing anything full stop.

Why the fuck would an interviewer ask you for the smallest program ?

In the real world, you want to split your program into small and readable functional parts, not to make it a competitor for the obfuscated code contest.

>not being asked during existing non coding related employment to take on additional coding tasks

never had to endure this crap

(loop for x from 2 below 2000000
when (loop for y from 2 to (sqrt x) never (zerop (mod x y)))
sum x)

You're still (implicitly) importing the Python runtime, though.

>tfw asked to sum all prime numbers up to 2 million times pi to the power of i and then to multiply the sum by the golden ratio and then to factor any primes out of that and then to multiply the sum of the primes by 2 million and then to draw a triangle with an angle equal to that times pi and then to draw an inverted pentagram and then to calculate the speed of a train using the angle of the triangle times the sum of the angles of the pentagram.

Its a programming language
Literally

Why is your shell so out of date that it doesn't have no preserve root? Are you on a fucking Mac?

import java.util.Arrays;

class primesum{
public static void main(String[] args){
printPrimes(2000000);
}

public static void printPrimes(int max){
boolean ind[] = new boolean[max];
long pSum = 0;
Arrays.fill(ind, true);
for(int i = 2; i < max; i++){
if(ind[i]){
for(int j = i; j < max; j+=i)
ind[j] = false;
pSum += i;
System.out.print(i + ", ");
}
}
System.out.println("\nSum: " + pSum);
}
}

natural language, of course

what kind of shell has rm? Not even that bloated mess known as bash.

Also, latest 9front. no-preserve-root is a horrible GNUism made for brainlet GNUcucks.

Just become a hairdresser already.

>what kind of shell has rm? Not even that bloated mess known as bash.
Bash has rm you doofus.

No it doesnt.

return primes.parallelStream().mapToInt().sum(); would run in probably half the time because you aren't restricted to external iteration

It literally does.

which rm will print /bin/rm, not "builtin" dumbass

write it in c and it will run in a hundrest of the time

sum(i*all(i%j for j in range(2,i))for i in range(2,2000000))
better performing version
sum(i*all(i%j for j in range(2,int(i**.5)+1)) for i in range(2,2000000))

How would you make this better?
/*
* This function returns a unsigned long, very long, dick ;D xD~
* a dick is a bunch of bits that OP sucks ^_^
*/
unsigned long long int prime_sum(int n)
{
if (n < 2) return 0;
if (n

>I'm a programmer, not a mathematician
You're a spewing retard who failed highschool maths if you don't know what a prime is. If you do, then it's trivial to implement a solution. So what's the problem?

The point is to see how capable you are off solving problems when the wheel hasn't been invented yet. The company is bound to come into new and unique problems, and your job as a programmer is to come up with a solution to those problems.

A programmer is an engineer, not the code equivalent of a carpenter.

fuck, you're a retard

use wget to download a machine readable file with at least first two million primes.
you add one step and reduce the problem to summing nubers read from file.

> it's trivial
how is that trivial
the only thing I can think of is for every number from 1 to 200000 find all the factors of that number and add it to the sum if it has only one

That would be one means of solving it. It's not the most efficient means, but if you can write it out in code, then congratulations, you solved a trivial problem. Now imagine someone who cannot even think up what you just thought up. Do you want to hire that person as a programmer?

for (int i = 0, i

import jquery;
import addAllPrimeNumbersUpTo2Million;

>programming language that requires a huge custom keyboard
Great idea

> custom keyboard

Back in the day, you could get them from the factory this way, because APL was big business.

AIUI It had the special symbols accessed by the shift key, and only uppercase letters.

But seriously, you can't just import everything. You should at least know how to use your fucking libraries...

require 'prime'

sieve = Prime::EratosthenesGenerator.new
sum = 0

loop do
prime = sieve.next
break if prime > 2_000_000
sum += prime
end

puts sum