6 kyu

Goldbach's Conjecture

180 of 515rsalgado

Description:

Goldbach's conjecture is amongst the oldest and well-known unsolved mathematical problems out there. In correspondence with Leonhard Euler in 1742, German mathematician Christian Goldbach made a conjecture stating that:

"Every even integer greater than 2 can be written as the sum of two primes"

which is known today as the (strong) Goldbach's conjecture.

Even though it's been thoroughly tested and analyzed and seems to be true, it hasn't been proved yet (thus, remaining a conjecture.)

Your task is to implement the function in the starter code, taking into account the following:

  1. If the argument isn't even and greater than two, return an empty array/tuple.
  2. For arguments even and greater than two, return a two-element array/tuple with two prime numbers whose sum is the given input.
  3. The two prime numbers must be the farthest ones (the ones with the greatest difference)
  4. The first prime number must be the smallest one.

A few sample test cases:

checkGoldbach(2)/check_goldbach(2) should return []

checkGoldbach(5)/check_goldbach(5) should return []

checkGoldbach(4)/check_goldbach(4) should return [2, 2]

checkGoldbach(6)/check_goldbach(6) should return [3, 3]

checkGoldbach(14)/check_goldbach(14) should return [3, 11]

Algorithms
Number Theory

Stats:

CreatedMay 20, 2014
PublishedMay 20, 2014
Warriors Trained1184
Total Skips80
Total Code Submissions3022
Total Times Completed515
JavaScript Completions180
PHP Completions46
Ruby Completions45
Elixir Completions17
Python Completions218
Go Completions13
Rust Completions17
D Completions4
C Completions18
Haskell Completions9
Total Stars34
% of votes with a positive feedback rating94% of 151
Total "Very Satisfied" Votes135
Total "Somewhat Satisfied" Votes13
Total "Not Satisfied" Votes3
Total Rank Assessments9
Average Assessed Rank
6 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • rsalgado Avatar
  • donaldsebleung Avatar
  • kazk Avatar
  • JohanWiltink Avatar
  • rowcased Avatar
  • cliffstamp Avatar
  • ejini战神 Avatar
  • akar-0 Avatar
Ad