Jow Forums Interview

Hello user,

Looks like you had trouble in round 3 of our interviewing process, so we're gonna give you another chance here in the fourth round.

Write a function that takes in a positive integer N and outputs True if there exists two PRIME numbers A and B such that A + B = N, otherwise it returns False.

For example:

Input: 8
Output: True because 3 + 5 = 8

You should be able to do this, user

Attached: dilbert23n-2-web.jpg (750x461, 31K)

Other urls found in this thread:

play.golang.org/p/7-XM_nsozeI
pastebin.com/5FN7Q6c3
twitter.com/NSFWRedditGif

Clarify: Two distinct primes? Because 4: 2+2.

no not necessarily distinct, 2+2 is fine and should be True.

return isSumOfTwoPrimeNumbersNotNecessarilyDistinct(n)

Unfortunately, we have decided to move forward with a few other candidates whose backgrounds better align with our current needs.

Jokes on you faggot I'm a nurse practitioner.

bump

if n

>Violently shits CDif all over the bed
Yeah, you really got me man. Now can you get to work over here?

int isPrime(int possiblePrime){
if(possiblePrime < 2)
return 0;

if(possiblePrime == 2)
return 1;

if(possiblePrime % 2 == 0)
return 0;

int i;
for(i = 3; i * i

jesus christ that's hideous

this is a trick question? how can you check all primes?

what's wrong with it

I'd move the check to include 2 and 3 mod, change the loop to start at i and also cache the numbered results so the longer you go the faster it gets at cost of ram

#include
using std::vector
bool primesum(size_t N){
vector primes(N);
primes.flip();
primes[0]=false;
primes[1]=false;
for(size_t i = 2; i

>Write a function that takes in a positive integer N and outputs True if there exists two PRIME numbers A and B such that A + B = N, otherwise it returns False.

>Goldbach's conjecture is one of the oldest and best-known unsolved problems in number theory and all of mathematics. It states:

> Every even integer greater than 2 can be expressed as the sum of two primes.

so you want me to solve the goldbach conjecture. are you retarded? if i could i wouldn't be working for your sorry ass.

Your isPrime can trivially be made faster by a factor of 2/3
bool isPrime(int possiblePrime){
if(possiblePrime < 2)
return false;
if(possiblePrime < 4)
return true;
if(possiblePrime % 2 == 0)
return false;
if(possiblePrime % 3 == 0)
return false;

const int next[2]={2,4};
int index = 1;
for(int i = 5; i * i

Okay it's me again... just had a go at this in JS. Is this correct? t. programming noob

function checkPrime(num) {

for (var a = 0; a < num; a++) {
for (var b = 0; b < num; b++) {
if (a + b === num) {
for (var i = 1; i

def gen_primes(limit):
...

def is_prime(primes, n):
...

def is_sum_of_primes(n):
primes = gen_primes(n)
for p in primes:
if p > n/2:
break
if is_prime(primes, n-p):
return True
return False

Pleb, your isPrime can trivially be made faster by a factor of 4/5

bool isPrime(int possiblePrime){
if(possiblePrime < 2)
return false;
if(possiblePrime < 4)
return true;
if(possiblePrime == 5)
return true;
if(possiblePrime % 2 == 0)
return false;
if(possiblePrime % 3 == 0)
return false;
if(possiblePrime % 5 == 0)
return false;

const int next[8]={2, 6, 4, 2, 4, 2, 4, 6};
int index = 1;
for(int i = 7; i * i

8 as an argument in this case would return False because isPrime(6) would return False, even though OP's example states that 8 as an argument should return True.

return True


It's always true.

wait wtf. I just ran a loop to go through 1000 of these and they all returned true...

pic related

wtf is the point of this exercise. i feel trolled

Attached: Screen Shot 2018-04-07 at 17.30.49.png (210x1340, 20K)

11

True. How did you not get this?

return !isPrime(n)
All numbers not prime can be expressed as the sum of two primes. Did none of you take discrete?

Fails on 5 as an input. Nice going Rajeet.

Conjecture != theorem

Many prime numbers can also be expressed as the sum of two primes though.

5 is a prime jamal

Bam, solved in the beginning!

27, 35, 65, 77, 95, ...

Attached: 1414826685835.jpg (760x728, 103K)

5 is also the sum of 2 and 3

>All numbers not prime can be expressed as the sum of two primes.

what two primes add to 27, please tell me o great sage

Why &= 7 ?

So this became a board where jobless neets help pajeets to get a job for free and then bitch about pajeets working in the industry. You are so smart Jow Forums Jesus.... Why not talk about algorithms and not giving a Rajesh answer straight away. Let them learn something in the process at least.

proof of the general case != doing it for one number

were you born retarded, or did you grow into it?

you did it wrong faggot

11 is not the sum of two primes.

OP here

This was actually a question for my most recent interview, which I already finished.

>you can only pass one number into the function

you're the retarded one.

>nurse (male)

bool interview(int N) {
return N>2 && !N%2;
}

Attached: [HorribleSubs] Uma Musume - Pretty Derby - 01 [1080p].mkv_snapshot_11.48_[2018.04.01_14.26.17].jpg (1500x952, 203K)

Does not work for an input of 8. It was even provided in the OP. How much of a Pajeet can you be?

because it's 240 times faster than %=8

>Does not work for an input of 8.
Dumb nigger

Attached: [HorribleSubs] Uma Musume - Pretty Derby - 01 [1080p].mkv_snapshot_18.52_[2018.04.01_14.37.02].jpg (1920x1080, 182K)

9 is not prime

#include
#include

#define true 1
#define false 0

int is_prime(int n);
int create_list(n);
int is_sum(int n);

int *prime_list;
int n;

main()
{
printf("%s","Enter a number);
scanf("%d",n);
create_list(n);
if( is_sum(n) ) printf("%s","true)
else printf("%s","false")
}

int is_prime(int n)
{
int i;
for(i = 2 ; i

til Jow Forums can't code

Ahhh I feel retarded lol. Just had dinner and realised y mistake. here is correct JS implementation;

function checkPrime(num) {

for (var a = 0; a < num; a++) {
for (var b = 0; b < num; b++) {
if (a + b === num) {

for (var y = 2; y < a; y++) {
if (a % y === 0 && a !== y) {
return false;
}
}

for (var x = 2; x < b; x++) {
if (b % x === 0 && b !== x) {
return false;
}
}

return true;

}
}
}
}

>int
>not bool

>int i;
>for(i = 2

What is this faggotry? Get the fuck out of my office.

Let's go through this one step at a time Ranjit.
Is 8 > 2?
Is 8 odd?

1 isn't prime dumbass

>!N%2
>odd
Delete your post, then your life

Attached: DZuJcheWsAA4YYM.jpg (1200x675, 137K)

Does not work for 5. Kill yourself Ranjit.

>posts clearly incorrect solution
>tells others to delete their post
The british colonization of India was a mistake.

Isn't that compiler's job? Are you making your code less readable on purpose?

return !5%2;

false

I'm serious now. You've dug yourself too deep. Just. End. It.

Attached: [HorribleSubs] Uma Musume - Pretty Derby - 01 [1080p].mkv_snapshot_19.06_[2018.04.01_14.37.25].jpg (1920x1080, 251K)

Honestly this thread has convinced me taking a course in mathematics in much wiser

what am I doing here and where I am, wtf

What is 2 + 3 Rajit?

1. bitmasks are obvious
2. compiler can't help you when you start using custom types without overloaded operators

Less than N

package main

import "fmt"

func PrimeLUT(n int) map[int]bool {
var lut []int
lut = append(lut, 2, 3)
plut := make(map[int]bool)
plut[1], plut[2], plut[3] = true, true, true
for i := 4; i < n; i++ {
prime := true
for j := 0; j < len(lut); j++ {
if rem := i % lut[j]; rem == 0 {
//fmt.Println("rem ", i, lut[j], rem)
prime = false
}
}
if prime {
lut = append(lut, i)
}
plut[i] = prime
//fmt.Println("is ", i, " prime? ", prime)
}
return plut
}

func hasPrimes(n int) bool {
plut := PrimeLUT(n)
//fmt.Println(plut)
prime := false
for i := 1; i < (n/2 + 1); i++ {
j := n - i
prime = plut[i] && plut[j]
fmt.Printf("Numbers %v and %v, are both prime? %v\n", i, j, prime)
if prime {
break
}
}
return prime
}

func main() {
n := 13000 // ENTER N HERE
fmt.Println("We're checking out ",n,"!")
prime := false
switch {
case n < 11:
prime = true
//case n%2 != 0:
// prime = false
default:
prime = hasPrimes(n)
}
fmt.Println("Does ", n, " have prime summands? ", prime)
}

play.golang.org/p/7-XM_nsozeI

Not a CS guy, is there a way to make this run in less than O(N^2)?

ANSI C best C.

You may as well be programming with vacuum tubes grandpa. We GenZ++20 now.

I can't really guess what's happening in that code but if you get all prime numbers up to N sorted, you can test if any two of them sum up to N in linear time (respective to the number of primes which is obviously smaller than O(n)). With sieve of Eratosthenes you can apparently easily get the primes in O(n (log n) (log log n)) time (I don't really remember that stuff so I just copied the complexity from Wikipedia).

Nice. Didn't know prime number sieves were a thing.

So is the lookup table approach (,
,) faster than this "bitmask" stuff like ?

>bool in C
why when you have char

#include
#include
#include

#define true 1
#define false 0

int is_prime(int n);
void create_list(int n);
int is_sum(int n);

int *prime_list;
int n;

main()
{
printf("%s","Enter a number \n");
scanf("%d",&n);
create_list(n);
if( is_sum(n) == true ) {
printf("%s","true");
}else printf("%s","false");
//free(prime_list);
}

int is_prime(int n)
{
int i;
for(i = 2 ; i

package chan4;

public class PrimesSum {

public int[] getTwoPrimes(int x) {
int numb = x / 2 + 1;
while (numb > 1) {
if (isItPrime(numb) && isItPrime(x - numb)) {
break;
}
numb--;
}
int result[] = new int[2];
result[0] = numb;
result[1] = x - numb;
return result;
}

private boolean isItPrime(int numb) {
if ((numb != 2 && numb != 3) && ((numb / 2 == 0) || (numb / 3 == 0))) {
return false;
}
int tmp = numb - 1;
while (tmp > 1) {
if (numb / tmp == 0) {
return false;
}
tmp--;
}
return true;
}
}

I am an idiot.
package chan4;

public class PrimesSum {

public int[] getTwoPrimes(int x) {
int numb = x / 2 + 1;
while (numb > 1) {
if (isItPrime(numb) && isItPrime(x - numb)) {
break;
}
numb--;
}
int result[] = new int[2];
result[0] = numb;
result[1] = x - numb;
return result;
}

public boolean isItPrime(int numb) {
if ((numb != 2 && numb != 3) && ((numb % 2 == 0) || (numb % 3 == 0))) {
return false;
}
int tmp = numb - 1;
while (tmp > 1) {
if (numb % tmp == 0) {
return false;
}
tmp--;
}
return true;
}
}

Here's the code:
#include
#include
#include


bool isPrime(unsigned int N)
{
if(N

Attached: Sebas_004.png (1366x768, 1.32M)

You're the same guy that posted the other threads? Were you actually asked all of these questions in an interview?

Hideous, I know. Python, I know.

But I am not a coding monkey and I don't have desire to be one. Plus, it seems to be working.

def isPrime(n):
if n < 2:
return False
elif n == 2 or n == 3:
return True
for i in range(2,n):
if n % i == 0:
return False
return True

def findSum(L, n):
for i in range(len(L)):
j = i
while True:
try:
sum = L[i] + L[j]
if sum > n:
sum = 0
break
elif sum < n:
sum = 0
j += 1
elif sum == n:
return (True, L[i], L[j])
except:
if i == len(L):
return False
else:
break
return False

def g(n):
listPrimes = []
for i in range(n):
if isPrime(i):
listPrimes.append(i)
return findSum(listPrimes, n)

2 or 3 ( I don't remember) including this one were interview questions, none of them on-site.

import math


class Primes:
sieve = [False, False]

@staticmethod
def eratosthenes(limit):
if len(Primes.sieve) > limit:
return

missing = limit - len(Primes.sieve) + 1
Primes.sieve += [True] * missing

root = int(math.sqrt(limit))

for a in range(2, root + 1):
if not Primes.sieve[a]:
continue

for b in range(a * a, limit + 1, a):
Primes.sieve[b] = False

@staticmethod
def is_prime(n):
Primes.eratosthenes(n)

return Primes.sieve[n]

@staticmethod
def generate(limit):
Primes.eratosthenes(limit)

for n, v in enumerate(Primes.sieve[0 : limit + 1]):
if v:
yield n


def interview(n):
for p in Primes.generate(n):
if Primes.is_prime(n - p):
return True

return False


for n in range(20):
print(n, interview(n))

Fite me faggots

Attached: 1520888289684.jpg (412x430, 24K)

what's with the decorations? Having objects out the ass isn't enough?
>tfw try to know as little python as possible

It's because Python's implementation of OOP is worse than PHP's.

Would someone care to assist me with my createrandarr func?
// Create an int array of 100 elements
// check whether each element in the array is prime or not

#include
#include
#include // to create a random array

int isprime(int);
int *createintarray(int);
int *createrandarr(int);

int main(){

int i = 0;
int flag = 0;
int size = 100;
int *ptr = createintarray(size);
// int *ptr = createrandarr(size);

// function test
flag = isprime(75);
printf("%p\n%d\n", ptr, *ptr);
printf("%d\n", flag);

while(*(ptr+i)

Yeah Rajesh I so believe you. Why didn't you put what you wrote? Your line of reasoning? You finished it already? So why didn't you phrase your question like that?

This kind of shit is why I'm trying to learn go. Honestly I've been liking it so far, the main design problem with the language is that it's somewhat verbose with a lot of reused boilerplate that should already have functions in the standard library, like
if err != nil{
fmt.Println(err)
}

all. over. the. place.

Other than that, I'm mostly hurting from the lack of a REPL and the lack of the advanced, well-polished packages that Python has.

Proper C doesn't have bool you degenerate

I hope this is okay. It seems to work.
It took a little over a minute to generate all primes up to 100 million, but checking everything lower after that was pretty quick.
>Error: Too many lines
fuck you moot.
pastebin.com/5FN7Q6c3

Attached: 1493268912270.png (592x2016, 151K)

8 % 2 = 0
> Returns true
Wut lol

Why the fucking fuck are you implementing pow and sqrt yourself?

return n > 3 && n % 2 == 0;

prove me wrong :^)

>return 4 > 3 && 4 % 2 == 0 --> true
Can you tell me how to get 4 with a sum of two prime numbers please? :^)

8

For fun, why else? I'd implement vectors myself too, but that seems like a lot of work just to shitpost on Jow Forums

read the thread, you've been proven wrong several times already.
it fails on 5, 7, 9, 13, etc. Think before posting next time.

Do you fucking know what a prime number is?

Attached: blackmanquestioning.jpg (406x304, 47K)

now write it in assembly code

My quick solution in Python.


def isPrime(n):
"""
Returns primality of n
"""
...


def generatePrimes(n):
"""
Returns list of primes less than n
"""
...


def solution(n):
lookup = {}
primes = generatePrimes(n)

have = 0
need = 0

for prime in primes:
have = prime
need = n - prime

lookup[have] = need

if need in lookup.keys():
return True

return False

To allow only distinct solutions (a!=b), only add numbers to the dictionary if they aren't already in the keys. i.e.

if need in lookup.keys():
return True
else:
lookup[have] = need


I think this is right but I haven't a fucking clue lol

#include
#include

bool IsSumOfPrimes(int input) {
int result = 0;

if(input == 0 || input == 1) {
return false;
}

for(int i = 2; i

Can you remind me what a prime number is again? Thanks

def isPrime(n):
kill(yourself)
return True

49?

Any number that has no other multiples outside of 1 and itself.

7 and 7. It's literally a perfect square.

Holy fuck I'm retarded

#include
#include

bool IsPrime(int input) {
for(int i = 2; i < input; i++) {
if(input % i == 0) {
return false;
}
}
return true;
}

bool IsSumOfPrimes(int input) {
int result = 0;

if(input

This is more advanced fizzbuzz

If even return true, if odd return true if n-2 is prime. This will work in every case