// Solucion a la practica 6 package edd.util; import java.util.LinkedList; import java.util.List; public class RecursiveAlgorithms { public static int gcd(int m, int n) { if (m == n) return m; else if (m > n) return gcd(m - n, n); else return gcd(m, n - m); } public static int pow(int base, int exponent) { if (exponent == 0) { return 1; } return base * pow(base, exponent - 1); } public static int max(List list) { if (list.isEmpty()) { return Integer.MIN_VALUE; } List rest = new LinkedList<>(list); int first = rest.remove(0); int m = max(rest); return m > first ? m : first; } public static int consecutiveAddition(int start, int end) { if (start > end) { return 0; } return start + consecutiveAddition(start + 1, end); } public static String toBinary(int n) { if (n == 0) { return ""; } else { return toBinary(n / 2) + (n % 2); } } public static boolean isPalindrome(String s) { if (s.length() <= 1) { return true; } char first = s.charAt(0); if (!Character.isLetter(first)) { return isPalindrome(s.substring(1)); } char last = s.charAt(s.length() - 1); if (!Character.isLetter(last)) { return isPalindrome(s.substring(0, s.length() - 1)); } if (Character.toUpperCase(first) == Character.toUpperCase(last)) { return isPalindrome(s.substring(1, s.length() - 1)); } return false; } }