Ad
Algorithms
Data Structures
Simulation
Logic
Games
Date Time
Code
Diff
  • import java.time.LocalTime;
    import java.time.format.DateTimeFormatter;
    import java.util.HashMap;
    import java.util.Map;
    
    public class Kata {
    
    	public static String arrivalTime(final String[] route, final String departureTime) {
    		if (route.length == 0) return "The Train Driver has the day off";
    
    		LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm"));
    		String origin = "Skyport";
    		int index = 0;
    		while (index < route.length) {
    			String destination = route[index];
    			Map<String, double[]> destinationMap = tableTime.get(origin);
    			if (destinationMap != null && destinationMap.containsKey(destination)) {
    				double[] times = destinationMap.get(destination);
    				timeResult = calculateTime(timeResult, times);
    				origin = destination;
    				index++;
    			} else if (origin.equals(destination)) {
    				timeResult = timeResult.plusHours(1);
    				index++;
    			} else {
    				String transfer = "Skyport";
    				double[] times = tableTime.get(origin).get(transfer);
    				timeResult = calculateTime(timeResult, times);
    				origin = transfer;
    			}
    		}
    		return timeResult.format(DateTimeFormatter.ofPattern("HH:mm"));
    	}
    
    	private static Map<String, Map<String, double[]>> tableTime = new HashMap<String, Map<String, double[]>>() {
    		{
    			addRecord("Skyport", "Crystalium", 15, 2);
    			addRecord("Skyport", "Oasis", 20, 3);
    			addRecord("Oasis", "Crystalium", 15, 1.5);
    			addRecord("Skyport", "Nexus", 15, 4);
    		}
    
    		private void addRecord(final String origin, final String destiny, final double minutesWait,
    				final double hoursTravel) {
    			putIfAbsent(origin, new HashMap<>());
    			get(origin).put(destiny, new double[] { minutesWait, hoursTravel });
    
    			putIfAbsent(destiny, new HashMap<>());
    			get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel });
    		}
    	};
    
    	private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) {
    		int minutes = (int) times[0];
    		int remainingMinutes = (int) (times[1] * 60);
    
    		return currentTime.plusMinutes(minutes).plusMinutes(remainingMinutes);
    	}
    }
    • import java.time.LocalTime;
    • import java.time.format.DateTimeFormatter;
    • import java.util.HashMap;
    • import java.util.Map;
    • public class Kata {
    • public static String arrivalTime(final String[] route, final String departureTime) {
    • if (route.length == 0)
    • return "The Train Driver has the day off";
    • if (route.length == 0) return "The Train Driver has the day off";
    • LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm"));
    • String origin = "Skyport";
    • int index = 0;
    • while(index < route.length) {
    • while (index < route.length) {
    • String destination = route[index];
    • Map<String, double[]> destinationMap = tableTime.get(origin);
    • if (destinationMap != null && destinationMap.containsKey(destination)) {
    • double[] times = destinationMap.get(destination);
    • timeResult = calculateTime(timeResult, times);
    • origin = destination;
    • index++;
    • index++;
    • } else if (origin.equals(destination)) {
    • timeResult = timeResult.plusHours(1);
    • index++;
    • index++;
    • } else {
    • String transfer = "Skyport";
    • double[] times = tableTime.get(origin).get(transfer);
    • timeResult = calculateTime(timeResult, times);
    • origin = transfer;
    • }
    • }
    • return timeResult.format(DateTimeFormatter.ofPattern("HH:mm"));
    • }
    • private static Map<String, Map<String, double[]>> tableTime = new HashMap<String, Map<String, double[]>>() {
    • {
    • addRecord("Skyport", "Crystalium", 15, 2);
    • addRecord("Skyport", "Oasis", 20, 3);
    • addRecord("Oasis", "Crystalium", 15, 1.5);
    • addRecord("Skyport", "Nexus", 15, 4);
    • }
    • private void addRecord(final String origin, final String destiny, final double minutesWait, final double hoursTravel) {
    • private void addRecord(final String origin, final String destiny, final double minutesWait,
    • final double hoursTravel) {
    • putIfAbsent(origin, new HashMap<>());
    • get(origin).put(destiny, new double[] { minutesWait, hoursTravel });
    • putIfAbsent(destiny, new HashMap<>());
    • get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel });
    • }
    • };
    • private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) {
    • int minutes = (int) times[0];
    • int remainingMinutes = (int) (times[1] * 60);
    • return currentTime.plusMinutes(minutes).plusMinutes(remainingMinutes);
    • }
    • }
Code
Diff
  • import java.time.LocalTime;
    import java.time.format.DateTimeFormatter;
    import java.util.HashMap;
    import java.util.Map;
    
    public class Kata {
    	
    	public static String arrivalTime(final String[] route, final String departureTime) {
    		if (route.length == 0)
    			return "The Train Driver has the day off";
    
    		LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm"));
    		String origin = "Skyport";
    		for (int i = 0; i < route.length; i++) {
    			String destination = route[i];
    
    			Map<String, double[]> destinationMap = tabla.get(origin);
    			if (destinationMap != null && destinationMap.containsKey(destination)) {
    				double[] times = destinationMap.get(destination);
    
    				timeResult = calculateTime(timeResult, times);
    				origin = destination;
    			} else if (origin.equals(destination)) {
    				timeResult = timeResult.plusHours(1);
    			} else {
    				String transfer = "Skyport";
    				double[] times = tabla.get(origin).get(transfer);
    
    				timeResult = calculateTime(timeResult, times);
    				origin = transfer;
    				i--;
    			}
    		}
    
    		return timeResult.format(DateTimeFormatter.ofPattern("HH:mm"));
    	}
    	
    	private static Map<String, Map<String, double[]>> tabla = new HashMap<String, Map<String, double[]>>() {
    		{
    			addRecord("Skyport", "Crystalium", 15, 2);
    			addRecord("Skyport", "Oasis", 20, 3);
    			addRecord("Oasis", "Crystalium", 15, 1.5);
    			addRecord("Skyport", "Nexus", 15, 4);
    		}
    
    		private void addRecord(final String origin, final String destiny, final double minutesWait,
    				final double hoursTravel) {
    			putIfAbsent(origin, new HashMap<>());
    			get(origin).put(destiny, new double[] { minutesWait, hoursTravel });
    
    			putIfAbsent(destiny, new HashMap<>());
    			get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel });
    		}
    	};
    
    	private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) {
    		int minutes = (int) times[0];
    		int remainingMinutes = (int) (times[1] * 60);
    
    		return currentTime.plusMinutes(minutes).plusMinutes(remainingMinutes);
    	}
    }
    • import java.time.LocalTime;
    • import java.time.format.DateTimeFormatter;
    • import java.util.HashMap;
    • import java.util.Map;
    • public class Kata {
    • public static String arrivalTime(final String[] route, final String departureTime) {
    • if (route.length == 0)
    • return "The Train Driver has the day off";
    • LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm"));
    • String origin = "Skyport";
    • for (int i = 0; i < route.length; i++) {
    • String destination = route[i];
    • Map<String, double[]> destinationMap = tabla.get(origin);
    • if (destinationMap != null && destinationMap.containsKey(destination)) {
    • double[] times = destinationMap.get(destination);
    • timeResult = calculateTime(timeResult, times);
    • origin = destination;
    • } else if (origin.equals(destination)) {
    • timeResult = timeResult.plusHours(1);
    • } else {
    • String transfer = "Skyport";
    • double[] times = tabla.get(origin).get(transfer);
    • timeResult = calculateTime(timeResult, times);
    • origin = transfer;
    • i--;
    • }
    • }
    • return timeResult.format(DateTimeFormatter.ofPattern("HH:mm"));
    • }
    • private static Map<String, Map<String, double[]>> tabla = new HashMap<String, Map<String, double[]>>() {
    • {
    • addRecord("Skyport", "Crystalium", 15, 2);
    • addRecord("Skyport", "Oasis", 20, 3);
    • addRecord("Oasis", "Crystalium", 15, 1.5);
    • addRecord("Skyport", "Nexus", 15, 4);
    • }
    • private void addRecord(final String origin, final String destiny, final double minutesWait,
    • final double hoursTravel) {
    • putIfAbsent(origin, new HashMap<>());
    • get(origin).put(destiny, new double[] { minutesWait, hoursTravel });
    • putIfAbsent(destiny, new HashMap<>());
    • get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel });
    • }
    • };
    • private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) {
    • int minutes = (int) times[0];
    • int hours = (int) times[1];
    • int remainingMinutes = (int) ((times[1] - hours) * 60);
    • int remainingMinutes = (int) (times[1] * 60);
    • return currentTime.plusMinutes(minutes).plusHours(hours).plusMinutes(remainingMinutes);
    • return currentTime.plusMinutes(minutes).plusMinutes(remainingMinutes);
    • }
    • }
