File tree 4 files changed +108
-0
lines changed
4 files changed +108
-0
lines changed Original file line number Diff line number Diff line change
1
+ FROM ubuntu:22.04
2
+
3
+ RUN apt-get update -qq \
4
+ && apt-get install -y squirrel3 \
5
+ && apt-get clean \
6
+ && rm -rf /var/lib/apt/lists/* \
7
+ && mkdir -p /usr/local/squirrel
8
+
9
+
10
+ COPY ["prime.nut" , "run.sh" , "/usr/local/squirrel/" ]
11
+
12
+ WORKDIR /usr/local/squirrel
13
+
14
+ ENTRYPOINT ["./run.sh" ]
Original file line number Diff line number Diff line change
1
+ class SieveClass {
2
+ bitArray = null ;
3
+ sieveSize = null ;
4
+ constructor (maxSize) {
5
+ bitArray = array (maxSize);
6
+ sieveSize = maxSize;
7
+ }
8
+
9
+ function GetBit (index)
10
+ {
11
+ return bitArray[index];
12
+ }
13
+
14
+ function runSieve ()
15
+ {
16
+ local factor = 3 ;
17
+ local sq = sqrt (sieveSize);
18
+
19
+ while (factor <= sq) {
20
+ for (local i = factor; i < sieveSize; i += 2 ) {
21
+ if (GetBit (i) == null ) {
22
+ factor = i;
23
+ break ;
24
+ }
25
+ }
26
+ local factordoubled = factor * 2 ;
27
+ for (local num = factor * factor; num < sieveSize; num += factordoubled)
28
+ {
29
+ bitArray[num] = 1 ; // ClearBit(num);
30
+ }
31
+ factor += 2 ;
32
+ }
33
+ }
34
+
35
+ function writeResults (end, passes)
36
+ {
37
+ local number = 1 ; // account for the prime number 2
38
+ foreach (i, j in bitArray) {
39
+ if (i > 2 && i % 2 != 0 && bitArray[i] == null ) {
40
+ number++ ;
41
+ }
42
+ }
43
+ if (number == 78498 ) {
44
+ print (" Tmob;" + passes + " ;" + end + " ;" + " 1;algorithm=base,faithful=yes\n " );
45
+ }
46
+ }
47
+
48
+ }
49
+
50
+
51
+ function main () {
52
+ local passes = 0 ;
53
+ local startTime = time ();
54
+ local lastTime = startTime;
55
+ while (lastTime == startTime) // Make sure we start exact on the next sec, as time() is only precise to the sec.
56
+ {
57
+ lastTime = time ();
58
+ }
59
+ local endTime = lastTime + 5 ;
60
+
61
+ while (time () < endTime)
62
+ {
63
+ sieve <- SieveClass(1000000 );
64
+ sieve. runSieve ();
65
+ passes++ ;
66
+ }
67
+ local progEnd = clock ();
68
+
69
+ sieve. writeResults (progEnd, passes);
70
+ }
71
+
72
+
73
+ main ();
Original file line number Diff line number Diff line change
1
+ # Squirrel solution by Tmob
2
+
3
+ ![ Algorithm] ( https://img.shields.io/badge/Algorithm-base-green )
4
+ ![ Faithfulness] ( https://img.shields.io/badge/Faithful-yes-green )
5
+ ![ Parallelism] ( https://img.shields.io/badge/Parallel-no-green )
6
+
7
+ Based on Python solution_1
8
+
9
+ ## Run instructions
10
+
11
+ ` apt-get install -y squirrel3 `
12
+
13
+ ` squirrel ./prime.nut `
14
+
15
+ ## Output
16
+
17
+ Ryzen 9 5900x
18
+ ` Tmob;179;5.31056;1;algorithm=base,faithful=yes `
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ squirrel ./prime.nut
You can’t perform that action at this time.
0 commit comments