-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtilities.java
More file actions
79 lines (75 loc) · 2.58 KB
/
Utilities.java
File metadata and controls
79 lines (75 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* Utilities.java */
/**
* Template for class that implements numeric utility functions.
* Initial functions address numeric sequences.
*
* @author Copyright © 2024 Dr. Jody Paul (GPLv3)
* @version 1.1.6
*/
public final class Utilities {
/**
* Hide constructor because this is a utility class.
*/
private Utilities() { }
/**
* Determines the number of unique connections between
* fully-connected members of a group of the specified
* size.
* The sequence starts with numberOfConnections(0)==0
* numberOfConnections(1)==0, numberOfConnections(2)==1.
*
* @param numPeople the number of people in the group
* (valid for numPeople >= 0)
* @return the number of connections
*/
public static long numberOfConnections(int numPeople) {
if (numPeople == 0) return 0;
else return numberOfConnections(numPeople - 1) + (numPeople - 1);
}
/**
* Determines the number in the Fibonacci sequence
* corresponding to the index given as the parameter.
* The sequence starts with fibonacci(0)==0 and
* fibonacci(1)==1.
*
* @param index the index of the desired value
* (valid for index >= 0)
* @return the number in the Fibonacci sequence at the specific index
*/
public static long fibonacci(int index) {
return index;
}
/**
* Determine the number in a Tribonacci sequence
* corresponding to the index given as the parameter.
* The sequence is defined as follows:
* tribonacci(0)==0,
* tribonacci(1)==0,
* tribonacci(2)==1,
* tribonacci(n)==tribonacci(n-1)+tribonacci(n-2)+tribonacci(n-3).
*
* @param index the index of the desired value
* (valid for index >= 0)
* @return the number in the Tribonacci sequence at the specific index
*/
public static long tribonacci(int index) {
return index;
}
/**
* Determine the number in a Fibonacci primes sequence
* corresponding to the index given as the parameter.
* A Fibonacci prime number is a Fibonacci number that is also prime.
* The first few Fibonacci primes are the following.
* fibonacciPrimes(0)==2,
* fibonacciPrimes(1)==3,
* fibonacciPrimes(2)==5, and
* fibonacciPrimes(3)==13.
*
* @param index the index of the desired value
* (valid for index >= 0)
* @return the number in the Fibonacci primes sequence at the specific index
*/
public static long fibonacciPrimes(int index) {
return index;
}
}