summaryrefslogtreecommitdiff
path: root/graphs/java/classics
diff options
context:
space:
mode:
Diffstat (limited to 'graphs/java/classics')
-rw-r--r--graphs/java/classics/.gitignore38
-rw-r--r--graphs/java/classics/pom.xml133
-rw-r--r--graphs/java/classics/src/main/java/fr/epita/assistants/classics/Classics.java104
3 files changed, 275 insertions, 0 deletions
diff --git a/graphs/java/classics/.gitignore b/graphs/java/classics/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/graphs/java/classics/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store \ No newline at end of file
diff --git a/graphs/java/classics/pom.xml b/graphs/java/classics/pom.xml
new file mode 100644
index 0000000..ce852cb
--- /dev/null
+++ b/graphs/java/classics/pom.xml
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>fr.epita.assistants</groupId>
+ <artifactId>classics</artifactId>
+ <version>1.0</version>
+
+ <properties>
+ <versions.java>21</versions.java>
+ <versions.junit>5.9.1</versions.junit>
+ <versions.maven-compiler-plugin>3.13.0</versions.maven-compiler-plugin>
+ <versions.maven-surefire-plugin>2.22.2</versions.maven-surefire-plugin>
+ <versions.maven-jar-plugin>3.1.1</versions.maven-jar-plugin>
+ <versions.maven-install-plugin>3.1.0</versions.maven-install-plugin>
+
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <surefire.reportsDirectory>${project.build.directory}/surefire-reports</surefire.reportsDirectory>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <version>${versions.junit}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-junit-platform</artifactId>
+ <version>${versions.maven-surefire-plugin}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-compat</artifactId>
+ <version>3.9.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>3.9.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-monitor</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>3.0.24</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-filtering</artifactId>
+ <version>3.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-interpolation</artifactId>
+ <version>1.13</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-profile</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact-manager</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-registry</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-repository-metadata</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>classworlds</groupId>
+ <artifactId>classworlds</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-commons</artifactId>
+ <version>1.9.3</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${versions.maven-compiler-plugin}</version>
+ <configuration>
+ <source>${versions.java}</source>
+ <target>${versions.java}</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <version>${versions.maven-install-plugin}</version>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${versions.maven-surefire-plugin}</version>
+ <configuration>
+ <reportsDirectory>${surefire.reportsDirectory}</reportsDirectory>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/graphs/java/classics/src/main/java/fr/epita/assistants/classics/Classics.java b/graphs/java/classics/src/main/java/fr/epita/assistants/classics/Classics.java
new file mode 100644
index 0000000..9be12e2
--- /dev/null
+++ b/graphs/java/classics/src/main/java/fr/epita/assistants/classics/Classics.java
@@ -0,0 +1,104 @@
+package fr.epita.assistants.classics;
+
+public class Classics {
+ /**
+ * Computes the factorial of n.
+ *
+ * @param n the nth value to compute, negative values should return -1
+ * @return the long value of n!
+ */
+ public static long factorial(int n) {
+ if (n < 0) return -1;
+ if (n == 0) return 1;
+ return n * factorial(n - 1);
+ }
+
+ /**
+ * Computes the nth value of the tribonacci suite.
+ * f(0) = 0, f(1) = 1, f(2) = 1, f(n+3) = f(n) + f(n+1) + f(n+2)
+ *
+ * @param n the nth sequence to compute
+ */
+ public static long tribonacci(int n) {
+ if (n < 0)
+ return -1;
+ if (n == 0) {
+ return 0;
+ }
+ long fst = 0;
+ if (n < 3) return 1;
+ long sec = 1;
+ long thd = 1;
+ while (n >= 3) {
+ long t = fst + sec + thd;
+ fst = sec;
+ sec = thd;
+ thd = t;
+ n--;
+ }
+ return thd;
+ }
+
+ /**
+ * Checks if a word is a palindrome.
+ *
+ * @param word the string to check
+ * @return true if the word is a palindrome, false otherwise.
+ */
+ public static boolean isPalindrome(String word) {
+ if (word == null) return false;
+ word = word.toLowerCase().strip();
+ if (word.isEmpty()) return true;
+ for (int i = 0, j = word.length() - 1; i < j; i++, j--) {
+ while (word.charAt(i) == ' ') {
+ i++;
+ }
+ while (word.charAt(j) == ' ') {
+ j--;
+ }
+ if (word.charAt(i) != word.charAt(j)) return false;
+ }
+ return true;
+ }
+
+ /**
+ * Sorts an array using an insertion sort.
+ *
+ * @param array the array to sort in place
+ */
+ public static void insertionSort(int[] array) {
+ if (array.length == 0) {
+ return;
+ }
+ for (int i = 1; i < array.length; i++) {
+ for (int j = i; j > 0 && array[j - 1] > array[j]; j--) {
+ int tmp = array[j];
+ array[j] = array[j - 1];
+ array[j - 1] = tmp;
+ }
+ }
+ }
+
+ /**
+ * Combines two strings by alternating their characters. Must use a StringBuilder.
+ * If the strings do not have the same length, appends the remaining characters at the end of the result.
+ * For instance, combine("abc", "def") returns "adbecf"
+ */
+ public static String combine(String a, String b) {
+ if (a.isEmpty())
+ return b;
+ if (b.isEmpty())
+ return a;
+ StringBuilder sb = new StringBuilder();
+ int i;
+ for (i = 0; i < Math.min(a.length(), b.length()); i++) {
+ sb.append(a.charAt(i));
+ sb.append(b.charAt(i));
+ }
+ if (b.length() > a.length()) {
+ for (; i < b.length(); i++)
+ sb.append(b.charAt(i));
+ }
+ return new String(sb);
+ }
+} \ No newline at end of file