-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d34c65d
commit ede6c2e
Showing
6 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
eBL-backend/src/main/java/com/info7255/ebl/config/FusekiConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.info7255.ebl.config; | ||
|
||
import org.apache.jena.fuseki.main.FusekiServer; | ||
import org.apache.jena.query.Dataset; | ||
import org.apache.jena.tdb.TDBFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class FusekiConfig { | ||
|
||
@Value("${fuseki.port}") | ||
private int port; | ||
|
||
@Value("${fuseki.datasetPath}") | ||
private String datasetPath; | ||
|
||
@Bean(initMethod = "start", destroyMethod = "stop") | ||
public FusekiServer fusekiServer() { | ||
Dataset dataset = TDBFactory.createDataset(datasetPath); | ||
return FusekiServer.create() | ||
.port(port) | ||
.add("/dataset", dataset) | ||
.build(); | ||
} | ||
|
||
|
||
} |
60 changes: 60 additions & 0 deletions
60
eBL-backend/src/main/java/com/info7255/ebl/service/Atkin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.info7255.ebl.service; | ||
|
||
import java.util.*; | ||
|
||
public class Atkin { | ||
|
||
public static List<Integer> findPrimes(int limit) { | ||
boolean[] isPrime = new boolean[limit + 1]; | ||
Arrays.fill(isPrime, false); | ||
|
||
// 2 and 3 are known primes | ||
isPrime[2] = true; | ||
isPrime[3] = true; | ||
|
||
for (int x = 1; x * x <= limit; x++) { | ||
for (int y = 1; y * y <= limit; y++) { | ||
int n = (4 * x * x) + (y * y); | ||
if (n <= limit && (n % 12 == 1 || n % 12 == 5)) { | ||
isPrime[n] = !isPrime[n]; | ||
} | ||
|
||
n = (3 * x * x) + (y * y); | ||
if (n <= limit && n % 12 == 7) { | ||
isPrime[n] = !isPrime[n]; | ||
} | ||
|
||
n = (3 * x * x) - (y * y); | ||
if (x > y && n <= limit && n % 12 == 11) { | ||
isPrime[n] = !isPrime[n]; | ||
} | ||
} | ||
} | ||
|
||
for (int n = 5; n * n <= limit; n++) { | ||
if (isPrime[n]) { | ||
for (int k = n * n; k <= limit; k += n * n) { | ||
isPrime[k] = false; | ||
} | ||
} | ||
} | ||
|
||
List<Integer> primes = new ArrayList<>(); | ||
for (int i = 2; i <= limit; i++) { | ||
if (isPrime[i]) { | ||
primes.add(i); | ||
} | ||
} | ||
|
||
return primes; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int limit = 50; | ||
|
||
List<Integer> primes = findPrimes(limit); | ||
System.out.println("Prime numbers up to " + limit + ":"); | ||
System.out.println(primes); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
eBL-backend/src/main/java/com/info7255/ebl/service/Eratosthenes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.info7255.ebl.service; | ||
|
||
import java.util.*; | ||
|
||
public class Eratosthenes { | ||
|
||
public static List<Integer> findPrimesInRange(int start, int end) { | ||
|
||
boolean[] isPrime = new boolean[end + 1]; | ||
Arrays.fill(isPrime, true); | ||
|
||
for (int i = 2; i * i <= end; i++) { | ||
if (isPrime[i]) { | ||
for (int j = i * i; j <= end; j += i) { | ||
isPrime[j] = false; | ||
} | ||
} | ||
} | ||
|
||
List<Integer> primes = new ArrayList<>(); | ||
for (int i = Math.max(2, start); i <= end; i++) { | ||
if (isPrime[i]) { | ||
primes.add(i); | ||
} | ||
} | ||
|
||
return primes; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int start = 10; | ||
int end = 50; | ||
|
||
List<Integer> primesInRange = findPrimesInRange(start, end); | ||
System.out.println("Prime numbers between " + start + " and " + end + ":"); | ||
System.out.println(primesInRange); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters