Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Last active January 3, 2020 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkphp/2893efd91b70171041ab4cb53625a93e to your computer and use it in GitHub Desktop.
Save thinkphp/2893efd91b70171041ab4cb53625a93e to your computer and use it in GitHub Desktop.
Goldbach's conjecture
<script>
import Title from './Title.svelte';
import Footer from './Footer.svelte';
const pkg = {
name: 'svelte',
version: 3,
speed: 'thinkphp',
website: 'http://thinkphp.github.com/'
};
let a = 2;
let out = ""
function isPrime(n) {
var prime = 1;
if(n == 1 || n == 0) return false;
for(i = 2; i <= Math.sqrt(n) && prime; i++) {
prime = ((n % i) != 0)
}
return prime;
}
function handlerClick() {
alert(Math.sqrt(a))
}
function handlerKeyUp() {
var i = 2;
out = ""
while(i <= a / 2) {
if(isPrime(i) && isPrime(a - i)) {
out += a + " = "+ i + ' + ' + (a - i) + "<br/>";
}
i++;
}
}
</script>
<style>
button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
p {
font-size: 40px;
color: violet
}
</style>
<Title name={pkg.name} version={pkg.version} speed={pkg.speed} website={pkg.website}/>
<input type="numeric" bind:value="{a}" on:keyup="{handlerKeyUp}"/>
<button on:click="{handlerClick}">Goldbach</button>
<p>{@html out}</p>
<Footer />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment