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.
Unfortunately, we have decided to move forward with a few other candidates whose backgrounds better align with our current needs.
Gavin Reyes
Jokes on you faggot I'm a nurse practitioner.
Luke Cooper
bump
Asher Flores
if n
Jordan Miller
>Violently shits CDif all over the bed Yeah, you really got me man. Now can you get to work over here?
Robert Perez
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
Adrian Butler
jesus christ that's hideous
Owen Russell
this is a trick question? how can you check all primes?
Robert Cook
what's wrong with it
Justin Gomez
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
Jack Cook
#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
Jason Rivera
>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.
Zachary Brown
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
Jacob Jones
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
William Miller
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
Carson Diaz
Pleb, your isPrime can trivially be made faster by a factor of 4/5
const int next[8]={2, 6, 4, 2, 4, 2, 4, 6}; int index = 1; for(int i = 7; i * i
Dylan Cooper
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.
Aaron Thompson
return True
It's always true.
Nathan Russell
wait wtf. I just ran a loop to go through 1000 of these and they all returned true...
>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
Henry Watson
Why &= 7 ?
Elijah Gonzalez
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.
Isaiah Jackson
proof of the general case != doing it for one number
were you born retarded, or did you grow into it?
Dominic Rodriguez
you did it wrong faggot
11 is not the sum of two primes.
Colton Fisher
OP here
This was actually a question for my most recent interview, which I already finished.
Honestly this thread has convinced me taking a course in mathematics in much wiser
Gavin Mitchell
what am I doing here and where I am, wtf
Jackson Johnson
What is 2 + 3 Rajit?
Levi Richardson
1. bitmasks are obvious 2. compiler can't help you when you start using custom types without overloaded operators
Matthew Taylor
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) }
Not a CS guy, is there a way to make this run in less than O(N^2)?
Easton Hernandez
ANSI C best C.
Cooper Ross
You may as well be programming with vacuum tubes grandpa. We GenZ++20 now.
Anthony Hall
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).
Ethan Campbell
Nice. Didn't know prime number sieves were a thing.
So is the lookup table approach (, ,) faster than this "bitmask" stuff like ?
John Gray
>bool in C why when you have char
Levi Diaz
#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
Matthew Wright
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; }
You're the same guy that posted the other threads? Were you actually asked all of these questions in an interview?
Josiah Carter
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)
Logan Long
2 or 3 ( I don't remember) including this one were interview questions, none of them on-site.
Brody Sanchez
import math
class Primes: sieve = [False, False]
@staticmethod def eratosthenes(limit): if len(Primes.sieve) > limit: return
what's with the decorations? Having objects out the ass isn't enough? >tfw try to know as little python as possible
Joseph Carter
It's because Python's implementation of OOP is worse than PHP's.
Kevin Richardson
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)
Brody Lewis
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?
Easton Gonzalez
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.
Dominic Baker
Proper C doesn't have bool you degenerate
Nathan Wright
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