물음표 살인마의 개발블로그

알고리즘 문제/CodeWar

Clocky Mc Clock-Face

BEstyle 2022. 11. 24. 14:09

DESCRIPTION:

Story

Due to lack of maintenance the minute-hand has fallen off Town Hall clock face.

And because the local council has lost most of our tax money to a Nigerian email scam there are no funds to fix the clock properly.

Instead, they are asking for volunteer programmers to write some code that tell the time by only looking at the remaining hour-hand!

What a bunch of cheapskates!

Can you do it?

Kata

Given the angle (in degrees) of the hour-hand, return the time in 12 hour HH:MM format. Round down to the nearest minute.

Examples

  • 12:00 = 0 degrees
  • 03:00 = 90 degrees
  • 06:00 = 180 degrees
  • 09:00 = 270 degrees
  • 12:00 = 360 degrees

Notes

  • 0 <= angle <= 360
  • Do not make any AM or PM assumptions for the HH:MM result. They are indistinguishable for this Kata.
    • 3 o'clock is 03:00, not 15:00
    • 7 minutes past midnight is 12:07
    • 7 minutes past noon is also 12:07

def what_time_is_it(angle):
    if angle//30 ==0:
        hour="12"
    elif angle//30<10:
        hour="0"+str(round(angle//30))
    else:
        hour=str(round(angle//30))
    if angle%30*2<10:
        minite="0"+str(int(angle%30*2))
    else:
        minite=str(int(angle%30*2))
    return hour+":"+minite

'알고리즘 문제 > CodeWar' 카테고리의 다른 글

Most Frequent Weekdays  (0) 2022.11.27
Message Validator  (0) 2022.11.27
The Office V - Find a Chair  (0) 2022.11.24
Split and then add both sides of an array together.  (0) 2022.11.23
Who has the most money?  (0) 2022.11.23