Code Examples
A repository of 155 code examples for BeepBeep
Main Page
+
Packages
Packages
+
Classes
Class List
Class Index
Class Hierarchy
+
Class Members
+
All
a
e
g
h
i
m
n
r
t
v
w
+
Functions
a
g
m
r
t
v
Variables
+
Files
File List
package-info.java
1
/*
2
BeepBeep, an event stream processor
3
Copyright (C) 2008-2017 Sylvain Hallé
4
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published
7
by the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU Lesser General Public License for more details.
14
15
You should have received a copy of the GNU Lesser General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
/**
20
* Compute twin primes by distributing the computation
21
* across two machines over a network.
22
* <p>
23
* Twin primes are pairs of numbers <i>p</i> and <i>p</i>+2 such that both are
24
* prime. For example, (3,5), (11,13) and (17,19) are three such pairs. The
25
* <a href="https://en.wikipedia.org/wiki/Twin_prime">twin prime conjecture</a>
26
* asserts that there exists an infinity of such pairs.
27
* <p>
28
* In our setup, Machine A will be programmed to check if each odd number
29
* 3, 5, 7, etc. is prime. If so, it will send the number <i>n</i> to Machine B,
30
* which will then check if <i>n</i>+2 is prime. If this is the case, Machine B
31
* will print to the console the values of <i>n</i> and <i>n</i>+2.
32
* <p>
33
* The interest of this setup is that checking if a number is prime is an
34
* operation that becomes very long for large integers (especially with the
35
* algorithm we use here). By having the verification for <i>n</i> and
36
* <i>n</i>+2 on two separate machines, the whole processor chain can actually
37
* run two primality checks at the same time.
38
* <p>
39
* Note that this chain of processors is only meant to illustrate a possible
40
* use of the HTTP gateways. As such, it is not a very efficient way of finding
41
* twin primes: when <i>n</i> and <i>n</i>+2 are both prime, three primality
42
* checks will be done: Machine A will first discover that <i>n</i> is prime,
43
* which will trigger Machine B to check if <i>n</i>+2 also is. However, since
44
* Machine A checks all odd numbers, it will also check for <i>n</i>+2 in its
45
* next computation step. Could you think of a better way of using processors
46
* to make this more efficient?
47
* <p>
48
* A few things you might want to try:
49
* <ul>
50
* <li>Machine B's program depends on the numbers sent by Machine A. Therefore,
51
* if you stop Machine A and restart it, you will see Machine B starting the
52
* the sequence of twin primes from the beginning.</li>
53
* </ul>
54
* @author Sylvain Hallé
55
*/
56
package
network.httppush.twinprimes;
Source
src
network
httppush
twinprimes
package-info.java
Generated by
1.8.13