Code
Diff
  • import java.time.LocalTime;
    import java.time.format.DateTimeFormatter;
    import java.util.HashMap;
    import java.util.Map;
    
    public class Kata {
    	
    	public static String arrivalTime(final String[] route, final String departureTime) {
    		if (route.length == 0)
    			return "Pepe has the day off";
    
    		LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm"));
    		String origin = "Skyport";
    		for (int i = 0; i < route.length; i++) {
    			String destination = route[i];
    
    			Map<String, double[]> destinationMap = tabla.get(origin);
    			if (destinationMap != null && destinationMap.containsKey(destination)) {
    				double[] times = destinationMap.get(destination);
    
    				timeResult = calculateTime(timeResult, times);
    				origin = destination;
    			} else if (origin.equals(destination)) {
    				timeResult = timeResult.plusHours(1);
    			} else {
    				String transfer = "Skyport";
    				double[] times = tabla.get(origin).get(transfer);
    
    				timeResult = calculateTime(timeResult, times);
    				origin = transfer;
    				i--;
    			}
    		}
    
    		return timeResult.format(DateTimeFormatter.ofPattern("HH:mm"));
    	}
    	
    	private static Map<String, Map<String, double[]>> tabla = new HashMap<String, Map<String, double[]>>() {
    		{
    			addRecord("Skyport", "Crystalium", 15, 2);
    			addRecord("Skyport", "Oasis", 20, 3);
    			addRecord("Oasis", "Crystalium", 15, 1.5);
    			addRecord("Skyport", "Nexus", 15, 4);
    		}
    
    		private void addRecord(final String origin, final String destiny, final double minutesWait,
    				final double hoursTravel) {
    			putIfAbsent(origin, new HashMap<>());
    			get(origin).put(destiny, new double[] { minutesWait, hoursTravel });
    
    			putIfAbsent(destiny, new HashMap<>());
    			get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel });
    		}
    	};
    
    	private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) {
    		int minutes = (int) times[0];
    		int hours = (int) times[1];
    		int remainingMinutes = (int) ((times[1] - hours) * 60);
    
    		return currentTime.plusMinutes(minutes).plusHours(hours).plusMinutes(remainingMinutes);
    	}
    }
    • import java.time.LocalTime;
    • import java.time.format.DateTimeFormatter;
    • import java.util.HashMap;
    • import java.util.Map;
    • public class Kata {
    • public static String arrivalTime(final String[] route, final String departureTime) {
    • public static String arrivalTime(final String[] route, final String departureTime) {
    • if (route.length == 0)
    • return "Pepe has the day off";
    • LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm"));
    • String origin = "Madrid";
    • String origin = "Skyport";
    • for (int i = 0; i < route.length; i++) {
    • String destination = route[i];
    • Map<String, double[]> destinationMap = tabla.get(origin);
    • if (destinationMap != null && destinationMap.containsKey(destination)) {
    • double[] times = destinationMap.get(destination);
    • timeResult = calculateTime(timeResult, times);
    • origin = destination;
    • } else if (origin.equals(destination)) {
    • timeResult = timeResult.plusHours(1);
    • } else {
    • String transbordo = "Madrid";
    • double[] times = tabla.get(origin).get(transbordo);
    • String transfer = "Skyport";
    • double[] times = tabla.get(origin).get(transfer);
    • timeResult = calculateTime(timeResult, times);
    • origin = transbordo;
    • origin = transfer;
    • i--;
    • }
    • }
    • return timeResult.format(DateTimeFormatter.ofPattern("HH:mm"));
    • }
    • private static Map<String, Map<String, double[]>> tabla = new HashMap<String, Map<String, double[]>>() {
    • {
    • addRecord("Madrid", "Barcelona", 15, 2);
    • addRecord("Madrid", "Valencia", 20, 3);
    • addRecord("Valencia", "Barcelona", 15, 1.5);
    • addRecord("Madrid", "Cadiz", 15, 4);
    • addRecord("Skyport", "Crystalium", 15, 2);
    • addRecord("Skyport", "Oasis", 20, 3);
    • addRecord("Oasis", "Crystalium", 15, 1.5);
    • addRecord("Skyport", "Nexus", 15, 4);
    • }
    • private void addRecord(final String origin, final String destiny, final double minutesWait,
    • final double hoursTravel) {
    • putIfAbsent(origin, new HashMap<>());
    • get(origin).put(destiny, new double[] { minutesWait, hoursTravel });
    • putIfAbsent(destiny, new HashMap<>());
    • get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel });
    • }
    • };
    • private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) {
    • int minutes = (int) times[0];
    • int hours = (int) times[1];
    • int remainingMinutes = (int) ((times[1] - hours) * 60);
    • return currentTime.plusMinutes(minutes).plusHours(hours).plusMinutes(remainingMinutes);
    • }
    • }