Skip to content

Commit ea83ff4

Browse files
committed
🎉
1 parent 6144dae commit ea83ff4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+364
-9
lines changed

Extra-C/prob03/prob3-2.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
file: prob3-2.c
33
author: David De Potter
44
description: extra, problem 3, maximum path
5-
version: 3.2, using functions library and
6-
while the time complexity is still in O(n²), the
7-
space complexity is now in O(n) instead of O(n²),
8-
by using only two rows of size n instead of a
9-
2D array of size n²
5+
version: 3.2, using clib library
6+
also changed the implementation to use only two
7+
rows of size n instead of a 2D array of size n²
8+
Time complexity is still O(n²)
9+
Space complexity is now O(n) instead of O(n²) of
10+
the previous implementation
1011
*/
1112

1213
#include <stdio.h>

Functions/clib/math.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ int isDivisor(int x, int y) {
2222

2323
// returns the greatest common divisor of a and b
2424
int GCD(int a, int b) {
25-
2625
if (b == 0) return a;
2726
return GCD(b, a % b);
2827
}
2928

3029
// returns the least common multiple of a and b
3130
int LCM(int a, int b) {
32-
3331
return a / GCD(a, b) * b;
3432
}
3533

PF3-3/exam3-2024/problem5/sol5.dfy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
file: sol5.dfy
33
author: David De Potter
4-
description: 3-3rd exam 2023, solution to problem 5
4+
description: 3-3rd exam 2024, solution to problem 5
55
*/
66

77
method problem5(a: array<int>) returns (k: nat)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
file: myprogram.c
3+
author: your name
4+
description: 3-3rd resit exam 2024, problem 2,
5+
special numbers
6+
*/
7+
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
11+
int main(int argc, char *argv[]) {
12+
13+
// your code here
14+
15+
// to test your code, run the test script in the terminal:
16+
// $ ../../../ctest.sh myprogram.c
17+
// after you made it executable by running:
18+
// $ chmod +x ../../../ctest.sh (you only need to do this once)
19+
20+
return 0;
21+
}

PF3-3/resit3-2024/problem2/prob2.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
file: prob2.c
3+
author: David De Potter
4+
description: 3-3rd resit exam 2024, problem 2,
5+
special numbers
6+
*/
7+
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
11+
int isSpecial(int n) {
12+
// determines if n is a special number
13+
int count = 0;
14+
// check number of prime factors up to sqrt(n)
15+
for (int i = 2; i * i <= n; i += (i == 2) ? 1 : 2) {
16+
while (n % i == 0) {
17+
n /= i;
18+
if (++count > 1)
19+
return 0;
20+
}
21+
}
22+
return count; // 0 if prime, 1 if special
23+
}
24+
25+
int main(){
26+
int m, count = 0, a = 0, b = 0, c = 0;
27+
28+
(void)! scanf("%d", &m);
29+
30+
// we check for n, n - 1 and n - 2 for efficiency
31+
// so we start at n = 3 and go up to m + 1
32+
for (int n = 3; n < m + 2; ++n) {
33+
c = b;
34+
b = a;
35+
a = isSpecial(n);
36+
37+
if (a && b && c)
38+
++count;
39+
}
40+
41+
printf("%d\n", count);
42+
return 0;
43+
}
44+

PF3-3/resit3-2024/problem2/tests/1.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
33
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4532199
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7958

PF3-3/resit3-2024/problem2/tests/2.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
34

0 commit comments

Comments
 (0)