Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- public class BytelandianConsistencyCheck {
- private static HashMap<Long, Long> memory = new HashMap<Long, Long>();
- private static HashMap<Long, Long> map = new HashMap<Long, Long>();
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement