Skip to content

Instantly share code, notes, and snippets.

@jluismm2311
Created June 9, 2020 17:19
Show Gist options
  • Save jluismm2311/1c7a34c4030039dd051576f186e29188 to your computer and use it in GitHub Desktop.
Save jluismm2311/1c7a34c4030039dd051576f186e29188 to your computer and use it in GitHub Desktop.
Peter can see a clock in the mirror from the place he sits in the office. When he saw the clock shows 12:22 alt text He knows that the time is 11:38 alt text in the same manner: 05:25 --> 06:35 01:50 --> 10:10 11:58 --> 12:02 12:01 --> 11:59 Please complete the function WhatIsTheTime(timeInMirror), where timeInMirror is the mirrored time (what P…
class Kata {
static String WhatIsTheTime(timeInMirror) {
def hoursAndMinutes = timeInMirror.split(':').collect{it.toInteger()}
def hours = hoursAndMinutes[1] == 0? 12 :11
if(hoursAndMinutes[0] < 12) {
hoursAndMinutes[0] = hours-hoursAndMinutes[0]== 0?12:hours-hoursAndMinutes[0]
}else{
hoursAndMinutes[0] = hours
}
hoursAndMinutes[1] = hoursAndMinutes[1] > 0 ? 60 - hoursAndMinutes[1] : 0
String.format('%02d:%02d',hoursAndMinutes[0],hoursAndMinutes[1])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment