import java.util.HashMap; public class BytelandianConsistencyCheck { private static HashMap memory = new HashMap(); private static HashMap map = new HashMap(); public static final long LOWER_BOUND = 10_000_000_000L; public static final long UPPER_BOUND = 10_000_500_000L; public static void main(String[] args) { memory.put(0L, 0L); for (long i = LOWER_BOUND; i < UPPER_BOUND; i++){ if (coins(i) != changer(i)){ System.out.println("The methods didn't return the same value"); } } } public static Long changer(long coin) { if (!memory.containsKey(coin)){ long tmp = changer(coin/4L) + changer(coin/3L) + changer(coin/2L); memory.put(coin, tmp > coin ? tmp : coin); } return memory.get(coin); } public static long coins(long n) { if (!map.containsKey(n)) { map.put(n, (n > (n / 2) + (n / 3) + (n / 4) ? n : coins(n / 2) + coins(n / 3) + coins(n / 4))); } return map.get(n); } }