Advertisement
IvoB1987

How many times?

Mar 20th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. //used for http://puzzling.stackexchange.com/questions/29323/how-many-times
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         int hours = 0, minutes = 0, seconds = 0;
  6.         seconds++;
  7.         while(!(hours == 0 && minutes == 0 && seconds == 0)) {
  8.             seconds++;
  9.             if (seconds == 60) {
  10.                 minutes++;
  11.                 seconds = 0;
  12.             }
  13.             if (minutes % 12 == 0 && seconds == 0) hours++;
  14.             if (minutes == 60) minutes = 0;
  15.             if (hours == 60) hours = 0;
  16.             check(hours,minutes,seconds);
  17.         }  
  18.     }
  19.  
  20.     private static void check(int hours, int minutes, int seconds) {
  21.         int max = Math.max(Math.max(hours, minutes), seconds);
  22.         int median = Math.max(Math.min(hours,minutes), Math.min(Math.max(hours,minutes),seconds));
  23.         int min = Math.min(Math.min(hours, minutes), seconds);
  24.         if (max == median + 20 && median == min + 20)
  25.             System.out.println((hours-(hours%5))/5+":"+minutes+":"+seconds);
  26.     }
  27. }
  28.  
  29. //output:
  30. //0:21:41
  31. //0:43:23
  32. //1:27:47
  33. //1:49:29
  34. //2:32:52
  35. //2:54:34
  36. //3:38:58
  37. //3:59:39
  38. //4:0:40
  39. //4:43:3
  40. //5:5:45
  41. //5:49:9
  42. //6:10:50
  43. //6:54:14
  44. //7:16:56
  45. //7:59:19
  46. //8:0:20
  47. //8:21:1
  48. //9:5:25
  49. //9:27:7
  50. //10:10:30
  51. //10:32:12
  52. //11:16:36
  53. //11:38:18
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement