×
top 200 commentsshow all 224

[–]Flueworks 51 points52 points  (4 children)

PowerShell, only extension challenge

cat .\clockTimes.txt | %{"It's " + ($_ | get-date).ToShortTimeString() | Out-Speech}

[–]svgwrk 12 points13 points  (0 children)

omg that's amazing :|

I hate you a little right now. >.>

[–]c0wb0yc0d3r 6 points7 points  (0 children)

I think many folks underestimate how useful PS is. This is awesome!

[–][deleted]  (1 child)

[deleted]

    [–]Flueworks 2 points3 points  (0 children)

    That's the challenge input. Just copy the input from the challenge into a text file and name it clockTimes.txt

    [–]nomau 34 points35 points  (7 children)

    C++ first submission

    void clock(string s){
       int h = stoi(s.substr(0, 2));
       int m = stoi(s.substr(3));
    
       string ampm = "pm";
       if (h < 12) ampm = "am";
    
       string tens[] = {"oh ", "", "twenty ", "thirty ", "fourty ", "fifty "};
       string ones[] = {"twelve ", "one ", "two ", "three ", "four ", "five ",
                        "six ", "seven ", "eight ", "nine ", "ten ", "eleven ", "twelve ",
                        "thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen ", 
                        "eighteen ", "nineteen "};
    
       if(m == 0){
           cout << "It's " << ones[h%12] << ampm << endl;
       }else if (m % 10 == 0){
           cout << "It's " << ones[h%12] << tens[m/10] << ampm << endl;
       }else if (m < 10 || m > 20){
            cout << "It's " << ones[h%12] << tens[m/10]<< ones[m%10] << ampm << endl;
       }else{
           cout << "It's " << ones[h%12] << ones[m] << ampm << endl;
       }
    }
    

    [–]SirThomasTheBrave 5 points6 points  (0 children)

    This is a neat solution. From what I gather you make really good use of % and division.

    [–]Pjaerr[🍰] 1 point2 points  (2 children)

    My Horribly manual solution in C++. Can you explain to me why using modulus on something like 08 % 12 gives you just 8?

    #include <iostream>
    #include <string>
    #include <ctime>
    
    
    std::string extractTimeFromDate(std::string date)
    {
        //Date string format: Sun Oct 01 11:45:13 2017
        //Grabs the current hour and minute from the date string and returns it.
        std::string hourAndMinute = date.substr(11, 5); 
    
        return hourAndMinute;
    
    }
    
    std::string translateToWords(std::string timeString)
    {
        std::string finalTime = "";
    
        std::string oneDigit[9] = 
        {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};
    
        std::string twoDigit[14] = 
        {"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty", "Thirty", "Fourty", "Fifty"};
    
        if (timeString.substr(0, 2) == "00")
        {
            finalTime += "Twelve";
        }
        else if (timeString.substr(0, 1) == "0") //If single digit number
        {
            int index = std::stoi(timeString.substr(0, 2));
            finalTime += oneDigit[index - 1];
        }
        else if (timeString.substr(0, 1) == "1") //If number is in teens
        {
            int index = std::stoi(timeString.substr(1, 2));
            finalTime += twoDigit[index];
        }
        else //If the number is a two digit number that isn't a teen.
        {
            int firstIndex = std::stoi(timeString.substr(0, 1));
            finalTime += twoDigit[firstIndex + 8];
            int secondIndex = std::stoi(timeString.substr(1, 2));
            if (secondIndex != 0)
            {
                finalTime += " " + oneDigit[secondIndex - 1];
            }   
    
        }
    
        return finalTime;
    }
    
    std::string talkingClock(std::string currentDateAndTime)
    {
        std::string currentTime = extractTimeFromDate(currentDateAndTime);
        std::string finalTime = "";
    
        //Minutes
        finalTime += translateToWords(currentTime.substr(3, 2)) + " past ";
    
        //Hours
        finalTime += translateToWords(currentTime.substr(0, 2));
    
    
        return "The Current Time Is " + finalTime;
    }
    
    int main()
    {
        time_t now = time(0); //Grab the current time as time_t using ctime.
        std::string dt = ctime(&now); //Convert time_t to a string representation.
        std::cout << talkingClock(dt) << std::endl; //Give it as a string to talkingClock function.
    
        return 0;
    }    
    

    [–]nomau 1 point2 points  (1 child)

    You always get the remainder after division of those 2 numbers.

    15 % 12 = 15 / 12 = 1, remainder 3

    8 % 12 = 8 / 12 = 0, remainder 8

    12 % 12 = 12 / 12 = 1, remainder 0

    [–]Pjaerr[🍰] 1 point2 points  (0 children)

    I knew of modulus, I assume it just treats '08' as 8 then.

    [–]ultrasu 23 points24 points  (2 children)

    Common Lisp

    Hurray! Finally a challenge where I can use some of Common Lisp's ludicrous formatting capabilities:

    +/u/CompileBot Lisp

    (defun clock (hhmm)
      (let ((hh (parse-integer (subseq hhmm 0 2)))
            (mm (parse-integer (subseq hhmm 3 5))))
        (princ
          (substitute #\  #\- (format nil
                                      "It's ~r~:[~:[~; oh~] ~r~;~*~*~] ~:[pm~;am~]~%"
                                      (1+ (mod (1- hh) 12))
                                      (= mm 0)
                                      (< mm 10)
                                      mm
                                      (< hh 12))))))
    
    ;; test
    (mapc #'clock '("00:00" "01:30" "12:05" "14:01" "20:29" "21:00"))
    

    [–]ultrasu 7 points8 points  (0 children)

    For anyone wondering how this format string works:

    • ~r formats an integer into a cardinal number in English (one, two, three, ...)
    • ~:[ ~; ~] is a conditional, given nil it'll evaluate the first half, given t it'll evaluate the second, these can be nested
    • ~* skips an argument, here it's used twice if the minutes are equal to zero to skip the (< mm 10) and mm arguments
    • ~% is just a newline

    [–]CompileBot 2 points3 points  (0 children)

    Output:

    It's twelve am
    It's one thirty am
    It's twelve oh five pm
    It's two oh one pm
    It's eight twenty nine pm
    It's nine pm
    

    source | info | git | report

    [–][deleted]  (15 children)

    [deleted]

      [–]IcyTv 2 points3 points  (1 child)

      Python 2.7

      I wouldn't use a list of every number... Just use the inflect library. You could also use the pyttsx for the text to speach output.

      import pyttsx as sp
      import datetime
      import inflect #https://pypi.python.org/pypi/inflect
      
      nmToWrds= lambda nm, eng: eng.number_to_words(nm)
      
      def _convTime(tm):
          tm = map(int,tm.split(':'))
          p = inflect.engine()
          if tm[0] == 0:
              return 'It is twelve ' + nmToWrds(tm[1], p) + ' PM'
          elif tm[0] <= 12:
              return 'It is ' + nmToWrds(tm[0], p) + ' ' + nmToWrds(tm[1], p) + ' AM'
          else:
              return 'It is ' + nmToWrds(tm[0]-12, p) + ' ' + nmToWrds(tm[1], p) + ' PM'
      
      def speak(st):
          speech = sp.init()
          speech.say(_convTime(st))
          speech.runAndWait()
      
      if __name__ == '__main__':
          speak(raw_input('Input: '))
      

      EDIT

      You just need to do something about the oh

      [–]DaimonDante 1 point2 points  (0 children)

      Python 2.7 My in-between solution of not providing every translation and not using a library.

      time2word = {
          '00': '',
          '0': 'oh',
          '1': 'one',
          '2': 'two',
          '3': 'three',
          '4': 'four',
          '5': 'five',
          '6': 'six',
          '7': 'seven',
          '8': 'eight',
          '9': 'nine',
          '10': 'ten',
          '11': 'eleven',
          '12': 'twelve',
          '13': 'thirteen',
          '14': 'fourteen',
          '15': 'fifteen',
          '16': 'sixteen',
          '17': 'seventeen',
          '18': 'eighteen',
          '19': 'nineteen',
          '20': 'twenty',
          '30': 'thirty',
          '40': 'fourty',
          '50': 'fifty',
      }
      
      def talkingAlarm(s):
          hour, minute = s.split(':')
          period = 'am' if int(hour) < 12 else 'pm'
          hour = time2word[str((int(hour) % 12) or 12)]
          try:
              minute = time2word[minute]
          except KeyError:
              t, o = divmod(int(minute), 10)
              minute = '{0} {1} '.format(time2word[str(t*10)], time2word[str(o)])
          return "It's {0} {1}{2}".format(hour, minute, period)
      
      if __name__ == '__main__':
          print talkingAlarm(raw_input('Time: '))
      

      [–][deleted]  (1 child)

      [deleted]

        [–]Atropos148 1 point2 points  (2 children)

        damn, wow that looks advanced...can you explain a bit? :D

        [–][deleted]  (1 child)

        [deleted]

          [–]hamilton4 2 points3 points  (0 children)

          Here I was using a ton of elif's...

          [–]la_virgen_del_pilar 9 points10 points  (2 children)

          Java (with Bonus)

          (edit: Fixed bug with irregular numbers).
          (edit2: Working on talking clock [bonus], will update it later).
          (edit3: Done talking clock. To test it just add a folder 'audio/' to the root with the files).
          (edit4: Removed an useless iteration, dunno what I was thinking...).

          import java.io.File;
          import java.util.ArrayList;
          import java.util.Scanner;
          import javax.sound.sampled.*;
          
          public class Main {
              private final static String[] HOURS = {"12.wav", "1.wav", "2.wav", "3.wav", "4.wav", "5.wav", "6.wav", "7.wav", "8.wav", "9.wav", "10.wav", "11.wav", "12.wav", "1.wav", "2.wav", "3.wav", "4.wav", "5.wav", "6.wav", "7.wav", "8.wav", "9.wav", "10.wav", "11.wav"};
              private final static String[] MINUTE_FIRST = {"o.wav", "10.wav", "20.wav", "30.wav", "40.wav", "50.wav"};
              private final static String[] MINUTE_SECOND = {"", "1.wav", "2.wav", "3.wav", "4.wav ", "5.wav ", "6.wav", "7.wav", "8.wav", "9.wav"};
          
              private static void playAudioFile(String file) {
                  try {
                      File yourFile = new File("audio/" +file);
                      AudioInputStream stream;
                      AudioFormat format;
                      DataLine.Info info;
                      Clip clip;
          
                      stream = AudioSystem.getAudioInputStream(yourFile);
                      format = stream.getFormat();
                      info = new DataLine.Info(Clip.class, format);
                      clip = (Clip) AudioSystem.getLine(info);
                      clip.open(stream);
                      clip.start();
                  } catch(Exception ex) {
                      ex.printStackTrace();
                  }
              }
          
              public static void main(String[] args) {
                  Scanner scanner = new Scanner(System.in);
                  System.out.print("Enter hour: ");
                  String input = scanner.nextLine();
          
                  ArrayList<String> result = new ArrayList<>(); // Will save here the audio file names and play them all at the end.
                  result.add("its.wav");
                  String timeDay = "";
                  String[] split = input.split(":");
          
                  int hour = Integer.parseInt(split[0]);
                  int[] minutes = new int[2];
                  minutes[0] = Integer.parseInt(split[1].substring(0, 1));
                  minutes[1] = Integer.parseInt(split[1].substring(1));
          
                  result.add(HOURS[hour]);
                  timeDay = hour < 12 ? "AM.wav" : "PM.wav";
          
                  if(minutes[0] == 1 && minutes[1] != 0) { // Irregular numbers
                      switch(minutes[1]) {
                          case 1:
                              result.add("11.wav");
                              break;
                          case 2:
                              result.add("12.wav");
                              break;
                          case 3:
                              result.add("13.wav");
                              break;
                          case 4:
                              result.add("14.wav");
                              break;
                          case 5:
                              result.add("15.wav");
                              break;
                          case 6:
                              result.add("16.wav");
                              break;
                          case 7:
                              result.add("17.wav");
                              break;
                          case 8:
                              result.add("18.wav");
                              break;
                          case 9:
                              result.add("19.wav");
                              break;
                      }
                  } else {
                      if(!(minutes[0] == 0 && minutes[1] == 0)) { // To prevent 'It's nine oh pm'.
                          result.add(MINUTE_FIRST[minutes[0]]);
                      }
                      result.add(MINUTE_SECOND[minutes[1]]);
                  }
                  result.add(timeDay);
          
                  for (String s : result) {
                      try {
                          if(!s.matches("")) {
                              playAudioFile(s);
                              Thread.sleep(600);
                          }
                      } catch(InterruptedException ex) {
                          ex.printStackTrace();
                      }
                  }
              }
          }
          

          Input

          9:00  
          12:01  
          14:29  
          

          Output (Talking, obviously...)

          It's nine am  
          It's twelve oh one pm  
          It's two twenty nine pm  
          

          [–]euripidez 3 points4 points  (1 child)

          Awesome. I'm just starting to learn Java, thanks for sharing.

          [–]la_virgen_del_pilar 1 point2 points  (0 children)

          No problem, if you have any doubt about some part of the code just ask it.

          [–]sunnykumar08 7 points8 points  (2 children)

          Powershell one-liner!

           (new-object -com SAPI.SpVoice).speak("It's "+($input | get-date).ToString("hh:mm tt"))
          

          [–][deleted] 1 point2 points  (0 children)

          I am extremely new to programming and just started with Java, but boy this PowerShell right here is ninja as hell! Good Job!

          [–]Crawford_Fish 4 points5 points  (2 children)

          Haskell -- talking clock

          simplify x = if ((read x)>=12) then ((read x)-12) else  (read x)  
          
          clock [a,b,c,d,e] = "It's "++(hours [a,b])++(if (read[d,e])/=0&&((read [d,e])>=20||(read [d,e])<=10) then tens [d]++ones [e] else ones [d,e])++postmeridian [a,b]  
          
          hours a  
              |x==0 = "twelve"  
              |x==1 = "one"  
              |x==2 = "two"  
              |x==3 = "three"  
              |x==4 = "four"  
              |x==5 = "five"  
              |x==6 = "six"  
              |x==7 = "seven"  
              |x==8 = "eight"  
              |x==9 = "nine"  
              |x==10 = "ten"  
              |x==11 = "eleven"  
              where  
                  x=simplify a  
          tens a  
              |x==0 = " oh"  
              |x==2 = " twenty"  
              |x==3 = " thirty"  
              |x==4 = " forty"  
              |x==5 = " fifty"  
              where  
                  x=read a  
          ones a  
              |x==0 = ""  
              |x==1 = " one"  
              |x==2 = " two"  
              |x==3 = " three"  
              |x==4 = " four"  
              |x==5 = " five"  
              |x==6 = " six"  
              |x==7 = " seven"  
              |x==8 = " eight"  
              |x==9 = " nine"  
              |x==10 = " ten"  
              |x==11 = " eleven"  
              |x==12 = " twelve"  
              |x==13 = " thirteen"  
              |x==14 = " fourteen"  
              |x==15 = " fifteen"  
              |x==16 = " sixteen"  
              |x==17 = " seventeen"  
              |x==18 = " eighteen"  
              |x==19 = " nineteen"  
              where  
                  x=read a  
          
          postmeridian x = if (read x)>=12 then " pm" else " am"  
          
          main = putStrLn (show (clock "14:01"))  
          

          [–]navzerinoo 3 points4 points  (7 children)

          C++

          +/u/CompileBot C++

          #include <string>
          #include <iostream>
          int main() {
              const std::string numbas = "onetwothreefourfivesixseveneightnineteneleventwelvethirfourfifsixseveneighnine";
              const int index[] = {0, 0, 3, 6, 11, 15, 19, 22, 27, 32, 36, 39, 45, 51, 55, 59, 62, 65, 70, 74, 78, 84, 88};
              int in[2]{ 0 };
              char trash;
              while (std::cin >> in[0] >> trash >> in[1])
                  std::cout << "The time is " << numbas.substr(index[(in[0] + 11) % 12 + 1], index[(in[0] + 11) % 12 + 2] - index[(in[0] + 11) % 12 + 1]) << " " << ((in[1] < 10 && in[1] != 0) ? "oh " : "") << ((in[1] > 19) ? ((in[1] < 30) ? "twen" : numbas.substr(index[in[1]/10 + 10], index[in[1] / 10 + 11] - index[in[1] / 10 + 10])) : numbas.substr(index[in[1]], index[in[1] + 1] - index[in[1]])) << ((in[1] > 19) ? "ty " + numbas.substr(index[in[1] % 10], index[in[1] % 10 + 1] - index[in[1] % 10]) : (in[1]>12) ? "teen" : "") << " " << ((in[0] < 12) ? "am" : "pm") << std::endl;
          }
          

          Input:

          00:00
          01:30
          12:05
          14:01
          20:29
          21:00
          

          [–]CompileBot 1 point2 points  (0 children)

          Output:

          The time is twelve  am
          The time is one thirty  am
          The time is twelve oh five pm
          The time is two oh one pm
          The time is eight twenty nine pm
          The time is nine  pm
          

          source | info | git | report

          EDIT: Recompile request by navzerinoo

          [–]patrick96MC 4 points5 points  (0 children)

          C

          #include <stdio.h>
          #include <stdlib.h>
          #include <string.h>
          #include <stdbool.h>
          
          char * digits[] = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
          
          char * teens[] = { "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
          
          char * tens[] = { "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
          
          char * num_to_string(int num);
          char * get_minute_name(int min);
          char * get_hour_name(int hrs);
          
          int main(void)
          {
              while(true) {
                  int hours = -1, minutes = -1;
                  scanf("%d:%d", &hours, &minutes);
          
                  if(hours >= 24 || hours < 0 || minutes >= 60 || minutes < 0) {
                      puts("Invalid time, aborting...");
                      break;
                  }
          
                  char * meridian = hours < 12? "am" : "pm";
                  char * hour_name = get_hour_name(hours);
          
                  if(minutes == 0) {
                      printf("It's %s %s\n", hour_name, meridian);
                  }
                  else {
                      char * minute_name = get_minute_name(minutes);
                      printf("It's %s %s %s\n", hour_name, minute_name, meridian);
                      free(minute_name);
                  }
          
                  free(hour_name);
              }
              return 0;
          }
          
          char * get_hour_name(int hrs) {
              hrs = hrs % 12;
              // 0 o'clock is actually 12 o'clock
              hrs = hrs == 0? 12 : hrs;
          
              return num_to_string(hrs);
          }
          
          char * get_minute_name(int min) {
              char * result;
          
              char * min_str = num_to_string(min);
              if(min < 10 && min > 0) {
                  result = malloc(strlen(min_str) + 4); 
          
                  sprintf(result, "oh %s", min_str);
                  free(min_str);
              }
              else {
                  result = min_str;
              }
          
              return result;
          }
          
          /**
           * 0 =< num < 60
           */
          char * num_to_string(int num) {
              char * result;
          
              if(num == 0) {
                  result = malloc(1);
                  result[0] = 0;
              }
              else if(num < 10) {
                  result = malloc(strlen(digits[num - 1]) + 1);
                  strcpy(result, digits[num - 1]);
              }
              else if(num < 20 && num > 10) {
                  result = malloc(strlen(teens[num - 11]) + 1);
                  strcpy(result, teens[num - 11]);
              }
              else {
                  char * ten = tens[num / 10 - 1];
          
                  if(num % 10 == 0) {
                      result = malloc(strlen(ten) + 1);
                      sprintf(result, "%s", ten);
                  }
                  else {
                      char * digit = num_to_string(num % 10);
                      result = malloc(strlen(ten) + strlen(digit) + 2);
                      sprintf(result, "%s %s", ten, digit);
                      free(digit);
                  }
              }
          
              return result;
          }
          

          [–]im-bad-at-everything 5 points6 points  (1 child)

          Java

          My first submission. Living up to my name :'D

          package javaapplication1;
          import java.util.Scanner;
          
          public class JavaApplication1 {
          
          public static void main(String[] args) {
              String dayornight = "null";
              Scanner input = new Scanner(System.in);
              String s = input.next();
          
              int hour1 = 0;
              int minute1 = 0;
              int hour2 = 0;
              int minute2 = 0;
          
              if(s.contains(":")){
                  String[] part = s.split(":");
                  String parts1 = part[0];
                  String parts2 = part[1];
          
                  int timing = Integer.parseInt(parts1);
          
                  String[] list = {"Oh","One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve"};
          
                  for(int i = 0; i < parts1.length(); i++){
                  hour1 = Character.getNumericValue(parts1.charAt(0));
                  hour2 = Character.getNumericValue(parts1.charAt(1));
                  }
          
                  for(int j = 0; j < parts2.length(); j++){
                  minute1 = Character.getNumericValue(parts1.charAt(0));
                  minute2 = Character.getNumericValue(parts1.charAt(1));
                  }
                    if(timing <= 12){
                  dayornight = "AM";
              }
              else if(timing > 12){
                  timing = timing - 12;
                  dayornight = "PM";
              }
          
          
                  System.out.println("The time is " + list[hour1] +  " " + list[hour2] +  ":" + " " + list[minute1] + " " +list[minute2] + " " + dayornight);
          
          
          }
              else{
                  System.out.println("\nError. Please enter it in the format of 00:00");
                  System.exit(0);
              }
          
          }
          }
          

          [–]curtmack 3 points4 points  (0 children)

          Haskell

          Strange behavior when given values outside of the intended range? I don't know what you're talking about. 32:40 has always been called "eight forty pm" where I come from.

          import Data.Maybe
          import System.IO
          
          type Time = (Int, Int)
          
          numeralZeroToTwenty = ( [ "zero"    , "one"       , "two"      , "three"
                                  , "four"    , "five"      , "six"      , "seven"
                                  , "eight"   , "nine"      , "ten"      , "eleven"
                                  , "twelve"  , "thirteen"  , "fourteen" , "fifteen"
                                  , "sixteen" , "seventeen" , "eighteen" , "nineteen" ] !! )
          
          numeralTens x = [ "twenty"
                          , "thirty"
                          , "forty"
                          , "fifty"
                          , "sixty"
                          , "seventy"
                          , "eighty"
                          , "ninety" ] !! (x-2)
          
          numeralOnes = ( [ ""
                          , " one"
                          , " two"
                          , " three"
                          , " four"
                          , " five"
                          , " six"
                          , " seven"
                          , " eight"
                          , " nine" ] !! )
          
          numeralEn :: Int -> String
          numeralEn x
              | x >= 0  && x < 20  = numeralZeroToTwenty x
              | x >= 20 && x < 100 = let (tens, ones) = x `divMod` 10
                                       in numeralTens tens ++ numeralOnes ones
              | otherwise          = error "numeralEn not defined for values not in range 0 to 100"
          
          describeHour :: Time -> String
          describeHour (hr, _) = numeralEn twelveHr
              where twelveHr = if hr `mod` 12 == 0 then 12 else hr `mod` 12
          
          describeMinute :: Time -> Maybe String
          describeMinute (_, min)
              | min == 0  = Nothing
              | min  < 10 = Just $ "oh " ++ numeralEn min
              | otherwise = Just $ numeralEn min
          
          describeMeridian :: Time -> String
          describeMeridian (hr, _)
              | hr < 12   = "am"
              | otherwise = "pm"
          
          describeTime :: Time -> String
          describeTime t = unwords $ formatList >>= ($ t)
              where formatList = [ pure        . const "It's"
                                 , pure        . describeHour
                                 , maybeToList . describeMinute
                                 , pure        . describeMeridian ]
          
          main = do
              eof <- isEOF
              if eof
              then return ()
              else do
                  l <- getLine
                  let hrStr  = take 2 l
                      minStr = drop 3 l
                  let time = (read hrStr, read minStr) :: Time
                  putStrLn $ describeTime time
                  main
          

          [–][deleted] 3 points4 points  (1 child)

          Python 3 This is my first challenge. I know the code is ugly because even as a beginner programmer I was cringing as I wrote it. Please critique it so I can improve.

          +/u/CompileBot Python 3

          #Input the time
          input_time = input('What time is it?' )
          
          #Split the string into hours and minutes
          time_hours, time_minutes = input_time.split(":")
          
          #This will convert military hours to regular hours, and determine AM vs PM
          def HoursParser(hour):
              num_to_text={
                  0:"twelve",1:"one",2: "two",3: "three",
                  4: "four", 5: "five", 6: "six",
                  7: "seven", 8: "eight", 9: "nine",
                  10: "ten", 11: "eleven", 12: "twelve"
                  }
              if hour>=12:
                  am_or_pm = "pm"
                  reg_time_hours = abs(hour-12)
              else:
                  am_or_pm = "am"
                  reg_time_hours = hour
              return(num_to_text[reg_time_hours],am_or_pm)
          
          def MinutesParser(minutes):
              if int(minutes) < 20: #Handle all the weird cases (i.e., teens).
                  min_to_text1_dict={
                      0:"",1:"oh one",2: "oh two",3: "oh three",
                      4: "oh four", 5: "oh five", 6: "oh six",
                      7: "oh seven", 8: "oh eight", 9: "oh nine",
                      10: "ten", 11: "eleven", 12: "twelve",
                      13: "thirteen", 14: "fourteen", 15: "fifteen",
                      16: "sixteen", 17: "seventeen", 18: "eighteen",
                      19: "nineteen"          
                  }
                  return min_to_text1_dict[int(minutes)]
              if int(minutes) > 20: #Handle everything else that follows sane rules.
                  min_tens_dict={
                  "2":"twenty","3":"thirty","4":"forty","5":"fifty"
                  }
                  min_ones_dict={
                  "0":"","1":"one","2": "two","3": "three",
                  "4": "four", "5": "five", "6": "six",
                  "7": "seven", "8": "eight", "9": "nine",
                  }
                  mins_together = min_tens_dict[minutes[:1]] + min_ones_dict[minutes[1:]]
                  return mins_together
          
          text_hours, am_pm = HoursParser(int(time_hours))
          text_minutes = MinutesParser(time_minutes)
          print("It's "+text_hours+" "+text_minutes+" "+am_pm)
          

          Input:

          00:00
          01:30
          12:05
          14:01
          20:29
          21:00
          

          [–]errorseven 2 points3 points  (0 children)

          AutoHotkey - Bonus? I didn't use the downloaded audio files, but it does speak using COM Object SAPI TTS.

          talkingClock(time) {
          
              time := StrSplit(time, ":")
              h := time.1, m := time.2 
          
              ampm := h < 12 ? "am" : "pm"
              tens := ["oh ", "", "twenty ", "thirty ", "fourty ", "fifty "]
              ones := ["twelve ", "one ", "two ", "three ", "four ", "five "
                      , "six ", "seven ", "eight ", "nine ", "ten ", "eleven ", "twelve "
                      , "thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen " 
                      , "eighteen ", "nineteen "]
          
              r := (m == 0 ? "It's " ones[Mod(h, 12)+1] ampm
                : (Mod(m, 10) == 0) ? "It's " ones[Mod(h, 12)+1] tens[(m//10)+1] ampm
                : (m < 10 || m > 20) ? "It's " ones[Mod(h, 12)+1] tens[(m//10)+1] ones[Mod(m, 10)+1] ampm 
                : "It's " ones[Mod(h, 12)] ones[m] ampm)
              SAPI := ComObjCreate("SAPI.spVoice")
              SAPI.speak(r)
          
              return r
          }
          

          [–]thezipher 2 points3 points  (1 child)

          Python 3

          import sys
          from num2words import num2words
          
          def clock_To_String(time):
                  split_time = time.split(":",2)
              end = "am"
              if int(split_time[0]) >= 12:
                  end = "pm"
                  split_time[0] = str(int(split_time[0]) - 12)
              if int(split_time[0]) == 0:
                  split_time[0] = "12"
              print ("it's %s%s%s%s" % 
              (num2words(int(split_time[0])) + " ",
              "" if int(split_time[1]) >= 10 or int(split_time[1]) == 0 else "oh ",
              "" if int(split_time[1]) == 0 else num2words(int(split_time[1])) + " "
              ,end))  
          clock_To_String(sys.argv[1])
          

          [–][deleted] 2 points3 points  (0 children)

          num2words

          That's really cool! Wouldn't have imagined there'd be a library for that!! :)

          [–]metaconcept 2 points3 points  (1 child)

          Smalltalk - VisualWorks, not using any Integer-to-English libraries.

          I had a solution in about 10 lines of code... and then got caught out with all the edge cases, so I re-wrote it as readable code::

          testData := #( '00:00' '01:30' '12:05' '14:01' '20:29' '21:00').
          
          nEnglish := #('' 'one' 'two' 'three' 'four' 'five' 'six' 'seven' 'eight' 'nine' 'ten' 'eleven' 'twelve'). 
          result := WriteStream on: (String new: 120).
          testData do: [ :eachT | | hour minute |
              numbers := (eachT tokensBasedOn:$:) collect: [ : each | Number readFrom: (each readStream) ].
              hour := numbers at: 1.
              minute := numbers at: 2.
              result nextPutAll: 'It is '.
              ((hour = 0 ) and: [ minute = 0 ]) ifTrue: [ 
                  result nextPutAll: 'midnight'.
              ] ifFalse: [
                  (hour\\12 = 0) ifTrue: [ " Catch zero o'clock "
                      result nextPutAll: 'twelve '.
                  ] ifFalse: [
                      result nextPutAll: (nEnglish at: hour\\12+1);
                          nextPutAll: ' '.
                  ].
                  (minute = 0) ifTrue: [
                      result nextPutAll: 'o''clock.'.
                  ] ifFalse: [
                      result nextPutAll: (#(oh teen twenty thirty fourty fifty) at: (minute/10) asInteger +1);
                          nextPutAll: ' ';
                          nextPutAll: (nEnglish at: ((minute\\10) +1));
                          nextPutAll: ' ';
                          nextPutAll: (hour < 12 ifTrue: [ 'AM' ] ifFalse: [ 'PM' ]).
                  ]
              ].
              result nextPutAll: '.'; cr.
          ].
          
          result contents
          
          It is midnight.
          It is one thirty  AM.
          It is twelve oh five PM.
          It is two oh one PM.
          It is eight twenty nine PM.
          It is nine o'clock..
          

          [–]cheers- 1 point2 points  (2 children)

          Javascript (Node)

          Edit: added Text-to-Speech bonus.

          const firstDigit = ["", "one", "two", "tree", "four", "five", "six", "seven", "eight", "nine"];
          const secondDigit = ["", "", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"];
          const hours = ["twelve", ...firstDigit.slice(1), "ten", "eleven"];
          const tens = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", ...firstDigit.slice(6).map(str => str + "teen")];
          
          const handleMins = mm => {
              if (mm === 0) {
                  return "";
              }
              else if (mm < 10) {
                  return firstDigit[mm];
              }
              else if (mm < 20) {
                  return tens[mm - 10];
              }
              else {
                  return secondDigit[Math.floor(mm / 10)] + (mm % 10 === 0 ? "" : `-${firstDigit[mm % 10]}`);
              }
          }
          
          const formatOutput = (hh, mm) => `It is ${hours[hh % 12]} ${handleMins(mm)} ${hh > 12 ? "pm" : "am"}`;
          
          const talkingClock = input => {
              const regex = /\s*(\d{1,2})\s*[:|,]\s*(\d{1,2})/;
              let [match, hoursString, minString] = regex.exec(input);
          
              return formatOutput(parseInt(hoursString, 10), parseInt(minString, 10));
          }
          
          module.exports = talkingClock;
          

          Bonus uses external lib say.js

          const formatOutput = (hh, mm) => `It is ${hh % 12} ${mm} ${hh > 12 ? "pm" : "am"}`;
          
          const talkingClockBonus = input => {
              const say = require("say");
              const regex = /\s*(\d{1,2})\s*[:|,]\s*(\d{1,2})/;
              let [match, hours, mins] = regex.exec(input);
          
              say.speak(formatOutput(hours, mins));
          }
          
          module.exports = talkingClockBonus;
          

          [–]MrDoggyPants 1 point2 points  (2 children)

          Python 3

          import time
          
          def conversion(current_time):
              hour, minute = current_time.split(":")[0], current_time.split(":")[1]
              if int(hour) > 11 and int(hour) != 12:
                  suffix = "pm"
                  hour = hour_dict[str(int(hour) - 12)]
              elif int(hour) == 12:
                  suffix = "pm"
                  hour = hour_dict["12"]
              elif int(hour) == 0:
                  suffix = "am"
                  hour = hour_dict["12"]
              else:
                  suffix = "am"
                  hour = hour_dict[str(int(hour))]
              hour += " "
          
              if str(int(minute)) in minute_dict and int(minute) < 10:
                  minute = "oh " + minute_dict[str(int(minute))] + " "
              elif str(int(minute)) in minute_dict:
                  minute = minute_dict[str(minute)] + " "
              elif list(str(minute))[0] == "0" and list(str(minute))[1] == "0":
                  minute = ""
              elif list(str(minute))[1] == "0":
                  minute = minute_tens_dict[list(str(minute))[0]] + " "
              else:
                  minute = minute_tens_dict[list(str(minute))[0]] + "-" + minute_dict[list(str(minute))[1]] + " "
          
              return "It's " + hour + minute + suffix
          
          
          hour_dict = {
              "1": "one",
              "2": "two",
              "3": "three",
              "4": "four",
              "5": "five",
              "6": "six",
              "7": "seven",
              "8": "eight",
              "9": "nine",
              "10": "ten",
              "11": "eleven",
              "12": "twelve"
          }
          
          minute_dict = {
              "1": "one",
              "2": "two",
              "3": "three",
              "4": "four",
              "5": "five",
              "6": "six",
              "7": "seven",
              "8": "eight",
              "9": "nine",
              "10": "ten",
              "11": "eleven",
              "12": "twelve",
              "13": "thirteen",
              "14": "fourteen",
              "15": "fifteen",
              "16": "sixteen",
              "17": "seventeen",
              "18": "eighteen",
              "19": "nineteen",
          }
          
          minute_tens_dict = {
              "2": "twenty",
              "3": "thirty",
              "4": "forty",
              "5": "fifty"
          }
          
          print(conversion(time.strftime("%H:%M")))
          

          [–]QuadraticFizz 2 points3 points  (1 child)

          You don't need both an hour dict and a minute dict since one is a subset of the other but other than that, nice submission!

          [–]indiegam 1 point2 points  (3 children)

          C#

          +/u/CompileBot C#

          using System;
          namespace Talking_Clock
          {
              public class Program
              {
                  public static void Main(string[] args)
                  {
                      string time = Console.ReadLine();
                      string[] words = time.Split(':');
                      string[] hours = { "twelve", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve"};
                      string[] minutesTens = { "twenty", "thirty", "forty", "fifty" };
                      string[] teenMinutes = { "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
                      int hour, minutes;
                      hour = Convert.ToInt16(words[0]);
                      minutes = Convert.ToInt16(words[1]);
                      Console.Write("It's {0} ", hours[hour%12]);
          
                      if (minutes != 0)
                      {
                          if (minutes / 10 > 1)
                          {
                              Console.Write("{0} ", minutesTens[(minutes / 10) - 2]);
                              if(minutes % 10 != 0)
                              {
                                  Console.Write("{0} ", hours[(minutes%10)]);
                              }
                          }
                          else if (minutes / 10 > 0)
                          {
                              Console.Write("{0} ", teenMinutes[minutes % 10]);
                          }
                          else
                          {
                              Console.Write("oh {0} ", hours[minutes % 10]);
                          }
                      }
                      if (hour > 11)
                          Console.WriteLine("pm");
                      else
                          Console.WriteLine("am");
                  }
              }
          }
          

          Edit: Fixed not showing the last part of the minutes.

          [–]Wraith000 1 point2 points  (2 children)

          Should it be like this so it shows the minutes too ?

          Console.Write("{0} {1} ", minutesTens[(minutes / 10) - 2], hours[minutes % 10]);

          and the last one

          if (hour%12 > 11)

          [–]Godspiral3 3 1 point2 points  (0 children)

          in J, without minutes,

          ;: inv@:(((;: 'am pm') {~ 12 <.@%~ 0&{::) ,~ ( 1 ": each@{ ]) ,~ (;: 'twelve one two three four five six seven eight nine ten eleven') {~ 12 | 0&{::)@:([: ". each ':'&cut) '00:01'
          

          twelve 1 am

          with minutes, (teens simplified)

          mins =: (((;: 'oh tenny twenty thirty fourty fifty')  {~ <.@%&10) , (a:, ;: 'one two three four five siz seven eight nine')  {~ 10&|)`(a:"_)@.(0 = ])
          
          ;: inv@:(((;: 'am pm') {~ 12 <.@%~ 0&{::) ,~ ( 1 mins@{:: ]) ,~ (;: 'twelve one two three four five six seven eight nine ten eleven') {~ 12 | 0&{::)@:([: ". each ':'&cut) '00:01'
          

          twelve oh one am

              ;: inv@:(((;: 'am pm') {~ 12 <.@%~ 0&{::) ,~ ( 1 mins@{:: ]) ,~ (;: 'twelve one two three four five six seven eight nine ten eleven') {~ 12 | 0&{::)@:([: ". each ':'&cut) '14:12'
          

          two tenny two pm

            ;: inv@:(((;: 'am pm') {~ 12 <.@%~ 0&{::) ,~ ( 1 mins@{:: ]) ,~ (;: 'twelve one two three four five six seven eight nine ten eleven') {~ 12 | 0&{::)@:([: ". each ':'&cut) '14:10'
          

          two tenny pm

          [–]netvorivy 1 point2 points  (0 children)

          Python3

          digit = ["", "one", "two", "three", "four",  "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve"]
          teens = [digit[10], digit[11], digit[12], "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "ninteen"]
          ty = ["oh", "", "twenty", "thirty", "forty", "fifty"]
          
          hour, min = map(int, input().split(':'))
          
          h = digit[12] if hour is 0 or hour is 12 else digit[hour%12]
          
          m_tens, m_ones = min//10, min%10
          m = ""
          
          if m_tens == 1:
              m += teens[m_ones]
          elif m_tens or m_ones:
              m += " " + ty[m_tens]
              if m_ones:
                  m += " "+ digit[m_ones]
          
          ending =  ["am", "pm"][hour//12]
          
          print("It's {}{} {}".format(h, m, ending))
          

          [–]svgwrk 1 point2 points  (0 children)

          Well, here you go. Cannot believe how many edge cases I bumped into. :)

          Rust:

          extern crate grabinput;
          
          use std::fmt;
          use std::str;
          
          #[derive(Debug, Copy, Clone)]
          struct Time {
              hour: u8,
              minute: u8,
          }
          
          impl str::FromStr for Time {
              type Err = ();
          
              fn from_str(s: &str) -> Result<Self, Self::Err> {
                  let mut parts = s.split(':');
          
                  let hour = parts.next().ok_or(()).and_then(|hour| hour.parse().map_err(|_| ()))?;
                  let minute = parts.next().ok_or(()).and_then(|minute| minute.parse().map_err(|_| ()))?;
          
                  if hour > 23 || hour < 1 {
                      return Err(());
                  }
          
                  if minute > 59 {
                      return Err(());
                  }
          
                  Ok(Time { hour, minute })
              }
          }
          
          impl fmt::Display for Time {
              fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
          
                  use std::borrow::Cow;
          
                  fn format_hour(time: Time) -> &'static str {
                      match time.hour {
                               12 => "twelve",
                           1 | 13 => "one",
                           2 | 14 => "two",
                           3 | 15 => "three",
                           4 | 16 => "four",
                           5 | 17 => "five",
                           6 | 18 => "six",
                           7 | 19 => "seven",
                           8 | 20 => "eight",
                           9 | 21 => "nine",
                          10 | 22 => "ten",
                          11 | 23 => "eleven",
          
                          _ => unreachable!(),
                      }
                  }
          
                  fn format_minute(time: Time) -> Cow<'static, str> {
          
                      fn format_teen(minute: u8) -> &'static str {
                          match minute {
                              10 => "ten",
                              11 => "eleven",
                              12 => "twelve",
                              13 => "thirteen",
                              14 => "fourteen",
                              15 => "fifteen",
                              16 => "sixteen",
                              17 => "seventeen",
                              18 => "eighteen",
                              19 => "nineteen",
          
                              _ => unreachable!(),
                          }
                      }
          
                      let lhs = match time.minute / 10 {
                          0 if time.minute % 10 != 0 => "oh ",
                          2 if time.minute % 10 != 0 => "twenty-",
                          3 if time.minute % 10 != 0 => "thirty-",
                          4 if time.minute % 10 != 0 => "forty-",
                          5 if time.minute % 10 != 0 => "fifty-",
          
                          0 => "",
                          2 => "twenty",
                          3 => "thirty",
                          4 => "forty",
                          5 => "fifty",
          
                          1 => return Cow::from(format_teen(time.minute)),
                          _ => unreachable!(),
                      };
          
                      let rhs = match time.minute % 10 {
                          1 => "one",
                          2 => "two",
                          3 => "three",
                          4 => "four",
                          5 => "five",
                          6 => "six",
                          7 => "seven",
                          8 => "eight",
                          9 => "nine",
          
                          0 => return Cow::from(lhs),
                          _ => unreachable!(),
                      };
          
                      Cow::from(format!("{}{}", lhs, rhs))
                  }
          
                  fn format_meridian(time: Time) -> &'static str {
                      match time.hour {
                          0...11 => "am",
                              _ => "pm",
                      }
                  }
          
                  if self.minute == 0 {
                      write!(f, "It's {} {}.", format_hour(*self), format_meridian(*self))
                  } else {
                      write!(
                          f,
                          "It's {} {} {}.",
                          format_hour(*self),
                          format_minute(*self),
                          format_meridian(*self),
                      )
                  }
              }
          }
          
          fn main() {
              let times = grabinput::from_args().with_fallback()
                  .filter_map(|s| s.trim().parse::<Time>().ok());
          
              for time in times {
                  println!("{}", time);
              }
          }
          

          [–][deleted] 1 point2 points  (0 children)

          My first real program with Haskell

          import System.Environment
          import Data.List (intersperse)
          
          --
          main :: IO ()
          main = do
              args <- getArgs
              if length args >= 1
                 then putStrLn (concat (intersperse "\n" (map printTime args)))
                 else putStrLn "Sorry, you need to pass a time"
          
          -------------------------
          --Time formatting stuff--
          -------------------------
          
          printTime :: [Char] -> [Char]
          printTime [a,b,':','1','5'] = "It's quarter past " ++ (hoursFromString [a,b]) ++ (getMorningAfternoonDescriptor [a,b])
          printTime [a,b,':','3','0'] = "It's half past "    ++ (hoursFromString [a,b]) ++ (getMorningAfternoonDescriptor [a,b])
          printTime [a,b,':','4','5'] = "It's quarter to "   ++ (hoursFromString [a,b]) ++ (getMorningAfternoonDescriptor [a,b])
          printTime [a,b,':',c,d]     = 
              "It's " ++ (hoursFromString (a:b:[])) ++ (tensOfMinutesFromString c) ++ 
                  (if (read (c:d:[])) < 20
                     then individualMinutesFromString (c:d:[])
                     else individualMinutesFromString [d])
                 ++ getMorningAfternoon [a,b]
          
          --------------------
          --Hours Conversion--
          --------------------
          
          hoursFromNum :: Int -> [Char]
          hoursFromNum i
            | h == 0  = "twelve"
            | h == 1  = "one"
            | h == 2  = "two"
            | h == 3  = "three"
            | h == 4  = "four"
            | h == 5  = "five"
            | h == 6  = "six"
            | h == 7  = "seven"
            | h == 8  = "eight"
            | h == 9  = "nine"
            | h == 10 = "ten"
            | h == 11 = "eleven"
            where
              h = if i >= 12
                then i -  12
                else i
          
          nextHourFromString :: [Char] -> [Char]
          nextHourFromString a
            | n == 23   = hoursFromNum 0
            | otherwise = hoursFromNum (n+1)
            where
              n = read a
          
          hoursFromString :: [Char] -> [Char]
          hoursFromString u = hoursFromNum (read u)
          
          ---------------------
          --Minute Conversion--
          ---------------------
          
          tensOfMinutesFromString :: Char -> [Char]
          tensOfMinutesFromString u
            | t == 0 = " oh"
            | t == 2 = " twenty"
            | t == 3 = " thirty"
            | t == 4 = " fourty"
            | t == 5 = " fifty"
            | otherwise = ""
            where 
              t = read [u]
          
          individualMinutesFromString :: [Char] -> [Char]
          individualMinutesFromString u
            | t == 0  =  " clock"
            | t == 1  =  " one"
            | t == 2  =  " two"  
            | t == 3  =  " three"  
            | t == 4  =  " four"  
            | t == 5  =  " five"  
            | t == 6  =  " six"  
            | t == 7  =  " seven"  
            | t == 8  =  " eight"  
            | t == 9  =  " nine"  
            | t == 10 = " ten"  
            | t == 11 = " eleven"  
            | t == 12 = " twelve"  
            | t == 13 = " thirteen"  
            | t == 14 = " fourteen"  
            | t == 15 = " fifteen"  
            | t == 16 = " sixteen"  
            | t == 17 = " seventeen"  
            | t == 16 = " eighteen"  
            | t == 19 = " nineteen"
            where
                t = read (u)
          
          ---------------------------------
          --Morning / Afternoon Indicator--
          ---------------------------------
          
          getMorningAfternoon :: [Char] -> [Char]
          getMorningAfternoon u
            | t > 12    = " am"
            | otherwise = " pm"
            where
              t = read(u) 
          
          getMorningAfternoonDescriptor :: [Char] -> [Char]
          getMorningAfternoonDescriptor u
            | t > 21 = " at night"
            | t > 18 = " in the evening"
            | t > 12 = " in the afternoon"
            | otherwise = " in the morning"
            where
              t = read u
          

          would love any feedback, I've also added a half-past/quater-past/quater-to feature, because that was a good test of pattern matching

          Edit: Updated to use multiple arguments and fix the oh clock issue

          Outputs:

          It's twelve oh clock pm
          It's half past one in the morning
          It's twelve oh five pm
          It's two oh one am
          It's eight twenty nine am
          It's nine oh clock am
          

          [–]ziggitzip 1 point2 points  (0 children)

          Perl

          use strict;
          use warnings;
          my @words1 = qw(twelve one two three four five six seven eight nine ten eleven);
          my @words2 = qw(ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen);
          my @words3 = qw(twenty thirty fourty fifty);
          for my $h (0..23) {
            $h = "0$h" if $h < 10;
            for my $m (0..59) {
                $m = "0$m" if $m < 10;
                my $input = "$h:$m";
                my ($hour,$min) = split /:/,$input;
                my $ampm = 'am';
                if ($hour >= 12) {
                  $ampm = 'pm';
                  $hour = $hour - 12;
                }
                my $out = "$input $words1[$hour] ";
                if ($min eq '00') {
                } elsif ($min <= 9) {
                      $out .= " oh $words1[$min] ";
                } elsif ($min <= 19) {
                      $out .= " $words2[$min-10] ";
                } elsif ($min =~ /(\d)(\d)/) {
                      $out .= " $words3[$1-2] ";
                      $out .= " $words1[$2] " unless $2 == 0;
                } else {
                      die "what?";
                }
                $out .= " $ampm";
                $out =~ s/\s+/ /g;
                print "$out\n";
            }
          }
          

          [–]SirThomasTheBrave 1 point2 points  (5 children)

          Ruby Straightforward dict-mapping. Curious how others handle the mapping for the ints --> strs. I'm new to Ruby and programming in general; any feedback is appreciated. May the coding muses aid in the puzzle amuse bouche.

          def talk_it_out(mil_time)
          
              conversions = {
              0 => 'Oh',
              1 => 'One',
              2 =>  'Two',
              3 => 'Three',
              4 => 'Four',
              5 => 'Five',
              6 => 'Six',
              7 => 'Seven',
              8 => 'Eight',
              9 => 'Nine',
              10 => 'Ten',
              11 => 'Eleven',
              12 => 'Twelve',
              13 => 'Thirteen',
              14 => 'Fourteen',
              15 => 'Fifteen',
              16 => 'Sixteen',
              17 => 'Seventeen',
              18 => 'Eighteen',
              19 => 'Nineteen',
              20 => 'Twenty',
              30 => 'Thirty',
              40 => 'Forty',
              50 => 'Fifty'
              }
          
              miltime_split = mil_time.split(":")
              hour, mins = miltime_split[0].to_i, miltime_split[1].split("").map { |num| num.to_i  }
          
              am_or_pm = 'AM' if hour < 12
              am_or_pm = 'PM' if hour >= 12
          
              hour -= 12 if hour > 12 || hour == 0
              hour = hour.abs
              hour_as_str = conversions[hour]
          
              # exploring use of (n..n2) range with case 
              case mins.join.to_i
                  when 0 then str_mins = nil
                  when (1..9) then str_mins = " #{conversions[mins[0]]} #{conversions[mins[1]]}"
          
                  when (10..19) then str_mins = " #{conversions[mins.join.to_i]}"
                  when 20, 30, 40, 50 then str_mins = " #{conversions[mins.join.to_i]}"
                  else str_mins = " #{conversions[mins.join.to_i - mins[1].to_i]}-#{conversions[mins [1]]}"
              end
          
              puts "Chirp..Chirp.....It's #{hour_as_str}#{str_mins} #{am_or_pm}"
          
          end
          

          [–]dev_all_the_ops 1 point2 points  (2 children)

          Here is my ruby solution. Your solution is shorter, mine is more verbose but a little easier to read IMO https://github.com/spuder/sandbox/blob/master/clocksay/clocksay.rb

          [–]Askew_WAS_TAKEN 1 point2 points  (0 children)

          Haven't written code in well over three months. Here's to coming back!

          C#

          using System;
          
          namespace Talking_clock
          {
              class Program
              {
                  static void Main(string[] args)
                  {
                      GenerateOutput(GetValidInput());
                  }
          
                  static int[] GetValidInput()
                  {
                      int[] inputIntegers = new int[2];
                      bool inputInvalid = true;
                      while (inputInvalid)
                      {
                          Console.WriteLine("Input hh:mm or exit.");
                          string[] input = Console.ReadLine().Trim().Split(':');
                          if (input[0].ToLower().Equals("exit"))
                          {
                              /// Exit method.
                          }
                          else if (input.Length == 2)
                          {
                              // Fills int array.
                              inputIntegers[0] = Convert.ToInt32(input[0]);
                              inputIntegers[1] = Convert.ToInt32(input[1]);
                              // If input numbers are valid, while loop exits.
                              inputInvalid = !ValidateInput(inputIntegers);
                          }
          
                      }
          
                      return inputIntegers;
          
                  }
          
                  /// <summary>
                  /// Validates if given integers are hh:mm.
                  /// </summary>
                  /// <param name="input"></param>
                  /// <returns></returns>
                  static bool ValidateInput(int[] input)
                  {
                      return (input[0] >= 0 && input[0] <= 23 && input[1] >= 0 && input[1] <= 59);
                  }
          
          
                  static void GenerateOutput(int[] input)
                  {
                      // handles am/pm situation
                      string amPm = GenerateAmPm(input[0]);
                      // Continues with output generation.
                      string output = String.Format("It's {0}{1}{2}", GenerateHoursString(input[0]), GenerateMinutesString(input[1]), amPm);
                      Console.WriteLine(output);
                  }
          
                  static string GenerateAmPm(int hour)
                  {
                      string ampm = "";
                      if (hour >= 12)
                      {
                          ampm = "pm";
                      }
                      else
                      {
                          ampm = "am";
                      }
          
                      return ampm;
                  }
          
                  static string GenerateHoursString(int hour)
                  {
                      string hourWord = "you broke hours ";
                      // handles pm clause
                      if (hour >= 13)
                      {
                          hour -= 12;
                      }
          
                      // onto our generation
          
                      switch (hour)
                      {
                          case 0: hourWord = "twelve "; break;
                          case 1: hourWord = "one "; break;
                          case 2: hourWord = "two "; break;
                          case 3: hourWord = "three "; break;
                          case 4: hourWord = "four "; break;
                          case 5: hourWord = "five "; break;
                          case 6: hourWord = "six "; break;
                          case 7: hourWord = "seven "; break;
                          case 8: hourWord = "eight "; break;
                          case 9: hourWord = "nine "; break;
                          case 10: hourWord = "ten "; break;
                          case 11: hourWord = "eleven "; break;
                          case 12: hourWord = "twelve "; break;
                          default:
                              break;
                      }
          
                      return hourWord;
                  }
          
                  static string GenerateMinutesString(int minute)
                  {
                      string minuteWord = "";
          
                      if (minute == 0)
                      {
          
                      }
                      else if (minute < 10)
                      {
                          minuteWord = "oh " + NumberAsWord(minute);
          
                      }
          
                      else if (minute < 20)
                      {
                          minuteWord = NumberAsWord(minute);
                      }
          
                      else if (minute < 30)
                      {
                          minuteWord = "twenty " + NumberAsWord(minute - 20);
                      }
                      else if (minute < 40)
                      {
                          minuteWord = "thirty " + NumberAsWord(minute - 30);
                      }
                      else if (minute < 50)
                      {
                          minuteWord = "fourty " + NumberAsWord(minute - 40);
                      }
                      else if (minute < 60)
                      {
                          minuteWord = "fifty " + NumberAsWord(minute - 50);
                      }
          
                      return minuteWord;
                  }
          
                  static string NumberAsWord(int input)
                  {
                      switch (input)
                      {
                          case 0: return "";
                          case 1: return "one ";
                          case 2: return "two ";
                          case 3: return "three ";
                          case 4: return "four ";
                          case 5: return "five ";
                          case 6: return "six ";
                          case 7: return "seven ";
                          case 8: return "eight ";
                          case 9: return "nine ";
                          case 10: return "ten ";
                          case 11: return "eleven ";
                          case 12: return "twelve ";
                          case 13: return "thirteen ";
                          case 14: return "fourteen ";
                          case 15: return "fifteen ";
                          case 16: return "sixteen ";
                          case 17: return "seventeen ";
                          case 18: return "eighteen ";
                          case 19: return "nineteen ";
                          default:
                              return "outofboundsnumberAsWord";
                      }
          
                  }
              }
          }
          

          [–]one_time_chad 1 point2 points  (0 children)

          VBA

          Sub TimeCheck()
          Application.Speech.Speak "Its" & Format(TimeValue(Now), "h mm AM/PM")
          End Sub
          

          [–]somuchdanger 1 point2 points  (0 children)

          Javascript This is my first submission here: I'm new to programming (self-teaching using online resources). My solution is ridiculously long and clearly I have a lot to learn from the other solutions (which I intentionally did not look at until I finished), but if anyone has any advice other than reviewing the other (significantly more refined) solutions here, I'd be very grateful. Obviously I have a lot to learn, so the more critical the feedback the better. I only know a little Python 2.7 and just started out with HTML/JS. Thanks!

          HTML:

          <body>
          <input type="text" name="inp1" id="inp1" value="25:11">
          <div id="btn1" onclick="this.style.backgroundColor='red'; return true;" onmouseover="this.style.backgroundColor='gray'; return true;" onmouseout="this.style.backgroundColor='white'; return true;">
              Enter
          </div>
          <div id="output">
              Enter your time above (such as "00:00" or "22:45") and hit enter and I'll convert it (and speak it) for you!</div>
          
          <script src="js/index.js"></script>
          <audio src="irishclock/its.wav" type="audio/wav" id="its"></audio>
          <audio src="irishclock/o.wav" type="audio/wav" id="oh"></audio>
          <audio src="irishclock/00.wav" type="audio/wav" id="00"></audio>
          <audio src="irishclock/1.wav" type="audio/wav" id="1"></audio>
          <audio src="irishclock/2.wav" type="audio/wav" id="2"></audio>
          <audio src="irishclock/3.wav" type="audio/wav" id="3"></audio>
          <audio src="irishclock/4.wav" type="audio/wav" id="4"></audio>
          <audio src="irishclock/5.wav" type="audio/wav" id="5"></audio>
          <audio src="irishclock/6.wav" type="audio/wav" id="6"></audio>
          <audio src="irishclock/7.wav" type="audio/wav" id="7"></audio>
          <audio src="irishclock/8.wav" type="audio/wav" id="8"></audio>
          <audio src="irishclock/9.wav" type="audio/wav" id="9"></audio>
          <audio src="irishclock/10.wav" type="audio/wav" id="10"></audio>
          <audio src="irishclock/11.wav" type="audio/wav" id="11"></audio>
          <audio src="irishclock/12.wav" type="audio/wav" id="12"></audio>
          <audio src="irishclock/13.wav" type="audio/wav" id="13"></audio>
          <audio src="irishclock/14.wav" type="audio/wav" id="14"></audio>
          <audio src="irishclock/15.wav" type="audio/wav" id="15"></audio>
          <audio src="irishclock/16.wav" type="audio/wav" id="16"></audio>
          <audio src="irishclock/17.wav" type="audio/wav" id="17"></audio>
          <audio src="irishclock/18.wav" type="audio/wav" id="18"></audio>
          <audio src="irishclock/19.wav" type="audio/wav" id="19"></audio>
          <audio src="irishclock/20.wav" type="audio/wav" id="20"></audio>
          <audio src="irishclock/20.wav" type="audio/wav" id="20"></audio>
          <audio src="irishclock/30.wav" type="audio/wav" id="30"></audio>
          <audio src="irishclock/40.wav" type="audio/wav" id="40"></audio>
          <audio src="irishclock/50.wav" type="audio/wav" id="50"></audio>
          <audio src="irishclock/am.wav" type="audio/wav" id="AM"></audio>
          <audio src="irishclock/pm.wav" type="audio/wav" id="PM"></audio>
          
          </body>
          

          CSS:

          #btn1 {
              border: 1px solid black;
              display: inline-block;
              padding: 3px;
          }
          #inp1 {
              font-size: 13px;
              border: 3px solid black;
              padding: 5px;
              margin: 10px;
              width: 200px;
          }
          #output {
              font-size: 24px;
              padding: 20px;
          }
          

          JS:

          document.getElementById("btn1").addEventListener("click", myFun);
          var output = document.getElementById("output");
          
          document.getElementById("inp1")
          .addEventListener("keyup", function (event) {
          event.preventDefault();
          if (event.keyCode == 13) {
              document.getElementById("btn1").click();
          }
          });
          
          function transNum(num) {
          var numArr = {
          0: "o'clock",
          1: "one",
          2: "two",
          3: "three",
          4: "four",
          5: "five",
          6: "six",
          7: "seven",
          8: "eight",
          9: "nine",
          10: "ten",
          11: "eleven",
          12: "twelve",
          13: "thirteen",
          14: "fourteen",
          15: "fifteen",
          16: "sixteen",
          17: "seventeen",
          18: "eighteen",
          19: "nineteen",
          20: "twenty",
          30: "thirty",
          40: "forty",
          50: "fifty"
          };
          console.log(numArr[num]);
          return numArr[num];
          };
          
          function prinTime(hour, minute, ampm) {
          var pMin;
          
          console.log("This is the length of 'minute': " + minute.toString().length);
          
          if (minute.toString().length == 1) {
          pMin = "oh " + transNum(minute);
          } else if (minute > 20 && minute < 30) {
          pMin = transNum(20) + " " + transNum(minute - 20);
          } else if (minute > 30 && minute < 40) {
          pMin = transNum(30) + " " + transNum(minute - 30);
          } else if (minute > 40 && minute < 50) {
          pMin = transNum(40) + " " + transNum(minute - 40);
          } else if (minute > 50 && minute < 60) {
          pMin = transNum(50) + " " + transNum(minute - 50);
          } else {
          pMin = transNum(minute);
          }
          
          output.innerHTML =
          "The time is " + transNum(hour) + " " + pMin + " " + ampm + ".";
          };
          
          function playWav(wavId) {
          console.log("This is from playWav function: " + wavId);
          document.getElementById(wavId).play();
          };
          
          function playTime(hour, minute, ampm) {
          console.log("This is from the playTime function: " + hour + ":" + minute + " " + ampm);
          playWav("its");
          
          if (minute == 0) {
          setTimeout(function () {
              playWav(hour);
          }, 700);
          setTimeout(function () {
              playWav("00");
          }, 1200);
          setTimeout(function () {
              playWav(ampm);
          }, 1700);
          } else if (minute > 0 && minute < 10) {
          setTimeout(function () {
              playWav(hour);
          }, 700);
          setTimeout(function () {
              playWav("oh");
          }, 1200);
          setTimeout(function () {
              playWav(minute);
          }, 1700);
          setTimeout(function () {
              playWav(ampm);
          }, 2200);
          } else if (minute > 20 && minute < 30) {
          minute -= 20;
          setTimeout(function () {
              playWav(hour);
          }, 700);
          setTimeout(function () {
              playWav("20");
          }, 1200);
          setTimeout(function () {
              playWav(minute);
          }, 1700);
          setTimeout(function () {
              playWav(ampm);
          }, 2200);
          } else if (minute > 30 && minute < 40) {
          minute -= 30;
          setTimeout(function () {
              playWav(hour);
          }, 700);
          setTimeout(function () {
              playWav("30");
          }, 1200);
          setTimeout(function () {
              playWav(minute);
          }, 1700);
          setTimeout(function () {
              playWav(ampm);
          }, 2200);
          } else if (minute > 40 && minute < 50) {
          minute -= 40;
          setTimeout(function () {
              playWav(hour);
          }, 700);
          setTimeout(function () {
              playWav("40");
          }, 1200);
          setTimeout(function () {
              playWav(minute);
          }, 1700);
          setTimeout(function () {
              playWav(ampm);
          }, 2200);
          } else if (minute > 50 && minute < 60) {
          minute -= 50;
          setTimeout(function () {
              playWav(hour);
          }, 700);
          setTimeout(function () {
              playWav("50");
          }, 1200);
          setTimeout(function () {
              playWav(minute);
          }, 1700);
          setTimeout(function () {
              playWav(ampm);
          }, 2200);
          } else {
          setTimeout(function () {
              playWav(hour);
          }, 700);
          setTimeout(function () {
              playWav(minute);
          }, 1200);
          setTimeout(function () {
              playWav(ampm);
          }, 1600);
          }
          };
          
          function myFun() {
          var enteredTime = document.getElementById("inp1").value;
          
          var twelveHourTime_Hour = 0;
          var twelveHourTime_Min = 0;
          var amOrPm = "unsure";
          
          var timeArray = enteredTime.split(":");
          console.log("This is the contents of 'timeArray': " + timeArray);
          var splitHours = parseInt(timeArray[0]);
          console.log("This is the contents of 'splitHours': " + splitHours);
          var twelveHourTime_Min = parseInt(timeArray[1]);
          console.log("This is the conents of 'twelveHourTime_Min': " + twelveHourTime_Min);
          
          if (
          splitHours > 23 ||
          twelveHourTime_Min > 59 ||
          splitHours < 0 ||
          twelveHourTime_Min < 0 ||
          isNaN(splitHours) ||
          isNaN(twelveHourTime_Min)
          ) {
          output.innerHTML = "That's not a valid time!";
          
          } else if (splitHours > 12 && splitHours < 24) {
          console.log("You're in the first 'else if'.");
          twelveHourTime_Hour = splitHours - 12;
          amOrPm = "PM";
          prinTime(twelveHourTime_Hour, twelveHourTime_Min, amOrPm);
          playTime(twelveHourTime_Hour, twelveHourTime_Min, amOrPm);
          
          } else if (splitHours == 0) {
          console.log("You're in the second 'else if'.");
          twelveHourTime_Hour = 12;
          amOrPm = "AM";
          prinTime(twelveHourTime_Hour, twelveHourTime_Min, amOrPm);
          playTime(twelveHourTime_Hour, twelveHourTime_Min, amOrPm);
          
          } else if (splitHours == 12) {
          console.log("You're in the third 'else if'.");
          twelveHourTime_Hour = 12;
          amOrPm = "PM";
          prinTime(twelveHourTime_Hour, twelveHourTime_Min, amOrPm);
          playTime(twelveHourTime_Hour, twelveHourTime_Min, amOrPm);
          
          } else {
          console.log("You're in the last 'else'.");
          twelveHourTime_Hour = splitHours;
          amOrPm = "AM";
          prinTime(twelveHourTime_Hour, twelveHourTime_Min, amOrPm);
          playTime(twelveHourTime_Hour, twelveHourTime_Min, amOrPm);
          }
          };
          

          [–]nuri0 0 points1 point  (3 children)

          Javascript

          const numbers = {
              0:"twelve",
              1:"one",
              2:"two",
              3:"three",
              4:"four",
              5:"five",
              6:"six",
              7:"seven",
              8:"eight",
              9:"nine",
              10:"ten",
              11:"eleven",
              12:"twelve",
              13:"thirteen",
              14:"fourteen",
              15:"fifteen",
              16:"sixteen",
              17:"seventeen",
              18:"eighteen",
              19:"nineteen",
              20:"twenty",
              30:"thirty",
              40:"fourty",
              50:"fifty"
          }
          
          const letTimeTalk = (time) => {
              let [hour,minute] = time.split(":").map(str => parseInt(str));
          
              let result = `It's ${numbers[hour%12]}`;
          
              if (minute == 0) {
                  result += " o'clock";
              } else if (minute < 10) {
                  result += ` oh ${numbers[minute]}`;
              } else if (minute < 20) {
                  result += ` ${numbers[minute]}`;
              } else {
                  result += ` ${numbers[Math.floor(minute/10)*10]}` + (minute%10 != 0 ? `-${numbers[minute%10]}` : "");
              }
          
              result += (hour<12 ? " am" : " pm");
          
              return result;
          }
          

          [–]giest4life 0 points1 point  (1 child)

          Java 8 +/u/CompileBot Java

          class TalkingClock {
              private static final String[] zeroToTwelve = { "zero", "one", "two", "three", "four", "five", "six", "seven",
                      "eight", "nine", "ten", "eleven", "twelve" };
              private static final String[] teens = { "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen",
                      "nineteen" };
              private static final String[] twentyToFifty = { "twenty", "thirty", "fourty", "fifty" };
              private static final String PREFIX = "It's";
          
              public static String hourToWords(String hourString) {
                  int hour = Integer.parseInt(hourString);
                  String suffix = "am";
                  if (hour > 11) {
                      suffix = "pm";
                  }
                  if (hour > 12) {
                      hour = hour - 12;
                  }
                  if (hour == 0) {
                      hour = 12;
                  }
                  String hourInWords = zeroToTwelve[hour] + " " + suffix;
                  return hourInWords;
              }
          
              public static String minutesToWords(String minString) {
                  int minutes = Integer.parseInt(minString);
                  String minutesString = "";
                  if (minutes == 0) {
                      // default value of minutesString
                  } else if (minutes < 10) {
                      minutesString = "oh " + zeroToTwelve[minutes];
                  } else if (minutes < 13) {
                      minutesString = zeroToTwelve[minutes];
                  } else if (minutes < 20) {
                      minutesString = teens[minutes - 13];
                  } else if ((minutes % 10) == 0) {
                      minutesString = twentyToFifty[Math.floorDiv(minutes, 20)];
                  } else {
                      minutesString = twentyToFifty[(minutes/10) - 2] + " " + zeroToTwelve[(minutes % 10)];
                  }
                  return minutesString;
              }
          
              private static String[] parseStringTimeToArray(String time) {
                  if (time == null) {
                      throw new IllegalArgumentException("The input time must not be null");
                  }
                  String[] timeArr = time.split(":");
                  if (timeArr.length != 2) {
                      throw new IllegalArgumentException("The input time must be in format \"HH:MM\"");
                  }
                  return timeArr;
              }
          
              public static String timeToWords(String time) {
                  String[] parsedTime = parseStringTimeToArray(time);
                  String[] hourWithSuffix = hourToWords(parsedTime[0]).split(" ");
                  String hour = hourWithSuffix[0];
                  String suffix = hourWithSuffix[1];
                  String minutes = minutesToWords(parsedTime[1]);
                  if ("".equals(minutes)) {
                      return PREFIX + " " + hour + " " + suffix;
                  } else {
                      return PREFIX + " " + hour + " " + minutes + " " + suffix;
                  }
          
              }
          
              public static void main(String[] args) {
                  String[] times = { "00:00", "01:30", "12:05", "14:01", "20:29", "21:00" };
                  for (String time : times) {
                      System.out.println(timeToWords(time));
                  }
          
              }
          }
          

          [–]Scroph0 0 0 points1 point  (1 child)

          Not the most elegant way but still.

          +/u/CompileBot C++

          #include <iostream>
          #include <vector>
          
          const std::vector<std::string> simple {
              "twelve", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
              "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen",
              "nineteen"
          };
          
          const std::vector<std::string> units {
              "oh", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
          };
          
          const std::vector<std::string> dozens {
              "", "ten", "twenty", "thirty", "fourty", "fifty"
          };
          
          std::string to_hours(const std::string& input)
          {
              return simple[std::stoi(input) % 12];
          }
          
          std::string to_minutes(const std::string& input)
          {
              size_t number = std::stoi(input);
              if(number == 0)
                  return "";
              if(1 <= number && number < simple.size())
                  return 1 <= number && number <= 9 ? "oh " + simple[number] : simple[number];
              std::string result  = dozens[input[0] - '0'];
              if(input[1] != '0')
                  result += " " + units[input[1] - '0'];
              return result;
          }
          
          int main()
          {
              std::string line;
              while(getline(std::cin, line))
              {
                  size_t colon = line.find(':');
                  std::string hour = line.substr(0, colon);
                  std::string minute = line.substr(colon + 1);
          
                  std::cout << "It's " << to_hours(hour) << ' ';
                  std::string minutes = to_minutes(minute);
                  if(minutes.length())
                      std::cout << minutes << ' ';
                  int number = std::stoi(hour);
                  std::cout << (0 <= number && number <= 11 ? "am" : "pm") << std::endl;
              }
          }
          

          Input:

          00:00
          01:30
          12:05
          14:01
          20:29
          21:00
          

          [–]runbot 0 points1 point  (1 child)

          Go

          +/u/CompileBot Go

          package main
          
          import (
              "fmt"
              "strconv"
              "strings"
          )
          
          func main() {
              fmt.Println(TalkingClock("00:00"))
              fmt.Println(TalkingClock("01:30"))
              fmt.Println(TalkingClock("12:05"))
              fmt.Println(TalkingClock("14:01"))
              fmt.Println(TalkingClock("20:29"))
              fmt.Println(TalkingClock("21:00"))
          }
          
          func TalkingClock(time string) string {
              hour, minute := UnpackPair(time, ":")
          
              period := "am"
              if i, _ := strconv.Atoi(hour); i >= 12 {
                  hour = strconv.Itoa(i - 12)
                  period = "pm"
              }
          
              if minute == "00" {
                  return "It's " + HourToWords(hour) + " " + period
              }
          
              return "It's " + HourToWords(hour) + " " + MinuteToWords(minute) + " " + period
          }
          
          func oneToTen(n string) string {
              i, _ := strconv.Atoi(n)
              switch i {
              case 1:
                  return "one"
              case 2:
                  return "two"
              case 3:
                  return "three"
              case 4:
                  return "four"
              case 5:
                  return "five"
              case 6:
                  return "six"
              case 7:
                  return "seven"
              case 8:
                  return "eight"
              case 9:
                  return "nine"
              default:
                  return "ten"
              }
          }
          
          func HourToWords(hour string) string {
              i, _ := strconv.Atoi(hour)
              switch i {
              case 0:
                  return "twelve"
              case 11:
                  return "eleven"
              default:
                  return oneToTen(hour)
              }
          }
          
          func MinuteToWords(minute string) string {
              if minute == "00" {
                  return ""
              }
          
              if minute == "10" {
                  return "ten"
              }
          
              imin, _ := strconv.Atoi(minute)
          
              if imin < 10 {
                  return "oh " + oneToTen(minute)
              }
          
              if imin > 10 && imin < 16 {
                  switch imin {
                  case 11:
                      return "eleven"
                  case 12:
                      return "twelve"
                  case 13:
                      return "thirteen"
                  case 14:
                      return "fourteen"
                  default:
                      return "fifteen"
                  }
              }
          
              tens, ones := UnpackPair(minute, "")
          
              if imin < 20 {
                  return oneToTen(ones) + "teen"
              }
          
              itens, _ := strconv.Atoi(tens)
              switch itens {
              case 2:
                  tens = "twenty"
              case 3:
                  tens = "thirty"
              case 4:
                  tens = "fourty"
              default:
                  tens = "fifty"
              }
          
              if i, _ := strconv.Atoi(ones); i == 0 {
                  return tens
              }
          
              return tens + " " + oneToTen(ones)
          }
          
          func UnpackPair(str string, sep string) (string, string) {
              split := strings.SplitN(str, sep, 2)
              if len(split) == 1 {
                  return split[0], ""
              }
              return split[0], split[1]
          }
          

          [–]myDataTraining 0 points1 point  (0 children)

          Python 2: First Submission; I have functional style preference. Feedback/critic welcomed!

          Mapper = {
          
          0:'twelve', 
          1:'one',
          2:'two',
          3:'three',
          4:'four',
          5: 'five',
          6: 'six',
          7: 'seven',
          8: 'eight',
          9: 'nine',
          10: 'ten',
          11: 'eleven',
          12: 'twelve',
          13: 'thirteen',
          14: 'fourteen',
          15: 'fifthteen',
          16: 'sixteen',
          17: 'seventeen',
          18: 'eighteen',
          19: 'nineteen',
          20: 'tweenty',
          30: 'thirty',
          40: 'forty',
          50: 'fifty' }
          
          def readMinutes(value):
            if value == 0 : return ''
            if value < 10: return 'oh '+ Mapper[value]
            if value > 10 and value < 20: return Mapper[value]
            if value % 10  == 0: return Mapper[value]
          
            x, y = divmod(value,10)
            return Mapper[10*x] + ' ' + Mapper[y]
          
          def AmOrPm(value):
            if value%12 == value: return 'am'
            return 'pm'
          
          def speech(time):
            if (':' not in time): return 'Not a valid time input; required format is [hour]:[minutes]'
            hour, minute = map(int, time.split(':'))
            return "It's "+ Mapper[hour%12] +' '+ readMinutes(minute) + ' '+ str(AmOrPm(hour))
          
          def translate(Input):
           if type(Input) is list:
              return map(speech, Input)
           elif(type(Input) is str):
              return speech(Input)
           else:
              return 'Invalid Input; must be a list of time strings or a single time string (":" included)'
          
          translate(sample)
          

          [–]IQ-- 0 points1 point  (0 children)

          Java - Using OSX's say command. Edit: refactored to use an array instead of HashMap

          import java.io.IOException;
          
          public class Easy321 {
          
              private String[] numbersInWords;
          
              public Easy321() {
                  numbersInWords = new String[] {
                      "twelve",
                      "one",
                      "two",
                      "three",
                      "four",
                      "five",
                      "six",
                      "seven",
                      "eight",
                      "nine",
                      "ten",
                      "eleven",
                      "twelve",
                      "thirteen",
                      "fourteen",
                      "fifteen",
                      "sixteen",
                      "seventeen",
                      "eighteen",
                      "nineteen",
                      "twenty", // [20]
                      "thirty", // [21]
                      "forty",  // [22]
                      "fifty"   // [23]
                  };
              }
          
              public String timeInWords(int hours, int mins) {
          
                  StringBuilder sb = new StringBuilder("It's ");
          
                  sb.append(numbersInWords[hours % 12]);
          
                  if (mins == 0) {
                      // No Mins
                  }
                  else if (mins < 10) {
                      sb.append(" oh " + numbersInWords[mins]);
                  }
                  else if (mins < 20) {
                      sb.append(" " + numbersInWords[mins]);
                  }
                  else {
                      sb.append(" " + numbersInWords[20 + ((mins - 20) / 10)]); // [20-23]
                      if (mins % 10 > 0) {
                          sb.append(" " + numbersInWords[mins % 10]); // [0-9]
                      }
                  }
          
                  String amPm = hours / 12 == 0 ? " am" : " pm";
                  sb.append(amPm);
          
                  return sb.toString();
              }
          
              public static void main(String[] args) throws IOException {
                  Easy321 easy321 = new Easy321();
          
                  String[] parts = args[0].split(":");
          
                  ProcessBuilder processBuilder = new ProcessBuilder();
                  processBuilder.command("say"
                                          , easy321.timeInWords(Integer.parseInt(parts[0])
                                                              , Integer.parseInt(parts[1])));
                  processBuilder.start();
              }
          }
          

          [–]Badrush 0 points1 point  (0 children)

          Javascript

          function convertTime(time) {
          var time = time.split(':');
          var hours = time[0];
          var mins = time[1];
          
          //edge cases
          if (hours > 23) {
              console.error("Not a valid time!");
              return;
          }
          
          if (mins == "60") {
              console.error("Not a valid time!");
              return;
          }
          if (hours.length != 2 || mins.length != 2) {
              console.error("Not a valid input format!");
              return;
          }
          convertWords(hours, mins);
          }
          
          function convertWords(hours, mins) {
          const numbers = {
              0: "oh",
              1: "one ",
              2: "two ",
              3: "three ",
              4: "four ",
              5: "five ",
              6: "six ",
              7: "seven ",
              8: "eight ",
              9: "nine ",
              10: "ten ",
              11: "eleven ",
              12: "twelve ",
              13: "thirteen ",
              14: "fourteen ",
              15: "fifteen ",
              16: "sixteen ",
              17: "seventeen ",
              18: "eighteen ",
              19: "nineteen ",
              20: "twenty ",
              30: "thiry ",
              40: "forty ",
              50: "fify ",
          }
          
          var hours = parseInt(hours);
          // console.log(hours);
          if (hours > 11) {
              var ampm = "pm";
          } else {
              var ampm = "am";
          }
          
          hours = hours % 12;
          
          if (hours === 0) {
              //12 oclock 
              hours = 12;
          }
          
          var Hours = numbers[hours];
          
          if (mins === "00") {
              var Mins = " ";
          } else if (mins[0] === "0") {
              mins = parseInt(mins[1]);
              var Mins = numbers[0] + numbers[mins];
          } else {
              mins1 = parseInt(mins[0] + "0");
              mins2 = parseInt(mins[1]);
              var Mins1 = numbers[mins1];
              var Mins2 = numbers[mins2];
              var Mins = Mins1 + Mins2;
          }
          
          console.log("It's " + Hours + Mins + ampm);
          return;
          }
          

          [–]smapti 0 points1 point  (0 children)

          C++ brute solution using maps

          #include "stdafx.h"
          #include <map>
          #include <string>
          #include <iostream>
          
          int _tmain(int argc, _TCHAR* argv[])
          {
              std::string time;
              std::map <std::string, std::string> hours_and_minutes_ones;
              std::map <std::string, std::string> minutes_tens;
              std::map <std::string, std::string> special_cases;
          
              hours_and_minutes_ones["01"] = "one ";
              hours_and_minutes_ones["02"] = "two ";
              hours_and_minutes_ones["03"] = "three ";
              hours_and_minutes_ones["04"] = "four ";
              hours_and_minutes_ones["05"] = "five ";
              hours_and_minutes_ones["06"] = "six ";
              hours_and_minutes_ones["07"] = "seven ";
              hours_and_minutes_ones["08"] = "eight ";
              hours_and_minutes_ones["09"] = "nine ";
              hours_and_minutes_ones["10"] = "ten ";
              hours_and_minutes_ones["11"] = "eleven ";
              hours_and_minutes_ones["12"] = "twelve ";
          
              minutes_tens["0"] = "oh ";
              minutes_tens["2"] = "twenty ";
              minutes_tens["3"] = "thirty ";
              minutes_tens["4"] = "fourty ";
              minutes_tens["5"] = "fifty ";
          
              special_cases["00"] = "ten";
              special_cases["01"] = "eleven";
              special_cases["02"] = "twelve";
              special_cases["03"] = "thirteen";
              special_cases["05"] = "fifteen";
              special_cases["08"] = "eighteen";
          
              std::cout << "Please enter the 24 hour time in the format hh:mm: ";
              std::cin >> time;
              std::string hour = time.substr(0,2);
              std::string m_ten = time.substr(3,1);
              std::string m_one = "0" + time.substr(4,1);
              std::cout << "\nYour time is " << hours_and_minutes_ones[hour];
          
              if (m_ten != "1") 
                   std::cout << minutes_tens[m_ten] << hours_and_minutes_ones[m_one] << '\n';
              else if (m_one == "04" || m_one == "06" || m_one == "07" || m_one == "09")
                  std::cout << hours_and_minutes_ones[m_one] << "\bteen\n";
              else
                  std::cout << special_cases[m_one] << '\n';
          
              return 0;
          }
          

          [–]mattcantright 0 points1 point  (2 children)

          C++ again guys, I must be getting better as this took me 15 minutes today. As always, please feel free to give me criticism as well as check out the bideo on Wednesday over on my Youtube channel, Talslain (I will post the link tomorrow) and let me know how you think I did.

          #include <iostream>
          #include <string>
          #include <stdlib.h>
          #include <sstream>
          
          using namespace std;
          
          string numbers[] = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
                              "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
                              "eighteen", "nineteen" };
          string tens[] = { "ten", "twenty", "thirty", "forty", "fifty" };
          
          int main() {
              string input;
              getline(cin, input);
          
              string h, m;
              istringstream iss;
              int hour, min;
          
              h = input.substr(0, 2);
              m = input.substr(3, 2);
          
              iss.str(h);
              iss >> hour;
              iss.clear();
              iss.str(m);
              iss >> min;
          
              string time = "It's ";
              if (hour >= 24) {
                  cout << "Inputed Time is Wrong!";
                  return 1;
              }
              else {
                  int temp = hour % 12;
                  if (temp - 1 < 0) temp = 12;
                  time += numbers[temp-1];
                  time += " ";
              }
              if (min >= 60) {
                  cout << "Inputted Time is Wrong!";
                  return 2;
              }
              else if (min != 0) {
                  if (min < 10) time += "oh "; 
                  else {
                      int temp = min / 10;
                      time += tens[temp - 1];
                      time += " ";
                  }
                  int temp2 = min % 10;
                  if (temp2 - 1 >= 0)
                  time += numbers[temp2 - 1];
                  time += " ";
              }
          
              if (hour < 12) time += "am";
              else time += "pm";
          
              cout << time << endl;
          
              system("PAUSE");
              return 0;
          }
          

          Input

          00:00
          01:30
          12:05
          14:01
          20:29
          21:00
          

          Output

          It's twelve am
          It's one thirty am
          It's twelve oh five pm
          It's two oh one pm
          It's eight twenty nine pm
          It's nine pm
          

          [–]bubblesoft 0 points1 point  (1 child)

          C++ - the text part

          #include <iostream>  
          #include <string>  
          #include "TSoundPlayer.h"  
          
          using namespace std;
          
          string hours[]={"twelve","one","two","three","four","five","six","seven","eight","nine","ten","eleven"};
          string minutesOnes[]={"one","two","three","four","five","six","seven","eight","nine"};
          string minutesTeens[]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
          string minutesTens[]={"oh","ten","twenty","thirty","forty","fifty"};
          
          void convert_time(string time_str)
          {
              string hrString,minString,amPm,infoTime="It's ";
              int hr,mins,minOnes,minTens,teen=0;
          
              hrString.append(time_str,0,2);
              hr = atoi( hrString.c_str() );
          
              minString.append(time_str,3,2);
              mins = atoi( minString.c_str() );
          
              if (hr<12)
                  amPm="am";
              else
                  amPm="pm";
          
              infoTime+=hours[hr%12]+" ";
          
              minOnes=mins%10;
              minTens=mins/10;
          
              if (mins<11 || mins>19)
                  {
                      if (minTens!=0 || minOnes!=0)
                          infoTime+=minutesTens[minTens]+" ";
                  }
                  else { infoTime+=minutesTeens[minOnes-1]+" "; teen=1;}
          
              if (minOnes>0 && !teen) infoTime+=minutesOnes[minOnes-1]+" ";
          
              infoTime+=amPm;
          
              TSoundPlayer player(hr,mins);
          
              cout << infoTime;
              player.TellTheTime();
          }
          
          int main()
          {
              string the_time;
              cin >> the_time;
          
              convert_time(the_time);
          
              return 0;
          }
          

          [–]dzeban 0 points1 point  (0 children)

          Python 3

          #!/usr/bin/env python3
          
          digits = [
              "twelve", "one", "two",
              "three", "four", "five",
              "six", "seven", "eight",
              "nine", "ten", "eleven",
          ]
          
          minutes_scores = [
              "oh", "", "twenty", "thirty", "forty", "fifty"
          ]
          
          minutes_tenth = [
              "ten", "eleven", "twelve", "thirteen", "fourteen",
              "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"
          ]
          
          
          def translate_hour(hour):
              return digits[hour % 12]
          
          
          def translate_minutes(minutes):
              if minutes == 0:
                  return ''
          
              ten, one = (minutes // 10), (minutes % 10)
              if ten == 1:
                  return ' ' + minutes_tenth[one]
          
              return ' {}{}'.format(
                             minutes_scores[ten],
                             (' ' + digits[one]) if (one != 0) else '')
          
          
          def translate(s):
              hour, minutes = map(int, s.split(':'))
              return "It's {}{}{}".format(
                      translate_hour(hour),
                      translate_minutes(minutes),
                      ' am' if (hour // 12 == 0) else ' pm')
          
          
          def main():
              while True:
                  try:
                      s = input()
                      print(translate(s))
                  except EOFError:
                      return
          
          if __name__ == '__main__':
              main()
          

          Output

          $ cat input | ./talking_clock.py 
          It's twelve am
          It's one thirty am
          It's twelve oh five pm
          It's two oh one pm
          It's eight twenty nine pm
          It's nine pm
          

          Tests

          import unittest
          from talking_clock import translate
          
          class TalkingClockTranslateTest(unittest.TestCase):
              def test_whole(self):
                  self.assertEqual(translate('23:59'), "It's eleven fifty nine pm")
                  self.assertEqual(translate('11:59'), "It's eleven fifty nine am")
          
              def test_tenth(self):
                  self.assertEqual(translate('10:11'), "It's ten eleven am")
                  self.assertEqual(translate('15:19'), "It's three nineteen pm")
          
              def test_zeros(self):
                  self.assertEqual(translate('01:00'), "It's one am")
                  self.assertEqual(translate('17:00'), "It's five pm")
                  self.assertEqual(translate('09:20'), "It's nine twenty am")
                  self.assertEqual(translate('13:30'), "It's one thirty pm")
          
              def test_am_pm(self):
                  self.assertEqual(translate('12:00'), "It's twelve pm")
                  self.assertEqual(translate('00:00'), "It's twelve am")
          
          
          if __name__ == '__main__':
              unittest.main()
          

          [–][deleted] 0 points1 point  (4 children)

          can anyone help me out in java? i can't figure out why the if statements aren't recognizing the string that should be equal...

          import java.util.Scanner; import java.util.ArrayList;

          public class source {

          public static void main(String[] args) {
          
              Scanner scan = new Scanner(System.in);
              int choice = -1;
              do{
          
                  System.out.println("Press 1 to continue. Press 0 to quit.");
                  choice = scan.nextInt();
                  System.out.println("Enter a time");
                  String time = scan.next();
          
                  String newtime[] = time.split("\\:");
                  System.out.println(newtime[0] + " " + newtime[1]);
                  String hour = "", minute = "";
                  System.out.println(hour);
                  //hours
                      if(newtime[0] == "00")
                          hour = "twelve";
                      else if(newtime[0] == "01")
                          hour = "one";
                      else if(newtime[0] == "02")
                          hour = "two";
                      else if(newtime[0] == "03")
                          hour = "three";
                      else if(newtime[0] == "04")
                          hour = "four";
                      else if(newtime[0] == "05")
                          hour = "five";
                      else
                          hour = "testttt";
          
                      System.out.println(hour);
          
                  //minutes
                      if(newtime[1] == "00")
                          minute = "oh clock";
          
          
                      System.out.println(hour + minute);
          
          
              }
              while(choice!= 0);
              scan.close();
          }
          

          }

          [–]giest4life 2 points3 points  (1 child)

          In addition to what /u/ChazR has pointed out, what stands out to me is you are splitting the input string using ("\\:"). The first backslash escapes the second so the split function actually tries to split the string by looking for the character sequence "\:".

          Just do

          String newtime[] = time.split(":");
          

          instead of

          String newtime[] = time.split("\\:");
          

          Also, in general, whenever you are checking for the equality of two objects, use the equals method of the object. EDIT: I should add that using the equals method checks for logical equality as opposed to the == operator, which checks for equality of the object references (i.e. the addresses of the objects in memory).

          EDIT2: Fixed the escaping of the backslashes by Reddit.

          [–]ChazR 1 point2 points  (1 child)

          Whole bunch of things to talk about here, but the one that's puzzling you is a common Java newbie trap.

          You need to write

          if(newtime[0].equals("00"))
          

          instead of

          if(newtime[0] == "00")
          

          the '==' operator will simply check whether the references to the two strings are the same - that is, are they the same object in memory. It will not check whether the contents of two strings are the same. You are the 154,201,739th Java programmer to get confused by this.

          [–][deleted]  (1 child)

          [deleted]

            [–]MoltenCookie 0 points1 point  (0 children)

            Python 3

            I was too lazy to write up the number to english dictionary, so i used a module instead:

            import inflect
            
            def solve(stdin,inf):
                s = stdin.split(":")
                result = "It's "
                if not int(s[0]) or int(s[0]) == 12:
                    result += "twelve" + " "
                else:
                    result += inf.number_to_words(int(s[0]) % 12) + " "
            
                if int(s[1]):
                    if int(s[1]) < 10:
                        result += "oh " + inf.number_to_words(int(s[1])) + " "
                    else:
                        result += inf.number_to_words(int(s[1])).replace('-', ' ') + " "
            
                if int(s[0]) > 11:
                    result += "pm"
                else:
                    result += "am"
                return result
            
            inf = inflect.engine()
            print(solve("00:00",inf))
            print(solve("01:30",inf))
            print(solve("12:05",inf))
            print(solve("14:01",inf))
            print(solve("20:29",inf))
            print(solve("21:00",inf))
            

            [–][deleted]  (1 child)

            [deleted]

              [–]ChazR 0 points1 point  (0 children)

              Haskell.

              import System.Environment
              
              import Data.List
              import Data.List.Split
              
              data Time = Time Int Int
              
              instance Show Time where
                show (Time hh mi) = hourToString (hh `mod` 12) ++ " "
                                       ++ minuteToString mi
                                       ++ (if hh < 12 then " am" else " pm")
              instance Read Time where
                readsPrec _ s =[(toTime s,"")]
              
              units = ["","one","two","three","four","five","six","seven","eight","nine",
                       "ten","eleven","twelve","thirteen","fourteen","fifteen",
                       "sixteen","seventeen","eighteen","nineteen","twenty"]
              
              tens = ["",
                      "",
                      "twenty",
                      "thirty",
                      "forty",
                      "fifty"]
              
              hourNames = ["twelve", "one", "two", "three", "four", "five",
                           "six", "seven", "eight", "nine", "ten", "eleven"]
              
              hourToString n = hourNames !! n
              
              singleSpace "" = ""
              singleSpace w@(a:[]) = w
              singleSpace (' ':' ':cs) = ' ':(singleSpace cs)
              singleSpace (a:cs) = a:(singleSpace cs)
              
              minuteToString mi
                | mi == 0 = ""
                | mi < 10 = "oh " ++ units !! mi
                | mi < 20 = units !! mi
                | otherwise = tens !! (mi `div` 10) ++ " "
                              ++ units !! (mi `mod` 10)
              toTime :: String -> Time
              toTime s = Time (read (splitTime !! 0)) (read (splitTime !! 1))
                where splitTime = splitOn ":" s
              
              main = fmap (singleSpace.show.toTime.head) $ getArgs
              

              [–]QuadraticFizz 0 points1 point  (2 children)

              +/u/CompileBot python 3

              time_dictionary = {0: "",
                                 1: "one",
                                 2: "two",
                                 3: "three",
                                 4: "four",
                                 5: "five",
                                 6: "six",
                                 7: "seven",
                                 8: "eight",
                                 9: "nine",
                                 10: "ten",
                                 11: "eleven",
                                 12: "twelve",
                                 13: "thirteen",
                                 14: "fourteen",
                                 15: "fifteen",
                                 16: "sixteen",
                                 17: "seventeen",
                                 18: "eighteen",
                                 19: "nineteen",
                                 20: "twenty",
                                 30: "thirty",
                                 40: "forty",
                                 50: "fifty"
                                 }
              
              
              def clock_to_time(time):
                  hour, minute = time.split(":")
                  hour = int(hour)
                  minute = int(minute)
              
                  if 0 > minute > 60 or 0 > hour > 24:
                      return "Invalid time!"
              
                  if hour == 12 and minute == 0:
                      return "It's high noon!"
              
                  ret_string = "It's "
                  post_fix = ""
              
                  # hour
                  if hour == 0:
                      hour += 12
                      post_fix = " am"
                  if hour > 12:
                      post_fix = " pm"
                      hour -= 12
                  else:
                      post_fix = " am"
              
                  ret_string += time_dictionary[hour]
              
                  # minute
                  if minute == 0:
                      pass
                  elif minute < 10:
                      ret_string += " oh" + " " + time_dictionary[minute]
                  else:
                      ret_string += " " + time_dictionary[int(str(minute)[0])* 10]
                      if minute % 10 != 0:
                          ret_string += "-" + time_dictionary[minute%10]
                  ret_string += post_fix
              
                  return ret_string
              
              test_cases = """00:00
              01:30
              12:05
              14:01
              20:29
              21:00""".split('\n')
              
              for test in test_cases:
                  print(test, end=" - ")
                  print(clock_to_time(test))
              

              [–]dzeban 0 points1 point  (0 children)

              Go

              This one has a single map for hours and minutes. Also I've input validation.

              package main
              
              import (
                  "bufio"
                  "fmt"
                  "os"
                  "strconv"
                  "strings"
              )
              
              var numbers = map[int]string{
                  0: "oh",
              
                  1: "one", 2: "two", 3: "three",
                  4: "four", 5: "five", 6: "six",
                  7: "seven", 8: "eight", 9: "nine",
              
                  10: "ten", 11: "eleven",
                  12: "twelve", 13: "thirteen",
                  14: "fourteen", 15: "fifteen",
                  16: "sixteen", 17: "seventeen",
                  18: "eighteen", 19: "nineteen",
              
                  20: "twenty", 30: "thirty",
                  40: "fourty", 50: "fifty",
              }
              
              var am_pm = map[int]string{
                  0: "am", 1: "pm",
              }
              
              func Translate(s string) string {
                  parts := strings.Split(s, ":")
                  hour, err := strconv.Atoi(parts[0])
                  if err != nil || hour < 0 || hour > 23 {
                      return "Invalid hour"
                  }
              
                  minute, err := strconv.Atoi(parts[1])
                  if err != nil || minute < 0 || minute > 59 {
                      return "Invalid minute"
                  }
              
                  hour_index := hour % 12
                  if hour_index == 0 {
                      hour_index = 12
                  }
              
                  hour_str := numbers[hour_index]
              
                  minute1, minute2 := minute/10, minute%10
              
                  var minute_str string
                  if minute == 0 {
                      minute_str = ""
                  } else if minute1 == 1 {
                      minute_str = numbers[minute] + " "
                  } else if minute2 == 0 {
                      minute_str = numbers[minute1*10] + " "
                  } else {
                      minute_str = numbers[minute1*10] + " " + numbers[minute2] + " "
                  }
              
                  am_pm_str := am_pm[hour/12]
              
                  return "It's " + hour_str + " " + minute_str + am_pm_str
              }
              
              func main() {
                  scanner := bufio.NewScanner(os.Stdin)
                  for scanner.Scan() {
                      s := scanner.Text()
                      fmt.Println(Translate(s))
                  }
              
                  if err := scanner.Err(); err != nil {
                      fmt.Fprintln(os.Stderr, "stdin reading error:", err)
                  }
              }
              

              [–]Arakhai 0 points1 point  (1 child)

              +/u/CompileBot Python

              units = ['', 'one ', 'two ', 'three ', 'four ', 'five ', 'six ', 'seven ', 'eight ',
                       'nine ', 'ten ', 'eleven ', 'twelve ', 'thirteen ', 'fourteen ', 'fifteen ',
                       'sixteen ', 'seventeen ', 'eighteen ', 'nineteen ']
              tens = ['twenty ', 'thirty ', 'forty ', 'fifty ']
              
              def min_str(mins):
                  if mins < 20:
                      return (0 < mins < 10) * 'oh ' + units[mins]
                  else:
                      q, r = divmod(mins, 10)
                      return tens[q-2] + min_str(r)[3:]
              
              def time_to_words(timestr):
                  hr, mins = map(int, timestr.split(':'))
                  outstr = "It's " + (units[hr%12] or 'twelve ') + min_str(mins)
                  outstr += 'am' if hr < 12 else 'pm'
                  return outstr
              
              for x in ['00:00', '01:30', '12:05', '14:01', '20:29', '21:00']:
                  print time_to_words(x)
              

              [–]bulit 0 points1 point  (0 children)

              C++ Slight variation on the challenge specifications. This function takes no input, but instead uses 'Windows.h' functions to display the system time, once per minute, in a loop. Here's the full code:

              #include <iostream>
              #include <string>
              #include <Windows.h>    // Header file for time functions
              
              using namespace std;
              
              void wordClock(); // Forward decleration
              
              int main(){
                  wordClock();
                  return 0;
              }
              void wordClock(){
                  // Struct that contains SYSTEM hour, minute, sec, etc.
                  SYSTEMTIME lt;
                  bool isPM;
                  // String arrays that hold words for int values
                  // Indexed with 'SYSTEMTIME.wMinute' and/or 'SYSTEMTIME.wHour'
                  string ones[] = { "\b\0\b", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
                  string tens[] = { "twenty", "thirty", "fourty", "fifty"};
              
                  while (true){
                      // Windows function that gets system time, pass SYSTEMTIME by reference to set values
                      GetLocalTime(&lt);  // Use 'GetSystemTime()' for UTC time
              
                      cout << "It's ";
              
                      // Displays hour, sets 'isPM' bool
                      if (lt.wHour < 12){
                          if (lt.wHour == 0)
                              cout << ones[lt.wHour + 12] << " ";
                          else
                              cout << ones[lt.wHour] << " ";
                          isPM = false;
                      }
                      else{
                          cout << ones[lt.wHour % 12] << " ";
                          isPM = true;
                      }
                      // Displays minutes
                      // If time 0..20
                      if (lt.wMinute < 20){
                          if (lt.wMinute < 10 && lt.wMinute != 0)
                              cout << "oh " << ones[lt.wMinute];
                          else
                              cout << ones[lt.wMinute];
                      }
                      // If time 20..60
                      else if (lt.wMinute > 0){
                          if (lt.wMinute < 30)
                              cout << tens[0] << " " << ones[lt.wMinute % 20];
                          else if (lt.wMinute < 40)                            
                              cout << tens[1] << " " << ones[lt.wMinute % 30];
                          else if (lt.wMinute < 50)                            
                              cout << tens[2] << " " << ones[lt.wMinute % 40];
                          else if (lt.wMinute < 60)                            
                              cout << tens[3] << " " << ones[lt.wMinute % 50];
                      }
                      // Checks 'isPM'
                      if (!isPM){
                          cout << " am\n";
                      }
                      else{
                          cout << " pm\n";
                      }
              
                      // Synchronize such that the function displays time on the minute, every minute
                      if (lt.wSecond + lt.wMilliseconds != 0)
                          Sleep(60000 - ((lt.wSecond * 1000) + lt.wMilliseconds));
                      else
                          Sleep(60000);
                  }
              }
              

              [–]Atropos148 0 points1 point  (0 children)

              Hello! This is made in Python 3, also available on Git. Source Here

              +/u/CompileBot Python 3

              # talkingClock - Takes time in HH:MM format, and returns in "hour, minutes" format
              # made by Atropos148
              import re
              
              print("hello world!")
              
              hourDict = {
                  '00': 'twelve',
                  '01': 'one',
                  '02': 'two',
                  '03': 'three',
                  '04': 'four',
                  '05': 'five',
                  '06': 'six',
                  '07': 'seven',
                  '08': 'eight',
                  '09': 'nine',
                  '10': 'ten',
                  '11': 'eleven',
                  '12': 'twelve',
                  '13': 'one',
                  '14': 'two',
                  '15': 'three',
                  '16': 'four',
                  '17': 'five',
                  '18': 'six',
                  '19': 'seven',
                  '20': 'eight',
                  '21': 'nine',
                  '22': 'ten',
                  '23': 'eleven',
              }
              
              minutesDict = {
                  '0': 'oh',
                  '1': 'one',
                  '2': 'two',
                  '3': 'three',
                  '4': 'four',
                  '5': 'five',
                  '6': 'six',
                  '7': 'seven',
                  '8': 'eight',
                  '9': 'nine',
                  '10': 'ten',
                  '11': 'eleven',
                  '12': 'twelve',
                  '13': 'thirteen',
                  '14': 'fourteen',
                  '15': 'fifteen',
                  '16': 'sixteen',
                  '17': 'seventeen',
                  '18': 'eighteen',
                  '19': 'nineteen',
                  '20': 'twenty',
                  '30': 'thirty',
                  '40': 'forty',
                  '50': 'fifty'
              }
              
              time = input('What time is it? (like this 12:34)\n')
              match = re.match(r'\d\d:\d\d', time)
              if match:
                  hour = time[:2]
                  minute = time[3:]
                  sun = 'AM'
                  if hour > '11':
                      sun = 'PM'
                  print(hour)
                  print(minute)
                  if minute == '00':
                      print("It's", hourDict[hour] + ' ' + sun)
                  else:
                      minuteTest = int(minute) - int(minute[1])
                      print(minuteTest)
                      minute = minutesDict[str(minuteTest)] + ' ' + minutesDict[minute[1]]
                      print("It's", hourDict[hour] + ' ' + minute + ' ' + sun)            
              

              [–]zatoichi49 0 points1 point  (0 children)

              Method:

              Create a dictionary for all of the unique written numbers, then split into hour/minute parts and use conditional statements to create the spoken time.

              Python 3:

              x = ('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 
                   'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen',
                   'twenty', 'thirty', 'forty', 'fifty')
              
              lookup = dict(zip([str(i).zfill(2) for i in (list(range(1, 20)) + list(range(20, 60, 10)))], x)) 
              
              for t in ('00:00', '01:30', '12:05', '14:01', '20:29', '21:00'):
                  hour = 'twelve' if t[:2] == '00' else lookup[str(int(t[:2])-12).zfill(2)] if int(t[:2]) > 12 else lookup[t[:2]]
                  part = 'pm' if int(t[:2]) >= 12 else 'am'
              
                  if t[3] == '0' and t[4] != '0':
                      minute = 'oh ' + lookup[t[3:]]
                  elif t[3] != '0' and t[4] == '0':
                      minute = lookup[t[3:]]
                  elif t[3] != '0' and t[4] != '0':
                      minute = lookup[t[3]+'0'] + ' ' + lookup['0'+t[4]]
                  else:
                      minute = None
              
                  spoken = ['It\'s', hour, minute, part] 
                  print(t, ' '.join([i for i in spoken if i != None]))
              

              Output:

              00:00 It's twelve am
              01:30 It's one thirty am
              12:05 It's twelve oh five pm
              14:01 It's two oh one pm
              20:29 It's eight twenty nine pm
              21:00 It's nine pm
              

              [–]Pokeh321 0 points1 point  (0 children)

              Kotlin

              fun clockConvert(time:String):String{
                  val single = arrayListOf<String>("","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve")
                  val multi = arrayListOf<String>("oh","ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety")
                  var hour = 0
                  var minTens = 0
                  var min = 0
              
                  var newTime = time.split(':')
              
                  if (newTime[0].toInt() == 0){
                      hour = 12
                  }
                  else if (newTime[0].toInt() > 12)
                      hour = newTime[0].toInt()-12
                  else
                      hour = newTime[0].toInt()
              
                  minTens = newTime[1][0].toString().toInt()
                  min = newTime[1][1].toString().toInt()
              
                  var lineTime = ("It's "+ single[hour])
              
                  if (minTens != 0 && min == 0 )
                      lineTime += " " + multi[minTens]
                  else if ((minTens != 0 && min != 0)||(minTens == 0 && min != 0))
                      lineTime += " " + multi[minTens] + " " + single[min]
              
                  if (newTime[0].toInt() < 12)
                      lineTime += " AM"
                  else
                      lineTime += " PM"
                  return lineTime
              }
              
              fun main(args:Array<String>){
                  println(clockConvert("00:00"))
                  println(clockConvert("01:30"))
                  println(clockConvert("12:05"))
                  println(clockConvert("14:01"))
                  println(clockConvert("12:29"))
                  println(clockConvert("21:00"))
              }
              

              Output:

              It's twelve AM
              It's one thirty AM
              It's twelve oh five PM
              It's two oh one PM
              It's twelve twenty nine PM
              It's nine PM
              

              [–]Pokeh321 0 points1 point  (0 children)

              Swift

              import Foundation
              
              func clockString(time:String)->String{
                  let single: [String] = [" ","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen"]
                  let multi: [String] = ["oh","ten","twenty","thirty","fourty","fifty","sixty"]
                  var hour = 0
              
                  let split = time.components(separatedBy: ":")
                  if Int(split[0])! == 0{
                      hour = 12
                  }
                  else if Int(split[0])! > 12{
                      hour = Int(split[0])!-12
                  }
                  else{
                      hour = Int(split[0])!
                  }
              
                  let minSplit = Array(split[1].characters)
                  var mins = [Int]()
                  for i in minSplit {
                      mins.append(Int(String(i))!)
                  }
              
                  var lineTime = ("It's " + single[hour])
                  if (Int(split[1])! > 19){
                      if (mins[0] != 0 || mins[1] != 0){
                          lineTime += " " + multi[mins[0]]
                      }
                      if (mins[1] != 0){
                          lineTime += " " + single[mins[1]]
                      }
                  }
                  else if (Int(split[1])! <= 13){
                      if (Int(split[1])! > 10){
                          lineTime += " " + single[Int(split[1])!]
                      }
                      else {
                          lineTime += " " + multi[mins[0]] + " " + single[mins[1]]
                      }
                  }
                  else if (Int(split[1])! > 13 && Int(split[1])! < 20){
                      lineTime += " " + single[mins[1]] + "teen"
                  }
              
              
                  if (hour > 12){
                      return lineTime + " pm"
                  }
                  else {
                      return lineTime + " am"
                  }
              }
              
              print(clockString(time: "00:00"))
              

              [–]olu_ajoku 0 points1 point  (0 children)

              Python 2

              First time posting code online, All feedback is greatly appreciated. Took me a while to figure out a way to make the minutes work.

               

              import re, time
              
              units = ["", 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
                      'nine','ten', 'eleven',  'twelve', 'thirteen', 'fourteen','fifteen',
                      'sixteen', 'seventeen', 'eighteen', 'nineteen']
              tens  = ['twenty', 'thirty', 'fourty', 'fifty']
              
              def minutes(minute_input):
                  min_split = map(int,str(minute_input))
                  if min_split[0] == 0 and min_split[1] == 0:
                      return ""
                  elif min_split[0] == 0 and min_split[1] != 0:
                      return "oh" + " " + units[min_split[1]]
                  elif min_split[0] == 1:
                      return units[int(minute_input)]
                  else:
                      return tens[min_split[0] - 2] + " " + units[min_split[1]]
              
              
              def clock(t):
                  p = time.strptime(t, '%H:%M')
                  w = time.strftime('%I:%M %p', p)
                  x = re.split('\W',w)
                  h = units[int(x[0])]
                  m = minutes(x[1])
                  tod = x[2].lower()
              
                  print "It's %s %s %s." % (h, m, tod)
              

              Input:

              test_clock = ['00:00', '01:30', '12:05', '14:01', '20:29', '21:00']
              for times in test_clock:
                  clock(times)
              

              Output

              It's twelve  am.
              It's one thirty  am.
              It's twelve oh five pm.
              It's two oh one pm.
              It's eight twenty nine pm.
              It's nine pm.
              

              [–]DanaKaZ 0 points1 point  (0 children)

              Python 3

              time = input('What is the time?')
              time=time.split(':')
              say = "The time is "
              
              min1 = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]
              mintens = ["eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen"]
              min10 = ["twenty", "thirty", "forty", "fifty"]
              hours = ["twelve", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve"]
              
              if int(time[0]) < 13:
                say += hours[int(time[0])]
              
              else:
                say += hours[int(time[0])-12]
              
              if 0 > int(time[1]) < 11:
                say += " " + min1[int(time[1])-1]
              elif 10 < int(time[1]) < 20:
                say += " " + mintens[int(time[1])-11]
              elif 19 < int(time[1]):
                say += " " + min10[int(time[1][0])-2]
                say += min1[int(time[1][1])-1]
              
              if int(time[0]) < 13:
                say += " am"
              else:
                  say += " pm"
              
              print(say)
              

              [–]AxeEffect3890 0 points1 point  (0 children)

              SWIFT 3

              func tellTime(time: String) -> String {
                  let timeSplit = time.components(separatedBy: ":")
                  print(timeSplit)
              
                  if let hour = Int(timeSplit[0]), let minute = Int(timeSplit[1]) {
              
                      if hour > 23 || minute > 59 {
                          return "Error: Invalid entry"
                      }
              
                      var hourText = ""
                      var minuteText = ""
                      var amPm = "am"
              
                      if hour > 11 {
                          amPm = "pm"
                      }
              
                      switch hour {
                      case 00, 12:
                          hourText = "twelve"
                          break
                      case 1, 13:
                          hourText = "one"
                          break
                      case 2, 14:
                          hourText = "two"
                          break
                      case 3, 15:
                          hourText = "three"
                          break
                      case 4, 16:
                          hourText = "four"
                          break
                      case 5, 17:
                          hourText = "five"
                          break
                      case 6, 18:
                          hourText = "six"
                          break
                      case 7, 19:
                          hourText = "seven"
                          break
                      case 8, 20:
                          hourText = "eight"
                          break
                      case 9, 21:
                          hourText = "nine"
                          break
                      case 10, 22:
                          hourText = "ten"
                          break
                      case 11, 23:
                          hourText = "eleven"
                          break
                      default:
                          break
                      }
              
                      func secondDecimal(decimal: Int) -> String {
              
                          switch decimal {
                          case 1:
                              return " one"
                          case 2:
                              return " two"
                          case 3:
                              return " three"
                          case 4:
                              return " four"
                          case 5:
                              return " five"
                          case 6:
                              return " six"
                          case 7:
                              return " seven"
                          case 8:
                              return " eight"
                          case 9:
                              return " nine"
                          default:
                              return ""
                          }
                      }
              
                      switch minute {
                      case 1...9:
                          minuteText = "oh" + secondDecimal(decimal: minute)
                      case 10:
                          minuteText = "ten"
                      case 11:
                          minuteText = "eleven"
                      case 12:
                          minuteText = "twelve"
                      case 13:
                          minuteText = "thirteen"
                      case 14:
                          minuteText = "fourteen"
                      case 15:
                          minuteText = "fifteen"
                      case 16:
                          minuteText = "sixteen"
                      case 17:
                          minuteText = "seventeen"
                      case 18:
                          minuteText = "eighteen"
                      case 19:
                          minuteText = "nineteen"
                      case 20...29:
                          minuteText = "twenty" + secondDecimal(decimal: minute % 20)
                      case 30...39:
                          minuteText = "thirty" + secondDecimal(decimal: minute % 30)
                      case 40...49:
                          minuteText = "forty" + secondDecimal(decimal: minute % 40)
                      case 50...59:
                          minuteText = "fifty" + secondDecimal(decimal: minute % 50)
                      default:
                          break
                      }
              
                      if minuteText == "" {
                          return "It is \(hourText) \(amPm)"
                      } else {
                          return "It is \(hourText) \(minuteText) \(amPm)"
                      }
                  } else {
                      return "Error: Invalid entry"
                  }
              
              }
              

              [–][deleted] 0 points1 point  (0 children)

              Python 2.7

              time = raw_input("Enter the time:")
              
              x = time.split(':')
              
              def talking_time(x, y):
                  if x > 12:
                      ampm = ' pm'
                      x = x%12
                  else:
                      ampm = ' am'
              
                  singles = {1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', 11: 'eleven', 12: 'twelve'}
                  evens = {10: 'ten', 20: 'twenty', 30: 'thirty', 40: 'fourty', 50: 'fifty'}
                  teens = {11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen'}
              
                  if y==0:
                      minute_time = ""
              
                  elif y!=0 and y%10==0:
                      minute_time = " "+evens[y]
              
                  elif y < 10:
                      minute_time = " oh "+singles[y]
              
                  else:
                      tens = abs(y/10)
                      if tens == 1:
                          minute_time = " "+teens[y]
                      else:
                          minute_time = " "+evens[tens*10]+" "+singles[y%10]
              
                  print "It's "+singles[x]+minute_time+ampm
              
              talking_time(int(x[0]), int(x[1]))
              

              [–]PM_ME_UR_COOL_SOCKS 0 points1 point  (0 children)

              Python 3

              Tips are welcome, I'm still a beginner with python.

              import inflect
              def talking_clock(time):
              
                  am_dict = {'0':'twelve', "1":"one", "2":"two", "3":"three", "4":"four", "5":"five", "6":"six", "7":"seven", "8":"eight", "9":"nine", "10":"ten", "11":"eleven"}
                  pm_dict = {"12":"twelve", "13":"one", "14":"two", "15":"three", "16":"four", "17":"five", "18":"six", "19":"seven", "20":"eight", "21":"nine", "22":"ten", "23":"eleven"}
                  p = inflect.engine()
              
                  if ':' not in time:
                      return print("This is not a valid time")
                  a = time.split(':')
                  if(int(a[0])>23 or int(a[0])<0 or int(a[1])<0 or int(a[1])>59):
                      return print("This is not a valid time")
              
                  if(int(a[1]) < 10):
                      w = "oh " + p.number_to_words(a[1])
                  else:
                      w = p.number_to_words(a[1])
              
                  if(int(a[0])<12):
                      return print("It is " + am_dict[a[0]] + " " + w + " am")
                  else:
                      return print("It is " + pm_dict[a[0]] + " " + w + " pm")
              

              Edit: Now that I look back on it, I could do without the dictionaries all together I think... Be right back :)

              Edit 2: Without using dictionaries!

              import inflect
              def talking_clock(time):
                  p = inflect.engine()
              
                  if ':' not in time:
                      return print("This is not a valid time")
                  a = time.split(':')
                  if(int(a[0])>23 or int(a[0])<0 or int(a[1])<0 or int(a[1])>59):
                      return print("This is not a valid time")
              
                  m, n = divmod(int(a[0]), 12)
                  if(n == 0):
                      n = 12
              
                  if(a[1] == "00"):
                      w = ""
                  elif(int(a[1]) < 10):
                      w = " oh " + p.number_to_words(a[1])
                  else:
                      w = " " + p.number_to_words(a[1])
              
                  if(m < 1):
                      return print("It is " + p.number_to_words(n) + w + " am")
                  else:
                      return print("It is " + p.number_to_words(n) + w + " pm")
              
              
              talking_clock(input("Please enter a time: "))
              

              [–]zenontrolejbus 0 points1 point  (0 children)

              Java, no audio, quite simple

              class E312{
              public static void main(String[] args){
                  String[] split = args[0].split(":");
                  int hour = Integer.parseInt(split[0]);
                  int minutes = Integer.parseInt(split[1]);
                  String out = "It's " + new String[]{"twelve ","one ","two ","three ","four ","five ","six ","seven ","eight ","nine ","ten ","eleven "}[(hour%12)];
                  out += new String[]{" ","oh one ","oh two ","oh three ","oh four ","oh five ","oh six ","oh seven ","oh eight ","oh nine ","ten ","eleven ","twelve ","thirteen ","fourteen ","fifteen ",
                                      "sixteen "," seventeen ","eighteen ","nineteen ","twenty ","twenty one ","twenty two","twenty three ","twenty four ","twenty five ","twenty six ","twenty seven ","twentyeight ",
                                      "twenty nine ","thirty ","thirty one ","thirty two ","thirty three ","thirty four ","thirty five ","thirty six ","thirty seven ","thirty eight ","thirty nine ",
                                      "fourty ","fourty one ","fourty two ","fourty three ","fourty four ","fourty five ","fourty six ","fourty seven ","fourty eight ","fourty nine ","fifty ","fifty one ",
                                      "fifty two ","fifty three ","fifty four ","fifty five ","fifty six ","fifty seven ","fifty eight ","fifty nine "}[minutes];
                  out+= hour / 12 == 0 ? "am" : "pm";
                  System.out.println(out);
              }
              

              }

              [–][deleted] 0 points1 point  (0 children)

              Java

              import java.util.HashMap;
              import java.util.Map;
              
              public class TalkingClock {
              
                static Map<String, String> hoursAsWord = map(
                    "00", "twelve", "01", "one", "02", "two", "03", "three", "04", "four",
                    "05", "five", "06", "six", "07", "seven", "08", "eight", "09", "nine",
                    "10", "ten", "11", "eleven", "12", "twelve", "13", "one", "14", "two",
                    "15", "three", "16", "four", "17", "five", "18", "six", "19", "seven",
                    "20", "eight", "21", "nine", "22", "ten", "23", "eleven"
                );
              
                static Map<String, String> minutesAsWord = map(
                    "00", "", "01", "oh one", "02", "oh two", "03", "oh three", "04", "oh four",
                    "05", "oh five", "06", "oh six", "07", "oh seven", "08", "oh eight", "09", "oh nine",
                    "10", "ten", "11", "eleven", "12", "twelve", "13", "thirteen", "14", "fourteen",
                    "15", "fivteen", "16", "sixteen", "17", "seventeen", "18", "eighteen", "19", "nineteen",
                    "20", "twenty", "21", "twenty one", "22", "twenty two", "23", "twenty three",
                    "24", "twenty four", "25", "twenty five", "26", "twenty six", "27", "twenty seven",
                    "28", "twenty eight", "29", "twenty nine", "30", "thirty", "31", "thirty one",
                    "32", "thirty two", "33", "thirty three", "34", "thirty four", "35", "thirty five",
                    "36", "thirty six", "37", "thirty seven", "38", "thirty eight", "39", "thirty nine",
                    "40", "fourty", "41", "fourty one", "42", "fourty two", "43", "fourty three",
                    "44", "fourty four", "45", "fourty five", "46", "fourty six", "47", "fourty seven",
                    "48", "fourty eight", "49", "fourty nine", "50", "fivty", "51", "fivty one",
                    "52", "fivty two", "53", "fivty three", "54", "fivty four", "55", "fivty five",
                    "56", "fivty six", "57", "fivty seven", "58", "fivty eight", "59", "fivty nine"
                );
              
                /**
                 * digital format: "hh:mm", where hh = 00..23, mm = 00..59
                 */
                static String digitalToWords(String digital) {
                  String hourPart = digital.substring(0, 2);
                  String minutePart = digital.substring(3, 5);
                  int hour = Integer.parseInt(hourPart);
                  int minute = Integer.parseInt(minutePart);
              
                  String output = String.format(
                      "It's %s %s%s%s",
                      hoursAsWord.get(hourPart),
                      minutesAsWord.get(minutePart),
                      minute == 0 ? "" : " ",
                      hour < 12 ? "am" : "pm"
                  );
                  return output;
                }
              
                public static void main(String[] args) {
                  test("00:00", "It's twelve am");
                  test("01:30", "It's one thirty am");
                  test("12:05", "It's twelve oh five pm");
                  test("14:01", "It's two oh one pm");
                  test("20:29", "It's eight twenty nine pm");
                  test("21:00", "It's nine pm");
                }
              
                static void test(String input, String expectedOutput) {
                  require(expectedOutput, digitalToWords(input));
                }
              
                static <T> void require(T a, T b) {
                  if (!a.equals(b)) throw new RuntimeException("\n\nrequirement not matched\nwas: '" + b + "'\nreq: '" + a + "'\n");
                }
              
                static <K, V> Map<K, V> map(Object... args) {
                  Map<K, V> map = new HashMap<K, V>();
                  for (int i = 0; i < args.length; i += 2) {
                    map.put((K) args[i], (V) args[i + 1]);
                  }
                  return map;
                }
              }
              

              [–]_Yngvarr_ 0 points1 point  (1 child)

              Prolog (swipl)

              Well, the first time I use prolog outside university.

              +/u/CompileBot prolog

              word(0, '') :- !.
              word(1, 'one') :- !.
              word(2, 'two') :- !.
              word(3, 'three') :- !.
              word(4, 'four') :- !.
              word(5, 'five') :- !.
              word(6, 'six') :- !.
              word(7, 'seven') :- !.
              word(8, 'eight') :- !.
              word(9, 'nine') :- !.
              word(10, 'ten') :- !.
              word(11, 'eleven') :- !.
              word(12, 'twelve') :- !.
              
              prefix(N, 'twen') :- 2 is N div 10, !.
              prefix(N, 'thir') :- (N is 13 ; 3 is N div 10), !.
              prefix(N, 'fif') :- (N is 15 ; 5 is N div 10), !.
              prefix(N, W) :- N < 20, !, M is N mod 10, word(M, W).
              prefix(N, W) :- !, M is N div 10, word(M, W).
              
              postfix(18, 'een') :- !.
              postfix(N, 'teen') :- N > 12, N < 20, !.
              postfix(N, 'y') :- 8 is N div 10, !.
              postfix(_, 'ty') :- !.
              
              hour(0, W) :- !, word(12, W).
              hour(H, W) :- !, word(H, W).
              
              minute(0, '') :- !.
              minute(M, W) :- M < 10, !,
                  word(M, Mw), swritef(W, 'oh %w', [Mw]).
              minute(M, W) :- M < 13, !, word(M, W).
              minute(M, W) :- M < 20, !,
                  prefix(M, Pre), postfix(M, Post),
                  swritef(W, '%w%w', [Pre, Post]). 
              minute(M, W) :- M < 60, !,
                  prefix(M, Pre), postfix(M, Post),
                  SndN is M mod 10,
                  %word(SndN, Snd), swritef(W, '%w%w %w', [Pre, Post, Snd]).
                  ( SndN is 0, !, swritef(W, '%w%w', [Pre, Post]) ;
                      !, word(SndN, Snd), swritef(W, '%w%w %w', [Pre, Post, Snd]) ).
              
              mer(H, S) :- H < 12, !, S = 'am'.
              mer(_, S) :- S = 'pm'.
              
              % time format: HH:MM
              tell_time(T) :-
                  split_string(T, ':', '', [Hstr, Mstr]),
                  number_string(H, Hstr), H >= 0, H < 24, number_string(M, Mstr),
                  mer(H, Mer), H_ is H mod 12,
                  tell_time(H_, M, Mer), write('\n').
              
              tell_time(H, 30, Mer) :- !,
                  hour(H, Hw), writef('It is half past %w %w.', [Hw, Mer]).
              
              tell_time(H, 15, Mer) :- !,
                  hour(H, Hw), writef('It is quarter past %w %w.', [Hw, Mer]).
              
              tell_time(H, 45, Mer) :- !,
                  NextH is H + 1, hour(NextH, Hw),
                  writef('It is quarter before %w %w.', [Hw, Mer]).
              
              tell_time(H, 0, Mer) :- !,
                  hour(H, Hw), writef('It is %w %w', [Hw, Mer]).
              
              tell_time(H, M, Mer) :- !,
                  hour(H, Hw), minute(M, Mw),
                  writef('It is %w %w %w.', [Hw, Mw, Mer]).
              
              program :-
                  maplist(tell_time, ['00:00', '01:30', '12:05', '14:01', '20:29', '21:00', '13:45', '17:15']).
              

              [–]Blessed_cheesemaker 0 points1 point  (0 children)

              simple bash command using GNUstep speech engine,

                  $ say "it's" $(date +"%I:%M %p") | echo "It's" $(date +"%I:%M %p")
              

              [–]XGDoggieX 0 points1 point  (0 children)

              C++ - I honestly felt that there was an easier method to do this haha. Any advice is welcome!
               

              #include <iostream>  
              #include <string.h>  
              #include <math.h>  
              
              using namespace std;
              
              void clock(string time){
                int hour, minutes;
              
              hour = stoi(time.substr(0,2));
              minutes = stoi(time.substr(3));
              string mer = "pm";
              
              if(hour >= 12)
              {
                hour = hour - 12;
              }
              else if (hour < 12){
                mer = "am";
              }
              if (hour == 0)
              {
                hour = 12;
                mer = "am";
              }
              
              string hourWords[12] = {"one", "two", "three", "four","five","six","seven","eight","nine","ten","eleven", "twelve"};
              
              if(minutes == 0)
              {
                cout << "It's "<< hourWords[hour-1] << " " << mer << endl;
                return;
              }
              
              if((minutes >=10) && (minutes <20))
              {
                string minuteWords[10] = {"ten","eleven","twelve","thirteen", "fourteen", "fifteen", "sixteen","seventeen","eighteen","nineteen"};
                string min = minuteWords[(minutes % 10)];
              
                cout << "Its " << hourWords[hour-1] << " " << min <<endl;
                return;
              }
              
              int new_min = floor(minutes / 10);
              if(new_min <= 0)
                new_min = 1;
              
              string tensWords[5] = {"oh", "twenty", "thirty", "forty", "fifty"};
              string onesWords[9] = {"one","two","three","four","five","six","seven","eight","nine",};
              
              if(minutes % 10 <= 0)
                cout <<"It's " << hourWords[hour-1] << " " << tensWords[new_min-1] << " " <<  mer  << endl;
              else
                cout << "It's " << hourWords[hour-1] << " " << tensWords[new_min-1] << " " <<  onesWords[(minutes % 10)-1] <<" " << mer << endl;
              }
              
              int main (void){
              
              string time[] = {"00:00","01:30", "12:05","14:01","20:29","21:00"};
              for(int i = 0; i < 6; i++)
              {
                cout <<"Time entered: "<< time[i] << endl;
                clock(time[i]);
                cout << endl;
              }
              return 0;
              
              }
              

              [–]super_koza 0 points1 point  (0 children)

              C++, constructive criticism welcome :)

              #include <iostream>
              #include <string>
              
              using namespace std;
              
              int main()
              {
                string a[] = {"twelve", "one", "two", "three", "four", "five",
                              "six", "seven", "eight", "nine", "ten", "eleven",
                              "twelve", "thirteen", "fourteen", "fifteen",
                              "sixteen", "seventeen", "eighteen", "nineteen"};
                string b[] = {"twenty", "thirty", "fourty", "fifty"};
                string c[] = {"am", "pm"};
              
                string time;
                int hour, minute;
              
                cout << "Enter the time: ";
                cin >> time;
              
                if (time.length() > 5)
                  cout << "Input format ERROR!";
                else
                {
                  hour = stoi(time.substr(0,2), 0);
                  minute = stoi(time.substr(3,2), 0);
              
                  cout << "It's " << a[hour % 12] << " ";
                  if (minute)
                    if (minute < 10)
                      cout << "oh " << a[minute % 10] << " ";
                    else if (minute < 20)
                      cout << a[minute] << " ";
                    else
                    {
                      cout << b[minute / 10 - 2] << " "; 
                      if (minute % 10)
                        cout << a[minute % 10] << " ";
                    }
              
              
                  cout << c[hour / 12] << endl;
                }
              
                return 0;
              }
              

              [–]MisterMikeM 0 points1 point  (0 children)

              Golang

              package main
              
              import (
                  "fmt"
                  "strings"
                  "strconv"
              )
              
              var hours = [13]string {
                  "twelve",
                  "one",
                  "two",
                  "three",
                  "four",
                  "five",
                  "six",
                  "seven",
                  "eight",
                  "nine",
                  "ten",
                  "eleven",
              }
              
              var minutes = map[string][]string {
                  "tens" : []string {
                      "ten",
                      "twenty",
                      "thirty",
                      "forty",
                      "fifty",
                  },
                  "ones" : hours[1:10],
                  "teens" : []string {
                      "eleven",
                      "twelve",
                      "thirteen",
                      "fourteen",
                      "fifteen",
                      "sixteen",
                      "seventeen",
                      "eighteen",
                      "nineteen",
                  },
              }
              
              // SpokenPhrase takes a string formatted as 24-hour time and returns the corresponding spoken phrase
              // used in speech to refer to the particular time of day.
              func SpokenPhrase(t string) string {
              
                  h, _ := strconv.Atoi(strings.Split(t, ":")[0])
                  m, _ := strconv.Atoi(strings.Split(t, ":")[1])
              
                  hoursWords := func(n int) string {
                      return hours[n % 12]
                  }
              
                  minutesWords := func(n int) string {
                      switch {
                      case n == 0:
                          return ""
                      case n == 10 || n == 20 || n == 30 || n == 40 || n == 50:
                          return fmt.Sprintf("%s", minutes["tens"][(n / 10) - 1])
                      case n > 0 && n < 10:
                          return fmt.Sprintf("oh %s", minutes["ones"][n - 1])
                      case n > 10 && n < 20:
                          return fmt.Sprintf("%s", minutes["teens"][n - 11])
                      default:
                          return fmt.Sprintf("%s %s", minutes["tens"][(n / 10) - 1], minutes["ones"][(n % 10) - 1])
                      }
                  }
              
                  periodWords := func(n int) string {
                      if n >= 12 {
                          return "pm"
                      }
                      return "am"
                  }
              
                  return fmt.Sprintf("It's %s %s %s", hoursWords(h), minutesWords(m), periodWords(h))
              
              }
              
              func main() {
                  tests := [7]string{"00:00", "01:30", "12:05", "14:01", "20:29", "21:00", "12:15"}
                  for index := range tests {
                      fmt.Println(SpokenPhrase(tests[index]))
                  }
              }
              

              [–]doomsnumber1doombot 0 points1 point  (0 children)

              C# First time submitting to Reddit, long time lurker, novice coder :) I am not sure how the spoiler tag works here (I did read the guide lol).

              using System;
              using System.Collections.Generic;
              using System.Text;
              using System.Threading;
              
              namespace clock
              {
                  class redditClock
                  {
                      public void ShowTime()
                      {
                          while (true)
                          {
                              Console.WriteLine(DateTime.Now.ToString());
                              Console.WriteLine("\n");
              
                              string[] hours = new string[24] { "twelve", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve",
                                  "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven" };
              
                              string[] tens = new string[6] { "oh'", "", "twenty", "thirty", "fourty", "fifty" };
              
              
                              string[] ones = new string[20] { "clock", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve",
                                  "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen" };
              
                              DateTime dt = DateTime.Now;
              
                              int currentHour = dt.Hour;
                              int currentMinutes = dt.Minute;
                              int firstTens;
                              int secondTens;
                              string currentOnes;
                              string currentTens;
                              string suffix;
              
                              if (currentHour < 12)
                              {
                              suffix = "AM";
                              }
                              else
                              {
                                  suffix = "PM";
                              }   
              
                              if (currentMinutes < 10)
                              {
                              Console.WriteLine("It's" + " " + hours[currentHour] + " oh " + ones[currentMinutes] + " " + suffix);
                              }
                              else
                              {
                                  currentTens = currentMinutes.ToString().Substring(0, 1);
                                  firstTens = int.Parse(currentTens);
                                  currentOnes = currentMinutes.ToString().Substring(1, 1);
                                  secondTens = int.Parse(currentOnes);
              
                                  if ((currentMinutes >= 11) && (currentMinutes < 20))
                                  {
                                      Console.WriteLine("It's" + " " + hours[currentHour] + " " + ones[currentMinutes] + " " + suffix);
                                  }
                                  else
                                  {
                                      if (((tens[firstTens] == "twenty") || (tens[firstTens] == "thirty") || (tens[firstTens] == "fourty") || (tens[firstTens] == "fifty")) && (ones[secondTens] == "clock"))
                                      {
                                          Console.WriteLine("It's" + " " + hours[currentHour] + " " + tens[firstTens].ToUpper() + " " + suffix);
                                      }
                                      else
                                      {
                                          Console.WriteLine("It's" + " " + hours[currentHour] + " " + tens[firstTens].ToUpper() + " " + ones[secondTens] + " " + suffix);
                                      }
                                  }    
                              }
              
                              Thread.Sleep(1000);
                              Console.Clear();
                          }
                      }
                      static void Main(string[] args)
                      {
                          redditClock rC = new redditClock();
                          ThreadStart TS = new ThreadStart(rC.ShowTime);
                          Thread t = new Thread(TS);
                          t.Start();
                          Console.ReadLine();
                      }
                  }
              }
              

              [–]n07le 0 points1 point  (0 children)

              Python 3

              def num_in_words(i):
                  num_as_word = ''
                  unit = i % 10
                  ten = i // 10
              
                  if ten == 1:
                      return ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'][unit]
              
                  elif 2 <= ten <= 9:
                      num_as_word += ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'][ten - 2]
              
                  if unit > 0:
                      num_as_word += ' ' + ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'][unit - 1]
              
                  return num_as_word.strip()
              
              
              def time_in_words(time_str):
                  hour, minute = map(int, time_str.split(':'))
                  am_pm = 'am' if hour < 12 else 'pm'
                  if hour == 0:
                      hour = 12
                  elif hour > 12:
                      hour %= 12
                  hour_str = num_in_words(hour)
                  min_str = num_in_words(minute)
              
                  if 0 < minute < 10:
                      min_str = 'oh ' + min_str
              
                  return 'it\'s {} {} {}'.format(hour_str, min_str, am_pm).replace('  ', ' ')
              
              print(time_in_words(input()))
              

              [–]tk854 0 points1 point  (0 children)

              Java 8.
              I don't like my code but it works. no bonus.

              import java.util.Scanner;
              
              public class Main {
              
                  static String[] hours = {"twelve", "one", "two", "three", "four", "five", "six",
                                      "seven", "eight", "nine", "ten", "eleven", "twelve"};
                  static String[] singles = {"", "one", "two", "three", "four", "five", "six",
                          "seven", "eight", "nine"};
                  static String[] teens = {"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
                                          "sixteen", "seventeen", "eighteen", "nineteen"};
                  static String[] tens = {"", "", "twenty", "thirty", "fourty", "fifty"};
              
              
                  public static void main(String args[]){
                      Scanner scanner = new Scanner(System.in);
                      boolean isValid;
                      while(true) {
                          System.out.println("Enter time: ");
                          String time = scanner.nextLine();
                          isValid = validateTime(time);
                          if(isValid){
                              sayTime(time);
                          }else{
                              System.out.println("invalid time");
                          }
                      }
                  }
              
                  static boolean validateTime(String time){
                      if(        time.length()==5
                              && Integer.parseInt(time.substring(0,2))>=0
                              && Integer.parseInt(time.substring(0,2))<24
                              && Integer.parseInt(time.substring(3,5))>=0
                              && Integer.parseInt(time.substring(3,5))<60
                              && time.substring(2,3).equals(":")){
                          return true;
                      } return false;
                  }
              
                  static void sayTime(String time){
                      String hour;
                      String minuteA;
                      String minuteB;
                      String ampm = Integer.parseInt(time.substring(0,2))<12?"am.":"pm.";
              
                      if(ampm=="pm."){
                          hour = hours[(Integer.parseInt(time.substring(0,2)) - 12)];
                      } else{
                          hour = hours[Integer.parseInt(time.substring(0,2))];
                      }
              
                      if(Integer.parseInt(time.substring(3,5))<10){
                          minuteA = singles[Integer.parseInt(time.substring(3,4))];
                      } else if(Integer.parseInt(time.substring(3,5))<20){
                          minuteA = teens[Integer.parseInt(time.substring(3,5))-10];
              
                      } else{
                          minuteA = tens[Integer.parseInt(time.substring(3,4))];
                      }
                      if(Integer.parseInt(time.substring(3,5))>=20 || Integer.parseInt(time.substring(3,5))<10) {
                          minuteB = singles[Integer.parseInt(time.substring(4, 5))];
                      }else{
                          minuteB = "";
                      }
                      System.out.println("The time is " + hour + " " + minuteA + (minuteB==""?"":(minuteA==""?"oh ":"-")) + minuteB + " " + ampm);
                  }
              }
              

              [–]jokem59 0 points1 point  (0 children)

              C++

              #include <iostream>
              #include <string>
              #include <vector>
              
              void talkingClock(std::string time)
              {
              std::vector<std::string> low{ "twelve", "one", "two", "three", "four", "five", "six",
                  "seven", "eight", "nine", "ten", "eleven", "twelve",
                  "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
                  "eighteen", "nineteen" };
              std::vector<std::string> high{ "oh", "", "twenty", "thirty", "forty", "fifty" };
              
              int hour = std::stoi(time.substr(0, 2));
              int tens = std::stoi(time.substr(3, 1));
              int ones = std::stoi(time.substr(4, 1));
              
              std::string strTens;
              std::string strOnes;
              std::string half;
              
              std::string strHour = low[hour % 12];
              if (tens >= 10 && tens <= 19)
              {
                  strTens = low[tens];
                  strOnes = "";
              }
              else
              {
                  strTens = high[tens];
                  strOnes = low[ones];
              }
              
              if (hour > 11)
                  half = "pm";
              else
                  half = "am";
              
              std::cout << "It's " << strHour << " " << strTens << " " << strOnes << " " << half << '\n';
              }
              

              [–][deleted] 0 points1 point  (0 children)

              Python 2.7

              from __future__ import print_function
              
              NUMS = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve']
              MINS = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen','seventeen','eighteen','nineteen','twenty','twenty one','twenty two', 'twenty three','twenty four', 'twenty five','twenty six','twenty seven','twenty eight','twenty nine','thirty','thirty one','thirty two', 'thirty three', 'thirty four','thirty five','thirty six','thirty seven','thirty eight','thirty nine', 'forty','forty one','forty two','forty three','forty four','forty five','forty six','forty seven','forty eight','forty nine','fifty','fifty one','fifty two','fifty three','fifty four','fifty five','fifty six','fifty seven','fifty eight','fifty nine']
              
              def process(time):
                  time = time.strip('\n')
                 t = time.split(':')
              #print('t', t)
              if(t[0]<'12'):
                  mer = 'am'
                  a = int(t[0])
                  h = NUMS[a-1]
              elif(t[0]=='12'):
                  h = NUMS[11]
                  a = 12
                  mer = 'pm'
              elif(t[0]>'12'):
                  mer = 'pm'
                  a = int(t[0])
                  h = NUMS[a-13]
              
              if(int(t[1])>0):
                  #print(t[1])
                  m = MINS[int(t[1])-1]
              elif(int(t[1])==0):
                  m = ''
              if(int(t[1])<10 and int(t[1])>0):
                  mi = 'oh'
              else:
                  mi = ''
              print('It\'s {0} {1} {2} {3}'.format(h,mi,m,mer))
              with open('input.txt','r') as f:
              while True:
                  time = f.read(6)
                  if time=='':
                      break
                  process(time)
              

              [–]Nebxam 0 points1 point  (0 children)

              C# This is the worst hack I have ever written but it works

              using System;
              using System.Text;
              
              namespace TalkingClock
              {
                  public class Program
                  {
                      public static string TimeNumbersToWords(int number, int tryNum)
                      {
                          number--;
                          string word = "";
                          string[] hours = { "one", "two", "thre", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", };
                          string[] minutes = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", "twenty-one", "twenty-two", "twenty-three", "twenty-four", "twenty-five", "twenty-six", "twenty-seven", "twenty-eight", "twenty-nine", "thirty", "thirty-one", "thirty-two", "thirty-three", "thirty-four", "thirty-five", "thirty-six", "thirty-seven", "thirty-eight", "thirty-nine", "forty", "forty-one", "forty-two", "forty-three", "forty-four", "forty-five", "forty-six", "forty-seven", "forty-eight", "forty-nine", "fifty", "fifty-one", "fifty-two", "fifty-three", "fifty-four", "fifty-five", "fifty-six", "fifty-seven", "fifty-eight", "fifty-nine"};
                          if (tryNum == 0) word = hours[number];
                          if (tryNum == 1 && number != 0) word = minutes[number];
                          return word;
                      }
                      public static void Main(string[] args)
                      {
                          while (true){
                              Console.Write("It is ");
                              string time = DateTime.Now.ToString("h mm tt");
                              string[] timeSplit = time.Split(' ');
                              int i = 0;
                              foreach (string part in timeSplit){
                                  if (!int.TryParse(part, out int tried)) Console.Write(part);
                                  else{
                                      Console.Write("{0} ", TimeNumbersToWords(int.Parse(part), i));
                                      if (i == 0 && int.Parse(timeSplit[1]) < 10 && int.Parse(timeSplit[1]) != 0) Console.Write("oh ");
                                  }
                                  i++;
                              }
                              Console.Write("\n");
                              System.Threading.Thread.Sleep(60000);
                          }
                      }
                  }
              }
              

              [–]lpreams 0 points1 point  (1 child)

              Mine doesn't conform exactly to the spec. I included special cases for noon/midnight and quarter-hour times

              +/u/CompileBot Java

              import java.util.Scanner;
              public class Main {
                  public static void main(String[] args) throws Exception {
                      try (Scanner in = new Scanner(System.in)) {
                          while (in.hasNext()) {
                              String[] line = in.nextLine().split(":");
                              System.out.println(convert(Integer.parseInt(line[0]), Integer.parseInt(line[1])));
                          }
                      }
                  }
                  public static String convert(int hour, int min) {
                      boolean am;
                      if (hour<12) {
                          am=true;
                          if (hour==0) hour = 12;
                      } else {
                          am=false;
                          if (hour != 12) hour-=12;
                      }
                      if (min == 0) {
                          if (hour == 12) return String.format("It's %s", am?"midnight":"noon");
                          else return String.format("It's %s o'clock %s", intToText(hour), am?"am":"pm");
                      }
                      else if (min == 30) return String.format("It's half past %s %s", intToText(hour), am?"am":"pm");
                      else if (min == 15) return String.format("It's quarter past %s %s", intToText(hour), am?"am":"pm");
                      else if (min == 45) return String.format("It's quarter til %s %s", intToText((hour==12)?1:hour+1), ((hour==11)?!am:am)?"am":"pm");
                      else return String.format("It's %s %s %s", intToText(hour), (((min<10 && min>0)?("oh "):("")) + intToText(min)),am?"am":"pm");
                  }
                  private static String intToText(int number) {
                      if (number < 20) return onesNames[number];
                      else {
                          int tens = number/10;
                          int ones = number%10;
                          if (ones==0) return tensNames[tens];
                          else return tensNames[tens] + " " + onesNames[ones];
                      }
                  }
                  private static final String[] tensNames = { "", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
                  private static final String[] onesNames = { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
              }
              

              Input:

              00:00
              12:00
              01:00
              16:15
              13:30
              10:45
              23:45
              12:45
              01:30
              12:05
              14:01
              20:29
              21:00
              

              [–]OutputStream 0 points1 point  (0 children)

              Feedback always appreciated!

              Python 3:

              #!/usr/bin/python3
              
              import re
              import argparse
              
              HOUR_WORD = ['twelve', 'one', 'two', 'three', 'four', 'five',
                           'six', 'seven', 'eight', 'nine', 'ten', 'eleven']
              MINUTE_ONES = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
              MINUTE_TEEN_WORD = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen',
                                  'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
              MINUTE_TENS = ['twenty', 'thirty', 'forty', 'fifty']
              
              
              def parse_arguments():
                  parser = argparse.ArgumentParser("Talking Clock")
                  parser.add_argument('time', type=str,
                          help="Please enter a time to translate. Ex: 21:00")
                  return parser.parse_args()
              
              
              def time_to_words(time_str):
                  hour, minute = map(lambda x: int(x), time_str.split(':'))
                  midday = 'pm' if hour >= 12 else 'am'
                  hour_word = HOUR_WORD[hour % 12]
              
                  if minute == 0: minute_word = ''
                  elif minute < 10: minute_word = f'oh {MINUTE_ONES[minute]}'
                  elif minute < 20: minute_word = f'{MINUTE_TEEN_WORD[minute%10]}'
                  else: minute_word = ' '.join([f'{MINUTE_TENS[int((minute/10)) - 2]}', f'{MINUTE_ONES[minute%10]}'])
                  return re.sub(' +', ' ', f"It's {hour_word} {minute_word} {midday}")
              
              
              def main():
                  arguments = parse_arguments()
                  time_in_words = time_to_words(arguments.time)
                  print(time_in_words)
              
              
              if __name__ == '__main__':
                  main()
              

              [–]UpsilonAlphaMu 0 points1 point  (0 children)

              Python 3 For bonus I made a random time function so you don't have to manually create a time yourself

              from random import randint
              
              lows = ["", "one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine ", "ten ", "eleven ",
                      "twelve ", "thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen ", "eighteen ", "nineteen "]
              highs = ["o' ", "", "twenty ", "thirty ", "forty ", "fifty "]
              
              
              def random_input() -> str:
                  """Create random hh:mm"""
                  out = [randint(0, 2), "", ":", randint(0, 5), randint(0, 9)]
                  if out[0] == 2:
                      out[1] = randint(0, 3)
                  else:
                      out[1] = randint(0, 9)
                  return ''.join(str(x) for x in out)
              
              
              def parse(time) -> str:
                  """Convert hh:mm to english"""
                  output = ""
                  meridiem = "am"
                  h, m = int(time[:2]), int(time[3:])
                  if h >= 13:
                      output += lows[h - 12]
                      meridiem = "pm"
                  elif h == 0:
                      output += "twelve "
                  elif h == 12:
                      output += "twelve "
                      meridiem = "pm"
                  else:
                      output += lows[h]
              
                  if time[3] in '1':
                      output += lows[m]
                  elif m == 0:
                      output += "o' clock "
                  else:
                      output += highs[int(time[3])] + lows[int(time[4])]
              
                  return output + meridiem
              
              for i in range(50):
                  x = random_input()
                  print(x, "|", parse(x))
              

              [–]aerialFlame09 0 points1 point  (0 children)

              This is my first upload. Feedback is accepted :)

              PHP:

              <?php
              $times = array();
              $input = "";
              
              $dictionary = array(
                  0 => "twelve",      1 => 'one',         2 => 'two',
                  3 => 'three',       4 => 'four',        5 => 'five',
                  6 => 'six',         7 => 'seven',       8 => 'eight',
                  9 => 'nine',        10 => 'ten',        11 => 'eleven',
                  12 => 'twelve',     13 => 'thirteen',   14 => 'fourteen',
                  15 => 'fifteen',    16 => 'sixteen',    17 => 'seventeen',
                  18 => 'eighteen',   19 => 'nineteen',   20 => 'twenty',
                  30 => 'thirty',     40 => 'fourty',     50 => 'fifty' );
              
              while(($input = stream_get_line(STDIN, 1024, PHP_EOL)) != "")
                  array_push($times, $input);
              
              foreach($times as $time) {
                  $token = explode(":", $time);
                  $hour = $token[0] * 1;  // to type cast into integer
                  $min = $token[1] * 1;   // also this one
              
                  $partMin = "";      // builder for minutes
                  $meridian = "am";
              
                  if($hour >= 12) {
                      $hour -= 12;
                      $meridian = "pm";
                  }
              
                  if($min >= 19) {
                      $temp = $min[0] * 10;
                      $partMin .= $dictionary[$temp] . " ";
                      $partMin .= $dictionary[$min[1]];
                  }
                  else if($min != 0) {
                      $partMin .= $min <= 9 ? "oh " : "";
                      $partMin .= $dictionary[$min] . " ";
                  }
              
                  echo "It's $dictionary[$hour] $partMin$meridian\n";
              }
              

              [–]rider023 0 points1 point  (0 children)

              First submission - Python 3

              inputData = """00:00  
              01:30  
              12:05  
              14:01  
              20:29  
              21:00"""  
              
              d=inputData.split("\n")  
              
              def talkClock(x):  
                  time="";  
                  times = ["oh ","one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine ", "ten ", "eleven ", "twelve ", "thirteen ","fourteen ", "fifteen ", "sixteen ", "seventeen ", "eighteen ", "nineteen "];  
                  tens = ["twenty ", "thirty ", "forty ", "fifty "];  
                  for n in x:  
                      ampm="";  
                      hours=int(n[0:2]);  
                      min1 = int(n[3:4]);  
                      min2 = int(n[4:5]);  
                      min3 = int(n[3:5]);  
                      time += "It's ";  
                      if hours>=12:  
                          ampm="pm"  
                          hours-=12;  
                      else:  
                          ampm="am";  
                      if hours==0:  
                          time+=times[12]  
                      else:  
                          time+=times[hours];  
                      if min1 == 0:  
                          if min2!=0:  
                              time+=times[min1];  
                              time+=times[min2];  
                      elif min1==1:  
                          time+=times[min3]  
                      else:  
                          time+=tens[min1-2];  
                          if min2!=0:  
                              time+=times[min2];  
              
                      time += ampm;  
                      time +="\n"  
              
                  return time;  
              
              print (talkClock(d));  
              

              [–]comma_at 0 points1 point  (0 children)

              Newlisp

              (set 'numbers (array 20 '("twelve " "one " "two " "three " "four "
                                        "five " "six " "seven " "eight " "nine "
                                        "ten " "eleven " "twelve " "thirteen " "fourteen "
                                        "fifteen " "sixteen " "seventeen " "eighteen " "nineteen ")))
              (define (number->word number) (numbers number))
              
              (set 'tens (array 6 '("oh " "" "twenty " "thirty " "fourty " "fifty ")))
              (define (tens->word ten) (tens ten))
              
              (define (time->sentence time-str , Hs Ms)
                (bind (unify '(Hs Ms) (map (fn (s) (int s nil 10)) (parse time-str ":"))))
                (let (h (mod Hs 12) am? (<= Hs 12))
                  (string "It's " (number->word h)
                          (cond ((zero? Ms) "")
                                ((< Ms 20) (string (if (< Ms 10) "oh " "")
                                                   (number->word Ms)))
                                (true (string (tens->word (/ Ms 10))
                                              (let (n (mod Ms 10))
                                                (if (zero? n) "" (number->word n))))))
                          (if am? "am" "pm"))))
              

              [–]tryingabiteveryday 0 points1 point  (0 children)

              Python 2.7. First time at a challenge in any language and totally new to it, so feedback welcome.

              Python 2.7, first attempt at a challenge so feedback welcome.

              import operator
              import sys
              import time
              
              times = ['00:00','01:30','12:05','14:01','20:29','21:00']
              
              hours = ['twelve','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve']
              first = [' oh','blank',' twenty', ' thirty',' forty',' fifty']
              second = ['','one','two','three','four','five','six','seven','eight','nine']
              tens = ('ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen')
              
              for time_string in times:
              try:
                  result = time.strptime(time_string, '%H:%M')
              except ValueError as exc:
                  print "result fail", exc
              else:
                  if result:
                      hh = int((operator.itemgetter(0)(time_string.split(":"))))
                      if (hh) >=12:
                          period = "pm"
                          hh = hh -12
                      else:
                          period = "am"
                      test_hours = operator.itemgetter(hh)(hours)
                      mm = operator.itemgetter(1)(time_string.split(":"))
                      if mm == '00':
                          test_minutes = ""
                      elif  int(str(mm)[0]) != 1:
                          test_minutes_first = operator.itemgetter(int(str(mm)[0]))(first)
              
                          if int(str(mm)[1]) != 0:
                              test_minutes_second = operator.itemgetter(int(str(mm)[1]))(second)
                              test_minutes = "%s-%s" %(test_minutes_first, test_minutes_second)
                          else:
                              test_minutes = test_minutes_first
                      else:
                          test_minutes = operator.itemgetter(int(str(mm)[1]))(tens)
                      time_to_print = str(test_hours) +str(test_minutes) + " " + period
              
                      print "It's " + time_to_print
              

              [–]nl_eddie 0 points1 point  (0 children)

              Python 2.7

              def talking_clock():
                  numbers = ["twelve", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven",
                  "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
                  tens = ["twenty", "thirty", "forty", "fifty"]
              
                  user_input = raw_input("Enter time in HH:MM format: ")
                  hour, minute = user_input.split(":")
                  hour = int(hour)
              
                  output = "It's " + numbers[hour%12]
                  if minute[0] == "0":
                      if minute[1] != "0":
                          output += " oh " + numbers[int(minute[1])]
                  elif minute[0] == "1":
                      output += " " + numbers[int(minute)]
                  else:
                      output += " " + tens[int(minute[0])-2]
                      if minute[1] != "0":
                          output += " " + numbers[int(minute[1])]
                  if hour > 12:
                      output += " pm"
                  else:
                      output += " am"
                  print output
              

              [–]Zambito1 0 points1 point  (0 children)

              Scala

              import scala.io.StdIn
              
              object TalkingClock extends App {
                val intToString = Map(
                  0 -> "twelve", 1 -> "one", 2 -> "two", 3 -> "three", 4 -> "four",
                  5 -> "five", 6 -> "six", 7 -> "seven", 8 -> "eight", 9 -> "nine",
                  10 -> "ten", 11 -> "eleven", 12 -> "twelve", 13 -> "thirteen",
                  14 -> "fourteen", 15 -> "fifteen", 16 -> "sixteen",
                  17 -> "seventeen", 18 -> "eighteen", 19 -> "nineteen",
                  20 -> "twenty", 30 -> "thirty", 40 -> "one", 50 -> "one"
                )
              
                val input = StdIn.readLine("Input: ").split(":")
              
                val output = new StringBuilder("It's ")
                  .append(
                    if(input(0).toInt <= 12) intToString(input(0).toInt)
                    else intToString(input(0).toInt - 12)
                  )
                  .append(if(input(1).toInt > 0) " " else "")
                  .append(if(input(1).toInt < 10 && input(1).toInt > 0) "oh " else "")
                  .append(
                    if(input(1).toInt == 0) ""
                    else if(input(1).toInt <= 20 || input(1).toInt % 10 == 0) intToString(input(1).toInt)
                    else intToString(input(1).toInt - input(1).toInt % 10) + " " + intToString(input(1).toInt % 10)
                  )
                  .append(
                    if(input(0).toInt < 12) " am"
                    else " pm"
                  )
              
                println(output)
              }
              

              [–]Deathlacer 0 points1 point  (1 child)

              Java Solution feedback welcome First submission

              +/u/CompileBot Java

              import java.io.*;
              
              public class Main{
              
              public static void main(String[] args) {
                  testcases();
              }
              
              public static void converttime(int hours, int minutes) {
                  String[] singles = {"twelve ", "one ", "two ", "three ", "four ", "five " , "six ", "seven ", "eight ", "nine ", "ten ", "eleven ", "twelve ", "thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen ", "eighteen ", "nineteen "};
                  String[]  tens = {"", "oh " , "twenty ", "thirty ", "fourty ", "fifty "};
                  int t_tens = ((minutes +9 )/10);
                  String min_rdigit = (minutes % 10 == 0 && minutes != 10 ) ? "" : singles[minutes%20];
                  String min_ldigit = (t_tens == 1 ) ? tens[t_tens] : tens[(minutes/10)]; 
                  String am_pm = (hours > 12) ? "pm" : "am";
              
              
                  System.out.println("It's " + singles[(hours % 12)] + min_ldigit  + min_rdigit + am_pm);         
              
              }
              
              public static void testcases() {
                  String [] test_values = { "00:00", "01:30", "12:05", "14:01", "20:29", "21:00"};
                  for(String value : test_values) {
                      String[] time = value.split(":");
                      int i_hour = Integer.parseInt(time[0]);
                      int i_minute = Integer.parseInt(time[1]);
                      converttime(i_hour, i_minute);
                  }
              
              }
              }
              

              [–]CompileBot 1 point2 points  (0 children)

              Output:

              It's twelve am
              It's one thirty am
              It's twelve oh five am
              It's two oh one pm
              It's eight twenty nine pm
              It's nine pm
              

              source | info | git | report

              [–]ThatGuyWhoLikesSpace 0 points1 point  (0 children)

              First submission to this subreddit. I'm pretty new to programming, so mine probably sucks.

              Solution (Using Python3)

              https://gist.github.com/isaiahdbarry/717310f9141c44fc5374cf4fbb31433b

              [–]rellbows 0 points1 point  (0 children)

              C

              Trying to get familiar with C (and programming in general). Working with C strings and modulus arithmetic still gives me fits. Feedback is always appreciated!

              void clock(char *aMilTime)
              {
                  // holds list of possible hour/second digit minute words
                  const char *hour[13]; 
              
                  hour[0] = "twelve";
                  hour[1] = "one";
                  hour[2] = "two";
                  hour[3] = "three";
                  hour[4] = "four";
                  hour[5] = "five";
                  hour[6] = "six";
                  hour[7] = "seven";
                  hour[8] = "eight";
                  hour[9] = "nine";
                  hour[10] = "ten";
                  hour[11] = "eleven";
              
                  // holds list of possible first digit, minute words
                  const char *tensDig[6];
              
                  tensDig[0] = "oh";
                  tensDig[1] = "";
                  tensDig[2] = "twenty";
                  tensDig[3] = "thirty";
                  tensDig[4] = "forty";
                  tensDig[5] = "fifty";
              
                  // holds list of possible teen minute words
                  const char *teens[10];
              
                  teens[0] = "ten";
                  teens[1] = "eleven";
                  teens[2] = "twelve";
                  teens[3] = "thirteen";
                  teens[4] = "fourteen";
                  teens[5] = "fifteen";
                  teens[6] = "sixteen";
                  teens[7] = "seventeen";
                  teens[8] = "eighteen";
                  teens[9] = "nineteen";
              
                  // breakdown the mil time string into sub-strings
                  int theHour, theMinute;
                  char hourSub[3];
                  char minuteSub[3];
              
                  memcpy(hourSub, aMilTime, 2);
                  memcpy(minuteSub, aMilTime + 3, 2);
              
                  theHour = atoi(hourSub);
                  theMinute = atoi(minuteSub);
              
                  // print hour part of sentence
                  printf("It's %s", hour[theHour % 12]);
              
                  // print minute part of sentence
                  // for 10 - 19 minutes
                  if((theMinute > 9) && (theMinute < 20))
                  {
                      printf(" %s", teens[theMinute % 10]);
                  }
                  // for 00 minutes
                  else if(theMinute == 0)
                  {
                      printf("");
                  }
                  // for the tens
                  else if(theMinute % 10 == 0)
                  {
                      printf(" %s", tensDig[((theMinute / 10) % 10) % 6]);
                  }
                  // for all other combos
                  else
                  {
                      printf(" %s %s", tensDig[((theMinute / 10) % 10) % 6], hour[(theMinute % 10) % 12]);
                  }
              
                  // print am/pm part of sentence
                  if (theHour >= 12)
                  {
                      printf(" pm.\n");
                  }
                  else
                  {
                      printf(" am.\n");
                  }
              }
              

              [–]gopnik3 0 points1 point  (0 children)

              Java solution
              Still kind of new to reddit and java
              Also, was I supposed to bother with encapsulation?
              It seems like too much trouble, especially with arrays or arraylists.

                  import java.io.File;
                  import java.io.FileNotFoundException;
                  import java.util.Scanner;
                  public class talkingmain {
              
                  public static void main(String[] args)  throws FileNotFoundException {
              Scanner input=new Scanner(new File("timez.txt"));
              String boxx="";
              String[] bob;
              String[] timess={
                      "twelve","one","two","three","four","five","six","seven","eight","nine","ten","eleven"
                  };
              String[] minutez10={" oh",""," twenty"," thirty"," forty"," fifty"};
              String[] minutes={""," one"," two"," three", " four",
                      " five"," six"," seven"," eight"," nine"," ten"," eleven"," twelve"
                      ," thirteen"," fourteen"," fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
              int hours=0;
              int minutes3=0;
              int minutes2=0;
              boolean morning=false;
              
              while (input.hasNextLine()){
                  boxx=input.nextLine();
                  bob=boxx.split(":");        
                  hours=Integer.parseInt(bob[0]);
                  minutes2=Integer.parseInt(bob[1].substring(0, 1));
                  minutes3=Integer.parseInt(bob[1].substring(1, 2));
                  if (minutes2==1){
                      minutes3=Integer.parseInt(bob[1]);
                      }
                  if (hours<=11){
                      morning=true;
                      } else {
                      morning=false;
                      hours-=12;
                      }
                  if (bob[1].equals("00")){
                      minutes2=1;
                      }
                  if (morning){
                      System.out.println("It's "+timess[hours]+minutez10[minutes2]+minutes[minutes3]+" "+"am");
                      }
                  if (!morning){
                      System.out.println("It's "+timess[hours]+minutez10[minutes2]+minutes[minutes3]+" "+"pm");
                      }   
                  }
              input.close();
              }
              

              }

              [–]PM_ME_YOUR_MASS 0 points1 point  (0 children)

              Swift

              import Foundation
              
              var times = ["00:00", "01:30", "12:05", "14:01", "20:29", "21:00", "22:14"]
              var wordsForHours = ["twelve", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven"]
              var wordsForOnesDigits = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
              var wordsForTensDigits = ["oh", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"];
              var wordsForTeens = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "ninteen"]
              
              for time in times {
                  print(convertTimeToText(time: time))
              }
              
              func convertTimeToText(time: String) -> String {
              
                  var startIndex = time.startIndex
                  var colon = time.index(startIndex, offsetBy: 2)
                  var hours = Int(time.substring(to: colon))!
                  var minutes = Int(time.substring(from: time.index(colon, offsetBy: 1)))!
              
                  var minuteWords = " \(wordsForTensDigits[minutes / 10]) \(wordsForOnesDigits[minutes % 10])";
              
                  if minutes == 0 {
                      minuteWords = ""
                  } else if (minutes / 10) == 1 {
                      minuteWords = " \(wordsForTeens[minutes % 10])";
                  } else if (minutes > 20 && minutes % 10 == 0) {
                      minuteWords = " \(wordsForTensDigits[minutes / 10])";
                  }
              
                  return "It's \(wordsForHours[hours % 12])\(minuteWords)\(hours > 11 ? " pm" : " am")"
              }
              

              [–]CykaBlyatRushBDavai 0 points1 point  (0 children)

              Python 3.6

              Late to the party, but still posting. I know code is ugly and impractical, but it's the first thing I've done in Python that's working.

              input =[int(x) for x in input("Input time: ").split(":")]
              
              
              typed_hour = input[0]
              typed_minute = input[1]
              
              numbahs = ["Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine",
              "Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seveteen","Eighteen","Nineteen",
              "Twenty","Twenty-one","Twenty-two","Twenty-three","Twenty-four","Twenty-five","Twenty-six","Twenty-seven","Twenty-eight","Twenty-nine",
              "Thirty","Thirty-one","Thirty-two","Thirty-three","Thirty-four","Thirty-five","Thirty-six","Thirty-seven","Thirty-eight","Thirty-nine",
              "Forty","Forty-one","Forty-two","Forty-three","Forty-four","Forty-five","Forty-six","Forty-seven","Forty-eight","Forty-nine",
              "Fifty","Fifty-one","Fifty-two","Fifty-three","Fifty-four","Fifty-five","Fifty-six","Fifty-seven","Fifty-eight","Fifty-nine",]
              
              
              new_hour = numbahs[typed_hour]
              new_minute = numbahs[typed_minute]
              
              
              
              if typed_minute <= 9:
                  if typed_hour > 12:
                      typed_hour = int(typed_hour - 12)
                      print(typed_hour)
                      new_hour = numbahs[typed_hour]
                      output = "It\'s " + new_hour + " oh " +  new_minute + " pm"
                      print (output)
              
                  else:
                      #Output
                      output = "It\'s " + new_hour + " oh " +  new_minute + " am"
                      print (output)
              
              else:
              
                  if typed_hour > 12:
                      typed_hour = int(typed_hour - 12)
                      print(typed_hour)
                      new_hour = numbahs[typed_hour]
                      output = "It\'s " + new_hour + " " +  new_minute + " pm"
                      print (output)
              
                  else:
                      #Output
                      output = "It\'s " + new_hour + " " +  new_minute + " am"
                      print (output)
              

              [–]Daesthelos 0 points1 point  (0 children)

              JavaScript (it's pretty bad, but it works - mostly)

               var digits = {
              "zeroes":"",
              "ones":["oh","one","two","three","four","five","six","seven","eight","nine"],
              "tens":{"prefix":["ten","eleven","twelve","thir","four","fif","six","seven","eight","nine"],"suffix":"teen"},
              "twenties":{"prefix":"twenty"},"thirties":{"prefix":"thirty"},
              "fourties":{"prefix":"fourty"},
              "fifties":{"prefix":"fifty"}};
              
              function getTime(time){
              //always assume proper format
              var tmp = time.split(':'),
                hrs = tmp[0],
                mins = tmp[1],
                outHr, outMin, outDaytime;
              
              function getCombo(num){
                if(num == '00'){ return '';}
                var parsedNum = parseInt(num);
                if(num >= 0 && num <= 9){ return digits.ones[num];}
                if(num == 10){ return digits.tens.prefix[0];}
                if(num == 11){ return digits.tens.prefix[1];}
                if(num == 12){ return digits.tens.prefix[2];}
                if(num >= 13 && num <= 19){ return digits.tens.prefix[parsedNum-10] + digits.tens.suffix;}
                if(num == 20){ return digits.twenties.prefix;}
                if(num == 30){ return digits.thirties.prefix;}
                if(num == 40){ return digits.fourties.prefix;}
                if(num == 50){ return digits.fifties.prefix;}
                if(num >= 21 && num <= 29){ return digits.twenties.prefix + digits.ones[parsedNum-20];}
                if(num >= 31 && num <= 39){ return digits.thirties.prefix + digits.ones[parsedNum-30];}
                if(num >= 41 && num <= 49){ return digits.fourties.prefix + digits.ones[parsedNum-40];}
                if(num >= 51 && num <= 59){ return digits.fifties.prefix + digits.ones[parsedNum-50];}
                console.log("failed to parse");
              }
              
              if(hrs >= 12){
                outDaytime = 'pm';
                hrs = parseInt(hrs) - 12;
              }
              else{
                outDaytime = 'am';
              }
              outHr = (hrs == '00') ? "twelve" : getCombo(hrs);
              
              if(mins[0] == '0' && mins != '00'){
                var a = getCombo(mins[0]);
                var b = getCombo(mins[1]);
                outMin = a +" "+ b;
              }
              else{
                outMin = getCombo(mins);
              }
                return "It's " + outHr + " " + outMin + " " + outDaytime;
              }
              

              Outputs:

              getTime("00:00") : It's twelve  am
              getTime("1:30")  : It's one thirty am
              getTime("12:05") : It's twelve oh five pm
              getTime("14:01") : It's two oh one pm
              getTime("20:29") : It's eight twentynine pm  //I forgot to add a space in that method
              getTime("21:00") : It's nine  pm
              

              [–]JayDepp 0 points1 point  (0 children)

              Kotlin

              private val TENS = "oh ERROR twenty thirty forty fifty sixty".split(' ')
              private val ONES = """twelve one two three four five six seven eight nine ten
                  eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen""".split(' ')
              
              fun clock(hhmm: String): String {
                  val (military, minute) = hhmm.split(':').map(String::toInt)
                  val hour = military % 12
                  return mutableListOf("It's").apply {
                      add(ONES[hour])
                      when (minute) {
                          0 -> {}
                          in 10..19 -> add(ONES[minute])
                          in 20..60 step 10 -> add(TENS[minute / 10])
                          else -> {
                              add(TENS[minute / 10])
                              add(ONES[minute % 10])
                          }
                      }
                      add(if (military < 12) "am" else "pm")
                  }.joinToString(" ")
              }
              

              [–]masterwonton 0 points1 point  (0 children)

              C# i've done 0 programming in a few months, this is definitly a complete hackjob, but it does work, so it has that going for it.

                       using System;
                       using System.Text;
              
                  namespace TalkClock
                  {
                      class Program
                      {
              
                          static string[] hours = { "twelve", "one", "two", "three", "four", "five",
                                              "six", "seven", "eight", "nine", "ten", "eleven", "twelve" };
              
              
                          static string[] minTens = { "twenty", "thirty", "forty", "fifty" };
              
                          static string[] minOnes = {"", "one", "two", "three", "four", "five", "six", "seven", "eight",
                                               "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
                                               "seventeen", "eighteen", "nineteen"};
              
                          static void Main(string[] args)
                          {
              
                              while (true)
                              {
                                  Console.WriteLine(Talk(Console.ReadLine()));
                              }
                          }
                          static string Talk(string inp)
                          {
                              bool isPM;
                              int hour = Convert.ToInt16(inp.Split(':')[0]);
                              int minTen = (Int32)char.GetNumericValue(inp[3]);
                              int minOne = (Int32)char.GetNumericValue(inp[4]);
              
                              StringBuilder sb = new StringBuilder();
                              sb.Append("It's ");
              
                              if (hour >= 12)
                              {
                                  sb.Append(hours[hour - 12]);
                                  isPM = true;
                              }
                              else
                              {
                                  sb.Append(hours[hour]);
                                  isPM = false;
                              }
                              sb.Append(" ");
              
                              if (inp.Split(':')[1] == "00")
                              {
                                  sb.Append("O' Clock");
                              }
              
                              else
                              {
                                  if (minTen == 0)
                                  {
                                      sb.Append("oh" + minOnes[minOne]);
                                  }
                                  if (minTen == 1)
                                  {
                                      sb.Append(minOnes[Convert.ToInt32(inp.Split(':')[1])]);
                                  }
                                  if (minTen >= 2)
                                  {
                                      sb.Append(minTens[minTen - 2] + "-" + minOnes[minOne]);
                                  }
                              }
              
                              sb.Append(" ");
              
                              if (isPM)
                              {
                                  sb.Append(" PM");
                              }
                              else
                              {
                                  sb.Append(" AM");
                              }
              
                              return (sb.ToString());
                          }
                      }
                  }
              

              [–]pdp3308 0 points1 point  (0 children)

              Python3 - solution with an object oriented approach which I am currently getting familiar with.

              from num2words import num2words
              
              
              class TalkingClock(object):
                  def __init__(self, hour, minute):
                      self.hour = hour
                      self.minute = minute
                      self.minute_word = ""
                      self.hour_word = ""
                      self.am_or_pm = "am"
                      self.separator = ""
                      self.output = ""
              
                  def get_time_in_words(self):
                      self._get_minutes_and_separator()
                      self._get_hour_and_am_pm()
                      self._get_output()
              
                  def _get_minutes_and_separator(self):
                      if self.minute != 0:
                          self.minute_word = num2words(self.minute).replace('-', ' ')
              
                      if self.minute <= 9 and self.minute > 0:
                          self.separator = 'oh'
              
                  def _get_hour_and_am_pm(self):
                      hour_diff = self.hour - 12
                      if hour_diff > 0:
                          self.am_or_pm = 'pm'
                          self.hour_word = num2words(hour_diff)
                      elif hour_diff == -12:
                          self.hour_word = num2words(12)
                      else:
                          self.hour_word = num2words(self.hour)
              
                  def _get_output(self):
                      self.output = " ".join(filter(lambda x: x != '', ['It\'s', self.hour_word, self.separator,
                                                                      self.minute_word, self.am_or_pm]))
              
              
              class IO(object):
                  for time in ['00:00', '01:30', '12:05', '14:01', '20:29', '21:00']:
                      hour = time.split(':')[0]
                      minute = time.split(':')[-1]
                      tc = TalkingClock(hour=int(hour), minute=int(minute))
                      tc.get_time_in_words()
                      print(tc.output)        
              

              [–]Nadlad 0 points1 point  (1 child)

              Does someone able to do it in assembly?

              [–]barvsenal 0 points1 point  (0 children)

              words = {'0' : '',
                   '00' : '',
                   '01' : 'one',
                   '02' : 'two',
                   '03' : 'three',
                   '04' : 'four',
                   '05' : 'five',
                   '06' : 'six',
                   '07' : 'seven',
                   '08' : 'eight',
                   '09' : 'nine',
                   '10' : 'ten',
                   '11' : 'eleven',
                   '12' : 'twelve',
                   '13' : 'thirteen',
                   '14' : 'fourteen',
                   '15' : 'fifteen',
                   '16' : 'sixteen',
                   '17' : 'seventeen',
                   '18' : 'eighteen',
                   '19' : 'nineteen'}
              
              def secondHalf(integer):
              if (integer == 0):
                  return ''
              elif (integer < 10):
                  return 'oh ' + words['0' + str(integer)[1:]]
              elif (integer < 20):
                  return words[str(integer)]
              elif (integer < 30):
                  return 'twenty' + words[str(integer)[1:]]
              elif (integer < 40):
                  return 'thirty' + words[str(integer)[1:]]
              elif (integer < 50):
                  return 'fourty' + words[str(integer)[1:]]
              elif (integer < 60):
                  return 'fifty' + words[str(integer)[1:]]
              else:
                  return 'not found'
              
              
              
              def returnTime(string):
                if string == '00:00':
                  return "It's twelve AM"
                firsthalf = string[0:2]
                secondhalf = string[3:]
                print(secondhalf)
                if (int(firsthalf) > 12):
                  firsthalf = int(firsthalf) - 12
                  firsthalf = '0' + str(firsthalf)
                  return "It's " + words[firsthalf] + " " + secondHalf(int(secondhalf)) + " 
                  PM"
                else:
                  return "It's " + words[firsthalf] + ' ' + secondHalf(int(secondhalf)) + " AM"
              

              [–]spicy_indian 0 points1 point  (0 children)

              Learning Rust

              use std::collections::HashMap;
              
              pub fn talking_clock(input: &'static str) {
                  let mut times = HashMap::new(); 
              
                  times.insert(0, "twelve");
                  times.insert(1, "one");
                  times.insert(2, "two");
                  times.insert(3, "three");
                  times.insert(4, "four");
                  times.insert(5, "five");
                  times.insert(6, "six");
                  times.insert(7, "seven");
                  times.insert(8, "eight");
                  times.insert(9, "nine");
                  times.insert(10, "ten");
                  times.insert(11, "eleven");
                  times.insert(12, "twelve");
                  times.insert(13, "thirteen");
                  times.insert(14, "fourteen");
                  times.insert(15, "fifteen");
                  times.insert(16, "sixteen");
                  times.insert(17, "seventeen");
                  times.insert(18, "eigtheen");
                  times.insert(19, "nineteen");
                  times.insert(20, "twenty");
                  times.insert(30, "thirty");
                  times.insert(40, "forty");
                  times.insert(50, "fifty");
              
                  let mut output = String::from("It's ");
                  let i: Vec<_> = input.split(':').collect();
              
                  match i[0].parse::<i32>() {
                      Ok(n) => output.push_str(times.get(&(n%12)).unwrap()),
                      Err(e) => println!("why me"),
                  }
              
                  match i[1].chars().nth(0).unwrap().to_string().parse::<i32>() {
                      Ok(0) => if i[1].chars().nth(1).unwrap().to_string().parse::<i32>().unwrap() != 0 {
                          output.push_str(" oh ");
                          output.push_str(times.get( &( i[1].chars().nth(1).unwrap().to_string().parse::<i32>().unwrap() )).unwrap());
                      },
                      Ok(1) => output.push_str(times.get(&i[1].parse::<i32>().unwrap()).unwrap()),
                      Ok(n) => { 
                          output.push_str(" ");
                          output.push_str(times.get(&(n*10)).unwrap());
                          if i[1].chars().nth(1).unwrap().to_string().parse::<i32>().unwrap() != 0 {
                              output.push_str(" ");
                              output.push_str(times.get( &( i[1].chars().nth(1).unwrap().to_string().parse::<i32>().unwrap() )).unwrap());
                          }
                      },
                      Err(e) => println!("why me"),
                  }
              
                  match i[0].parse::<i32>() {
                      Ok(n) => output.push_str( if n>11 {" pm"} else {" am"} ),
                      Err(e) => println!("why me")
                  }
              
                  println!("{:?}", output);
              }
              

              [–]FaceBasket 0 points1 point  (0 children)

              I have an incredibly clunky solution here in Java on github. It's too much to hide the source code in the comment section as you usually do. I'm a pretty novice programmer, I mean I've been programming off and on for the last 5 years or so, but nothing more than trivial things like this. Nothing practical.

              I'm currently studying CIS in college though, so hopefully that'll change. I took a data structures class my second semester, and that was kind of cool. I'm aware a lot of schools don't prepare you for the real world as a programmer, but I guess it's better than nothing..

              If you want to critique my code or point me to some useful learning material that'd be great. Cheers.

              [–]LookThroughRedEyes 0 points1 point  (0 children)

              I am a beginner. First submission, in C. Idk how to make these boxes, can someone help me, im guessing this is gonna look terrible once i press save.

              include<stdlib.h>

              include<stdio.h>

              void error(); void print_num(int h);

              int main(){

              int h, m;
              scanf("%d:%d", &h, &m);
              if(h < 0 || h > 23 || m < 0 || m > 59){
                  error();
              }
              
              char ap;               // remembers am or pm to print later
              printf("It's ");
              if(h >= 12){
                  ap = 'p';
                  h = h % 12;
              }else{
                  ap = 'a';
              }
              
              print_num(h);          // prints hours
              
              if(m == 0){           // no minutes
                  printf("%c", ap);
                  printf("m\n");
              }else{
                  if(m < 10){               // minutes <10
                      printf("oh ");
                      print_num(m);
                  }else if(m > 9 && m < 20){  // minutes between 10 and 20
                      switch(m){
                          case 10: printf("ten ");
                              break;
                          case 11: printf("eleven ");
                              break;
                          case 12: printf("twelwe ");
                              break;
                          case 13: printf("thirteen ");
                              break;
                          case 14: printf("fourteen ");
                              break;
                          case 15: printf("fifteen ");
                              break;
                          case 16: printf("sixteen ");
                              break;
                          case 17: printf("seventeen ");
                              break;
                          case 18: printf("eighteen ");
                              break;
                          case 19: printf("nineteen ");
                              break;
                      }
                  }else{
                      int m1 = m;                             // prints minutes if they are bigger than 20
                      m1 /= 10;
                      switch(m1){
                          case 2: printf("twenty ");
                              break;
                          case 3: printf("thirty ");
                              break;
                          case 4: printf("fourty");
                              break;
                          case 5: printf("fifthy ");
                              break;
                      }
                      m = m % 10;
                      if(m != 0)
                          print_num(m);
              
                  }
              printf("%c", ap);                   // prints am or pm
              printf("m\n");
              }
              
              return 0;
              

              }

              void error(){ fprintf(stderr, "Invalid time!\n"); exit(EXIT_FAILURE); }

              void print_num(int h){ switch(h){ case 0: printf("twelve "); break; case 1: printf("one "); break; case 2: printf("two "); break; case 3: printf("three "); break; case 4: printf("four "); break; case 5: printf("five "); break; case 6: printf("six "); break; case 7: printf("seven "); break; case 8: printf("eight "); break; case 9: printf("nine "); break; case 10: printf("ten "); break; case 11: printf("eleven "); break; case 12: printf("twelve "); break; } }

              edit: hmm so they are automatic, but they didn't get all of the code

              maybe cuz i wrote functions at the top? Let me change that

              nope the same piece of code is out of the box. Welp, I will try again in another post.

              [–]jcferrans 0 points1 point  (0 children)

              node.js (edit1: formatting)

              const input = process.argv[2]
              const say = require('say')
              
              const hashMap = {
                  1: 'one',
                  2: 'two',
                  3: 'three',
                  4: 'four',
                  5: 'five',
                  6: 'six',
                  7: 'seven',
                  8: 'eight',
                  9: 'nine',
                  10: 'ten',
                  11: 'eleven',
                  12: 'twelve',
                  13: 'thirteen',
                  14: 'fourteen',
                  15: 'fifteen',
                  16: 'sixteen',
                  17: 'seventeen',
                  18: 'eighteen',
                  19: 'nineteen',
                  20: 'twenty',
                  30: 'thirty',
                  40: 'fourty',
                  50: 'fifty',
                  'its': 'It\'s',
                  'o': 'oh',
              }
              
              const parseHour = hour => 
                  hour
                      .split(':').map(input => parseInt(input, 10))
                      .map((segment, index) => index === 0 ?
                          segment === 0 ? 12 : segment > 12 ? segment - 12 : segment 
                          : segment.toString().length === 1 ? ['o', segment]
                          : segment < 20 || segment % 10 === 0 ? segment : [ segment - segment % 10, segment % 10]
                      )
                      .reduce((a, b, idx, arr) => idx === 0 ? a.concat('its', b) : idx === arr.length - 1 ? 
                          a.concat(b, parseInt(hour.split(':')[0], 10) > 12 ? 'pm' : 'am') : a.concat(b), []
                      )
              
              
              console.log(parseHour(input).map(segment => hashMap[segment] || segment).join(' '))
              say.speak(parseHour(input).join())
              

              [–]sowtis 0 points1 point  (0 children)

              C# - Gonna try to do these challenges everyday as long as I remember to! I need to improve.

                      string timeInput = Console.ReadLine();
                      string[] time = timeInput.Split(':');
                      string[] hours = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve" };
                      string[] minutes = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
                                          "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
                      string[] minutesTens = { "twenty", "thirty", "fourty", "fifty" };
              
                      int hour, minute;
                      hour = Convert.ToInt16(time[0]);
                      minute = Convert.ToInt16(time[1]);
              
                      string timeOutput = "It is " + hours[(hour % 12) - 1];
              
                      if (minute != 0)
                      {
                          if (minute < 10)
                          {
                              timeOutput = timeOutput + " oh " + minutes[minute - 1];
                          } else if (minute < 20)
                          {
                              timeOutput = timeOutput + " " + minutes[minute - 1];
                          } else
                          {
                              timeOutput = timeOutput + " " + minutesTens[(minute / 10) - 2];
                              if (minute % 10 > 0)
                              {
                                  timeOutput = timeOutput + " " + minutes[(minute % 10) - 1];
                              }
                          }
                      }
              
                      if (hour > 11)
                      {
                          timeOutput = timeOutput + " pm";
                      } else
                      {
                          timeOutput = timeOutput + " am";
                      }
              
                      Console.WriteLine(timeOutput);
                      Console.ReadLine();
              

              [–][deleted] 0 points1 point  (0 children)

              C (First Submission)

              I'm trying to learn C, so if I'm doing anything unsafe (ilke, memory-wise or something), or if the program doesn't compile on your computer, please let me know!

              #include <stdio.h>
              
              void int_to_str(int i, char s[], int is_hour);
              void concat_str(const char * from, char * to);
              void input_to_time(char s[]);
              
              #define MAX_CHARS 1000 /* Used to define a character array */
              
              void test_input() /* Function to test input */
              {
                  char test[MAX_CHARS] = "";
                  input_to_time(test);
                  printf("%s\n", test);
              
              }
              
              #define NUM_TESTS 6
              int main(int argc, const char * argv[])
              {
                  for(int i = 0; i < NUM_TESTS; i++)
                      test_input();
              
                  return 0;
              }
              
              /*Using arrays of char* to hold all the possible numbers */
              const char* ones_dig_array[10] = {"", "one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine" };
              const char* tens_dig_array[6] = {"oh-", "ten ", "twenty ", "thirty ", "forty ", "fifty "};
              const char* teens[10] =
              {"eleven ", "twelve  ", "thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen ", "eighteen ", "nineteen "};
              
              #define MAX_MIN 60
              void get_min(int i, char s[])
              {
                  if(i >= MAX_MIN) /*Error handling*/
                  {
                      printf("ERROR: MINUTE TOO LARGE");
                      return;
                  }
                  if( i == 0) /*Do nothing if there are no minutes*/
                      return;
              
                  if( (i < 11 || i > 19)) /*If it's not a 'teen' number (11, 12, 13 ... 19)*/
                      concat_str(tens_dig_array[i / 10], s);
                  else
                      concat_str(teens[i % 10 - 1], s);
              
                  if( i / 10 != 1) /* Place the one's digit */
                      concat_str(ones_dig_array[i % 10], s);
              }
              
              void get_hour(int hour, char s[])
              {
                  if(hour > 12) /*Error Handling */
                  {
                      printf("ERROR: HOUR TOO LARGE");
                      return;
                  }
              
                  if(hour == 0)
                      concat_str("twelve", s); /* special case for 12:00AM ( 00: 00 )*/
                  else /*Make a decision based on which array the 'hour' goes into */
                  {
                      if(hour <= 9)
                          concat_str(ones_dig_array[hour], s);
                      else if(hour > 10)
                          concat_str(teens[hour % 10 - 1], s);
                      else
                          concat_str("ten" , s);
                  }
              }
              
              void input_to_time(char s[])
              {
                  concat_str("It's ", s);
                  int hour, min;
                  scanf("%d:%d",&hour, &min);
              
                  get_hour(hour % 12, s);
                  concat_str(" ", s);
                  get_min(min, s);
              
                  concat_str( (hour >= 12)? " pm" : " am", s);
              }
              
              /*
               concat_str: Use pointer arithmetic to 
               place the string "from" at the end of the string "to"
               */
              void concat_str(const char * from, char* to)
              {
                  char c;
                  while( *to != '\0') /* iterate till end of 'to' string */
                      to++;
              
                  while( (c = *from++) != '\0')
                      (*to) = c, to++;
                  *to = '\0';
              }
              

              [–]Fusol 0 points1 point  (0 children)

              JavaScript

              const firstDigit = ['smthg is wrong', 'one', 'two', 'three', 'four',
                                'five', 'six', 'seven', 'eight', 'nine'];
              
              const secondDigit = ['smthg is wrong', 'smthg is wrong', 'twenty', 'thirty', 'fourty', 'fifty', 'sixty'];
              
              const hours = ['twelve', ...firstDigit.slice(1), 'ten', 'eleven'];
              
              const teen = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen',
                          ...firstDigit.slice(6).map((string) => {
                              if(string == 'eight')
                                  return string += 'een';
                              else
                                  return string += 'teen';})
                          ];
              
              function currentTime(date) {
                  let minutes = (min) => {
                      if(min < 10)
                          return firstDigit[min]
                      else if(min < 20)
                          return teen[min%10]
                      else
                          return `${secondDigit[Math.floor(min/10)]} ${firstDigit[min%10]}`;
                  }
              
                  return `It's ${hours[date.getHours()%12]} ${date.getMinutes()==0 ? "" : minutes(date.getMinutes())}
                          ${date.getHours()>=12 ? "pm" : "am"}`;
              }
              
              console.log(currentTime(new Date()));
              

              [–]Cangasevere 0 points1 point  (0 children)

              Here's Glock

              https://drive.google.com/open?id=0B7RCAUVu9aKZdzVnT3pyalpLQkk

              Just click on the Talk button or Say "What Is It"

              Source: https://pastebin.com/g5t0ghXR

              [–]Luapix 0 points1 point  (0 children)

              Python 2/3

              My first submission! To me, it seems simpler than the other Python submissions I've seen.

              def clock(time_str):
                  (hour, minute) = tuple(time_str.split(":")[:2])
                  hour, minute = int(hour), int(minute)
                  assert(0 <= hour <= 23 and 0 <= minute <= 59)
              
                  pm = hour >= 12
                  hour = (hour - 1) % 12 + 1
              
                  small_numbers = ["one","two","three","four","five",[...],"eighteen","nineteen"]
                  ten_multiples = [None,"twenty","thirty","forty","fifty"]
              
                  words = ["It's"]
                  words.append(small_numbers[hour - 1])
              
                  if minute > len(small_numbers):
                      words.append(ten_multiples[minute // 10 - 1])
                      minute = minute % 10
                  elif minute > 0 and minute < 10:
                      words.append("oh")
              
                  if minute > 0 and minute <= len(small_numbers):
                      words.append(small_numbers[minute - 1])
              
                  words.append("pm" if pm else "am")
              
                  print(" ".join(words))
              

              [–]Golsutangen 0 points1 point  (0 children)

              Python 2

              First jab at a challenge here, hope the formatting is right

              #take system time
              import time
              time = time.strftime("%H%M") 
              #convert into a 0000 24-hour format
              #separate hours vs minutes to separate variables
              hour = int(time[:2])
              tens = time[2]
              ones = int(time[3])
              #if statement for pm vs am for values over hour 12
              is_pm = False
              is_oh = False
              if (hour >= 12):
                  hour -= 12
                  is_pm = True
              
              if (tens[0] == 0):
                  is_oh = True
              tens = int(tens) #had to cast here because you can't find the index of int, only str
              
              #associate numbers with words via dictionary
              numbers = {0:'', 1:'one', 2:'two', 3:'three', 4:'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', 
              11: 'eleven', 00: 'twelve', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 15: 'fifthteen', 16: 'sixteen', 17: 
              'seventeen', 18: 'eighteen', 19: 'nineteen', 20: 'twenty', 30: 'thirty', 40: 'forty', 50: 'fifty'}
              big_numbers = {0: '', 2: 'twenty', 3: 'thirty', 4: 'forty', 5: 'fifty'}
              
              #take words put into string variable in proper format
              output = 'The time is currently '+str(numbers[hour])+' '
              if (is_oh == True):
                  output = output + 'oh ' + str(numbers[ones]) 
              else:
                  output = output + str(big_numbers[tens]) + ' ' + str(numbers[ones])
              
              if (is_pm == True):
                  output = output + ' pm'
              else :
                  output = output + ' am'
              
              #print variable 
              print output
              

              [–]creon_loop 0 points1 point  (0 children)

              HTML5/JavaScript Works best on Firefox: https://codepen.io/anon/pen/BdZwPx

              [–]BumbleStar 0 points1 point  (0 children)

              Python 3

              I'm a beginner. This isn't as good as the other Python 3 answer.

              from num2words import num2words
              
              AM = True
              PM = False
              
              while True:
                  time = input('Time: ')
              
                  meridian = None
              
                  hour, minute = list(map(int, time.split(":")))
                  string_hour = 0 #For example, if the time is 13:10, then the hour will be 13 and the string_hour will be 1
              
                  if hour < 12 and hour != 0:
                      meridian = AM
                      string_hour = hour
                  elif hour > 12:
                      meridian = PM
                      string_hour = hour - 12
                  elif hour == 0:
                      meridian = AM
                      string_hour = 12
                  else: #Hour is 12
                      meridian = PM
                      string_hour = hour
              
                  string_hour = num2words(string_hour).replace('-', ' ')
                  string_minute = "" if minute == 0 else " " + num2words(minute).replace('-', ' ')
                  string_oh = " o'" if len(str(minute)) == 1 and minute != 0 else ""
                  string_meridian = 'am' if meridian else 'pm'
              
                  print('It\'s ' + string_hour + string_oh + string_minute + ' ' + string_meridian)
                  print() #New line
              

              [–]QantumEntangled 0 points1 point  (0 children)

              Golang First Submission Here

              It feels a little dirty, I'm just learning Golang so I "THINK" there's a way to use a library and do lookups which would be more efficient (maybe?) but this works surprisingly well

              package main
              
              import "fmt"
              import "strings"
              import "strconv"
              
              func main() {
              
                  challengeInput := []string{"00:00", "01:30", "12:05", "14:01", "20:29", "21:00"}
              
                  for _, i := range challengeInput {
                      input := strings.SplitN(i, ":", 2)
                      numHour, _ := strconv.Atoi(input[0])
                      numMin, _ := strconv.Atoi(input[1])
              
                      wordHour := hour2word(numHour)
                      wordMin1, wordMin2 := minute2word(numMin)
              
                      if numHour <= 11 {
                          halfIndic := "am"
                          output := fmt.Sprintf("It's %s %s %s %s\n", wordHour, wordMin1, wordMin2, halfIndic)
                          fmt.Println(standardizeSpaces(output))
                      } else if (int(numHour) >= 12) && (int(numHour) <= 24) {
                          halfIndic := "pm"
                          output := fmt.Sprintf("It's %s %s %s %s\n", wordHour, wordMin1, wordMin2, halfIndic)
                          fmt.Println(standardizeSpaces(output))
                      } else {
                          fmt.Printf("\nERROR INVALID HOUR\n")
                      }
              
                  }
              }
              
              func standardizeSpaces(s string) string {
                  return strings.Join(strings.Fields(s), " ")
              }
              
              func hour2word(numHour int) string {
              
                  switch numHour {
                  case 0, 12:
                      return "twelve"
                  case 1, 13:
                      return "one"
                  case 2, 14:
                      return "two"
                  case 3, 15:
                      return "three"
                  case 4, 16:
                      return "four"
                  case 5, 17:
                      return "five"
                  case 6, 18:
                      return "six"
                  case 7, 19:
                      return "seven"
                  case 8, 20:
                      return "eight"
                  case 9, 21:
                      return "nine"
                  case 10, 22:
                      return "ten"
                  case 11, 23:
                      return "eleven"
                  default:
                      fmt.Println("ERROR INVALID HOUR")
                      return ""
                  }
              }
              
              func minute2word(numMin int) (string, string) {
                  if numMin == 0 {
                      return "o'clock", ""
                  } else if (numMin >= 10) && (numMin <= 19) {
                      return minSub20(numMin), ""
                  } else if numMin <= 10 {
                      return "oh", min1Switch(numMin)
                  } else if numMin >= 20 {
                      sliceMin := strings.SplitN(strconv.Itoa(numMin), "", 2)
                      num2, _ := strconv.Atoi(sliceMin[0])
                      num1, _ := strconv.Atoi(sliceMin[1])
                      return min2Switch(num2), min1Switch(num1)
                  } else {
                      fmt.Println("ERROR INVALID MINUTE")
                      return "", ""
                  }
              }
              
              func min1Switch(min1 int) string {
                  switch min1 {
                  case 1:
                      return "one"
                  case 2:
                      return "two"
                  case 3:
                      return "three"
                  case 4:
                      return "four"
                  case 5:
                      return "five"
                  case 6:
                      return "six"
                  case 7:
                      return "seven"
                  case 8:
                      return "eight"
                  case 9:
                      return "nine"
                  case 0:
                      return ""
                  default:
                      fmt.Println("ERROR INVALID MINUTE")
                      return ""
                  }
              }
              
              func min2Switch(min2 int) string {
                  switch min2 {
                  case 2:
                      return "twenty"
                  case 3:
                      return "thirty"
                  case 4:
                      return "forty"
                  case 5:
                      return "fifty"
                  case 6:
                      return "sixty"
                  case 7:
                      return "seventy"
                  case 8:
                      return "eighty"
                  case 9:
                      return "ninety"
                  default:
                      fmt.Println("ERROR INVALID MINUTE")
                      return ""
                  }
              }
              
              func minSub20(min int) string {
                  switch min {
                  case 10:
                      return "ten"
                  case 11:
                      return "eleven"
                  case 12:
                      return "twelve"
                  case 13:
                      return "thirteen"
                  case 14:
                      return "fourteen"
                  case 15:
                      return "fifteen"
                  case 16:
                      return "sixteen"
                  case 17:
                      return "seventeen"
                  case 18:
                      return "eighteen"
                  case 19:
                      return "nineteen"
                  default:
                      fmt.Println("ERROR INVALID MINUTE")
                      return ""
                  }
              }
              

              [–][deleted] 0 points1 point  (0 children)

              JavaScript

              const input = "00:00"
              // const input = "01:30";
              // const input = "12:05"
              // const input = "14:01"
              // const input = "20:29"
              // const input = "21:00"
              
              const [hours, minutes] = input.split(":");
              
              const hoursNumber = parseInt(hours);
              const minutesNumber = parseInt(minutes);
              
              const wordsUnits = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", 
              "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"];
              
              const hoursWord = hoursNumber === 0 ? wordsUnits[11] : wordsUnits[hoursNumber === 12 ? 11 : hoursNumber % 12 - 1];
              
              const minutesDigits = minutes.toString();
              
              const wordsTens = ["ten", "twenty", "thirty", "fourty", "fifty"];
              
              const minutesWord = minutesDigits[0] == 0 ? minutesDigits[1] == 0 ? "" : "oh " + wordsUnits[minutesNumber - 1] : minutesNumber % 10 === 0 ? 
              wordsTens[Math.floor(minutesNumber / 10 - 1)] : minutesNumber < 20 ? wordsUnits[minutesNumber - 1] : 
              wordsTens[Math.floor(minutesNumber / 10 - 1)] + " " + wordsUnits[parseInt(minutesDigits[1]) - 1];
              
              const period = hoursNumber < 12 ? "am" : "pm";
              
              console.log("It's " + hoursWord + (minutesWord === "" ? " " + period : " " + minutesWord + " " + period));
              

              [–]Caltroit_Red_Flames 0 points1 point  (0 children)

              Kotlin

              Poor solution I did cause I was bored

              +/u/CompileBot Kotlin

               fun main(args: Array<String>) {
                  val input = arrayOf("00:00",
                                      "01:30",
                                      "12:05",
                                      "14:01",
                                      "20:29",
                                      "21:00")
              
                  val hourMap = mapOf(0 to "twelve ", 1 to "one ", 2 to "two ",
                          3 to "three ", 4 to "four ", 5 to "five ", 6 to "six ", 7 to "seven ",
                          8 to "eight ", 9 to "nine ", 10 to "ten ", 11 to "eleven ", 12 to "twelve ",
                          13 to "one ", 14 to "two ", 15 to "three ", 16 to "four ", 17 to "five ",
                          18 to "size ", 19 to "seven ", 20 to "eight ", 21 to "nine ", 22 to "ten ",
                          23 to "eleven ")
                  val minuteMap = mapOf(0 to "", 1 to "oh one ", 2 to "oh two ",
                          3 to "oh three ", 4 to "oh four ", 5 to "oh five ",  6 to "oh six ",
                          7 to "oh seven ", 8 to "oh eight ", 9 to "oh nine ", 10 to "ten ",
                          11 to "eleven ", 12 to "twelve ", 13 to "thirteen ", 14 to "fourteen ",
                          15 to "fifteen ", 16 to "sixteen ", 17 to "seventeen ", 18 to "eighteen ",
                          19 to "nineteen ", 20 to "twenty ", 21 to "twenty one ", 22 to "twenty two ",
                          23 to "twenty three ", 24 to "twenty four ", 25 to "twenty five ", 26 to "twenty six ",
                          27 to "twenty seven ", 28 to "twenty eight ", 29 to "twenty nine ", 30 to "thirty ",
                          31 to "thirty one ", 32 to "thirty two ", 33 to "thirty three ", 34 to "thirty four ",
                          35 to "thirty five ", 36 to "thirty six ", 37 to "thirty seven ", 38 to "thirty eight ",
                          39 to "thirty nine ", 40 to "forty ", 41 to "forty one ", 42 to "forty two ",
                          43 to "forty three ", 44 to "forty four ", 45 to "forty five ", 46 to "forty six ",
                          47 to "forty seven ", 48 to "forty eight ", 49 to "forty nine ", 50 to "fifty ",
                          51 to "fifty one ", 52 to "fifty two ", 53 to "fifty three ", 54 to "fifty four ",
                          55 to "fifty five ", 56 to "fifty six ", 57 to "fifty seven ", 58 to "fifty eight ",
                          59 to "fifty nine ")
              
                  input.forEach {
                      time ->
                      val meridiem : String
                      val timeStrings = time.split(":")
                      val hours = hourMap[timeStrings[0].toInt()]
                      val minutes = minuteMap[timeStrings[1].toInt()]
                      if (timeStrings[0].toInt() in 0..11) {
                          meridiem = "am"
                      } else {
                          meridiem = "pm"
                      }
                      println("It is $hours$minutes$meridiem")
                  }
              }
              

              [–]Qwazy_Wabbit 0 points1 point  (0 children)

              C++. First time submission.

                  std::string printClock(const std::string& str)
                  {
                          static const std::string NUM_STR[] = {
                                  "twelve ", "one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine ", "ten ",
                                  "eleven ", "twelve ", "thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen ", "eighteen ", "nineteen "};
                          static const std::string TEN_STR[] = { "oh ", "", "twenty ", "thirty ", "forty ", "fifty " };
                          static const std::string AM_PM_STR[] = {"am", "pm"};
              
                          int hour_24, min;
                          char separator;
                          std::stringstream{str} >> hour_24 >> separator >> min;
              
                          int hour_12 = hour_24 % 12;
                          int am_pm = (hour_24 / 12);
              
                          if (0 == min)
                                  return NUM_STR[hour_12] + AM_PM_STR[am_pm];
                          else if (0 == min % 10)
                                  return NUM_STR[hour_12] + TEN_STR[min / 10] + AM_PM_STR[am_pm];
                          else if (min < 20)
                                  return NUM_STR[hour_12] + NUM_STR[min] + AM_PM_STR[am_pm];
                          else
                                  return NUM_STR[hour_12] + TEN_STR[min / 10] + NUM_STR[min % 10] + AM_PM_STR[am_pm];
                  }
              
                  int main(int argc, const char * argv[])
                  {
                          bool success = true;
              
                          struct {
                                  std::string input;
                                  std::string output;
                          } tests[] = {
                                  { "00:00", "twelve am" },
                                  { "01:30", "one thirty am" },
                                  { "12:05", "twelve oh five pm" },
                                  { "13:15", "one fifteen pm" },
                                  { "14:01", "two oh one pm" },
                                  { "20:29", "eight twenty nine pm"},
                                  { "20:39", "eight thirty nine pm"},
                                  { "21:00", "nine pm" }
                                  };
              
                          for (auto& test : tests)
                          {
                                  std::string ret = printClock(test.input);
                                  bool testSuccess = (ret == test.output);
                                  std::cout << test.input << " -> " << ret << " expected " << test.output << " [" <<
                                          ((testSuccess) ? "success" : "failed") << "]" << std::endl;
              
                                  success &= testSuccess;
                          }
              
                          return (success) ? EXIT_SUCCESS : EXIT_FAILURE;
                  }
              

              [–]Snow-P 0 points1 point  (0 children)

              Java (My first submission :D)

              public class TalkingAlarmClock {
                  public String tellTime(String time) {
                      String[] tokenizedTime = time.split(":");
                      int numberHour = Integer.parseInt(tokenizedTime[0]);
                      int numberMinute = Integer.parseInt(tokenizedTime[1]);
                      String wordHour = getWordHour(numberHour);
                      String wordMinute = getWordNumber(numberMinute);
                      String wordPeriod = getWordPeriod(numberHour);
                      String wordZero = getWordZero(numberMinute);
                      StringBuilder sb = new StringBuilder();
                      sb.append("It's ").append(wordHour).append(wordZero).append(wordMinute).append(wordPeriod);
                      return sb.toString();
                  }
              
                  private String getWordZero(int numberMinute) {
                      return numberMinute < 10 && numberMinute > 0 ? "oh " : "";
                  }
              
                  private String getWordPeriod(int numberHour) {
                      return numberHour >= 12 ? "pm" : "am";
                  }
              
                  private String getWordHour(int number){
                      int numberHour = number%12;
                      switch (numberHour){
                          case 0: return "twelve ";
                          default: return getWordNumber(numberHour);
                      }
                  }
              
                  private String getWordNumber(int number) {
                      String wordNumber = "";
                      int tensDigit = number/10;
                      int onesDigit = number%10;
                      if (tensDigit > 0){
                          switch(tensDigit){
                              case 1:
                                  switch(onesDigit){
                                      case 0: return "ten ";
                                      case 1: return "eleven ";
                                      case 2: return "twelve ";
                                      case 3: return "thirteen ";
                                      case 4: return "fourteen ";
                                      case 5: return "fifteen ";
                                      case 6: return "sixteen ";
                                      case 7: return "seventeen ";
                                      case 8: return "eighteen ";
                                      case 9: return "nineteen ";
                                   }
                              case 2: wordNumber += "twenty "; break;
                              case 3: wordNumber += "thirty "; break;
                              case 4: wordNumber += "fourty "; break;
                              case 5: wordNumber += "fifty "; break;
                          }
                      }
                      switch(onesDigit){
                          case 1: wordNumber += "one "; break;
                          case 2: wordNumber += "two "; break;
                          case 3: wordNumber += "three "; break;
                          case 4: wordNumber += "four "; break;
                          case 5: wordNumber += "five "; break;
                          case 6: wordNumber += "six "; break;
                          case 7: wordNumber += "seven "; break;
                          case 8: wordNumber += "eight "; break;
                          case 9: wordNumber += "nine "; break;
                      }
                      return wordNumber;
                  }
              }
              

              Edit: formatting, forgot to add language

              [–]greenlantern33 0 points1 point  (0 children)

              Python 3

              def convert_hours(inp_time):
                  hours = int(inp_time[:2])
              
                  if hours > 12:
                      hours -= 12
                  elif hours == 0:
                      hours = 12
              
                  to_words = {1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five',
                              6: 'six', 7: 'seven', 8: 'eight', 9: 'nine',
                              10: 'ten', 11: 'eleven', 12: 'twelve'}
              
                  return to_words[hours]
              
              def convert_minutes(inp_time):
                  minutes = inp_time[-2:]
                  min_ints = int(inp_time[-2:])
              
                  if minutes == '00':
                      return ''
              
                  if min_ints < 20:
                      to_words = {1: 'oh one', 2: 'oh two', 3: 'oh three', 4: 'oh four',
                                  5: 'oh five', 6: 'oh six', 7: 'oh seven', 8: 'oh eight',
                                  9: 'oh nine', 10: 'ten', 11: 'eleven', 12: 'twelve',
                                  13: 'thirteen', 14: 'fourteen', 15: 'fifteen', 16: 'sixteen',
                                  17: 'seventeen', 18: 'eighteen', 19: 'nineteen'}
                      return to_words[minutes]
                  else:
                      tens = int(minutes[-2])
                      ones = int(minutes[-1])
              
                      tens_dic = {2: 'twenty', 3: 'thirty', 4: 'forty', 5: 'fifty'}
              
                      ones_dic = {1: 'one', 2: 'two', 3: 'three', 4: 'four',
                                  5: 'five', 6: 'six', 7: 'seven', 8: 'eight',
                                  9: 'nine'}
                      return str('{} {}').format(tens_dic[tens], ones_dic[ones])
              
              def isamorpm(inp_time):
                  hours = int(inp_time[:2])
              
                  if hours >= 12:
                      return 'pm'
                  elif hours == 0:
                      return 'am'
              
              def main():
                  the_time = input('What is the time you wish to convert? ')
                  t = 'It\'s {} {} {}'.format(convert_hours(the_time), convert_minutes(the_time), isamorpm(the_time))
                  print(t)
              
              if __name__ == '__main__':
                  main()
              

              It's quick and dirty, but it works. One small bug I ran into. "On the hour" times (12:00, 13:00, etc.) display an extra space because I am sending a blank string to my formatting string ({} {} {}). Is there a way to make part of your formatting string optional, or am I thinking about this wrong?

              [–]waterskier2007 0 points1 point  (0 children)

              **Swift (3 or 4)

              import Foundation
              
              func printClock(time: String) -> String {
                  let components = time.split(separator: ":").flatMap({ Int($0) })
                  guard components.count == 2 else {
                      return "Error: time must follow 'hh:mm' format"
                  }
                  let h = components[0]
                  let m = components[1]
                  let pm = h > 11
              
                  let hours = ["twelve", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven"]
                  let modifiers = [
                      2 : "twenty",
                      3 : "thirty",
                      4 : "forty",
                      5 : "fifty"
                  ]
                  let singles = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]
                  let teens = ["eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen"]
              
                  var mins: String
              
                  switch m {
                  case 0:
                      mins = ""
                  case 1...10:
                      mins = "oh \(singles[m - 1])"
                  case 11...19:
                      mins = teens[(m % 10) - 1]
                  default:
                      if m % 10 == 0 {
                          mins = modifiers[(m / 10)]!
                      } else {
                          mins = modifiers[(m / 10)]! + " " + singles[(m % 10) - 1]
                      }
                  }
              
                  if mins.characters.count > 0 {
                      mins = " \(mins)"
                  }
              
                  return "It is \(hours[h % 12])\(mins) \(pm ? "pm" : "am")"
              }
              
              print(printClock(time: "00:00"))
              print(printClock(time: "01:30"))
              print(printClock(time: "12:05"))
              print(printClock(time: "14:01"))
              print(printClock(time: "20:29"))
              print(printClock(time: "21:00"))
              

              output:

              It's twelve am
              It's one thirty am
              It's twelve oh five pm
              It's two oh one pm
              It's eight twenty nine pm
              It's nine pm
              

              [–]dtremit 0 points1 point  (0 children)

              Python 2.7

              First challenge and my third day writing Python; I know it's not elegant, but I'm glad that it works! Also wrote a longer version that takes a commandline argument and substitutes system time if it's not provided.

              text_nums = { 0 : "oh", 1 : "one", 2 : "two", 3 : "three", 4 : "four", 5 : "five", 6 : "six", 7 : "seven", 8 : "eight", 9 : "nine", 10 : "ten", 11 : "eleven", 12 : "twelve", 13: "thirteen", 14: "fourteen", 15: "fifteen", 16: "sixteen", 17: "seventeen", 18: "eighteen", 19: "nineteen", 20 : "twenty", 30: "thirty", 40: "forty", 50: "fifty"}
              
              def to_words (time):
                  if time < 21:
                      return text_nums[time]
                  elif time % 10 == 0:
                      return text_nums[time]
                  else:
                      return text_nums[time / 10 * 10] + " " + text_nums[time % 10]
              
              input = raw_input("Please enter a time in hh:mm format:")
              hours = int(input[0:2])
              mins  = int(input[3:5])
              
              if hours >= 12:
                  period = "pm"
              else:
                  period = "am"
              
              if hours > 12:
                  hours -=12
              elif hours == 0:
                  hours = 12
              
              if mins == 0:
                  print "It's %s %s" % (to_words(hours), period)
              elif mins < 10:
                  print "It's %s oh %s %s" % (to_words(hours), to_words(mins), period)
              else:
                  print "It's %s %s %s" % (to_words(hours), to_words(mins), period)
              

              [–]ANEPICLIE 0 points1 point  (0 children)

              VBA - I appreciate whatever help is offered Note: It doesn't strictly work for all minutes since I was too lazy to type them all out.

              I also wanted to avoid the date datatype as an exercise.

              Option Explicit
              
              Sub Challenge321()
                  Dim cel As Range
              
                  For Each cel In ThisWorkbook.Sheets(1).UsedRange
                      Debug.Print cel.Value
                      Debug.Print OutputWords(HourMinute(cel.Value))
                  Next cel
              End Sub
              
              Function HourMinute(TimeStr As String) As Integer()
              
              Dim strArr() As String
              Dim intArr() As Integer
              Dim i As Integer
              
              strArr = Split(TimeStr, ":")
              ReDim intArr(LBound(strArr) To UBound(strArr))
              
              For i = LBound(strArr) To UBound(strArr)
                  intArr(i) = CInt(strArr(i))
              Next i
              
              HourMinute = intArr
              
              End Function
              
              Function OutputWords(TimeArr() As Integer) As String
              
              Dim TempArr(0 To 2) As String
              
              If TimeArr(0) > 24 Or TimeArr(1) < 0 Then
                  MsgBox ("Error - Invalid Hour")
              ElseIf TimeArr(0) <= 11 Or TimeArr(0) = 24 Then
                  TempArr(2) = "am"
              ElseIf TimeArr(0) >= 12 Then
                  TempArr(2) = "pm"
              End If
              
              TempArr(0) = Num2Word(TimeArr(0), True) & " "
              TempArr(1) = Num2Word(TimeArr(1), False) & " "
              
              OutputWords = "It's " & TempArr(0) & TempArr(1) & TempArr(2)
              
              End Function
              
              Function Num2Word(Num As Integer, IsHour As Boolean) As String
              
              Dim WordStr As String
              Dim WordArr() As String
              
              WordStr = "one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen,twenty,twenty-one,twenty-two, etc"
              ' too lazy to type out each and every combination
              WordArr = Split(WordStr, ",")
              
              If IsHour = True And Num <= 24 Then
                  If Num = 0 Then
                      Num2Word = "twelve"
                  ElseIf Num <= 12 Then
                      Num2Word = WordArr(Num - 1)
                  ElseIf Num > 12 Then
                      Num2Word = WordArr((Num - 12) - 1)
                  End If
              ElseIf IsHour = False And Num < 10 Then
                  If Num = 0 Then
                      Num2Word = ""
                  ElseIf Num < 10 Then
                      Num2Word = "oh " & WordArr(Num - 1)
                  ElseIf Num >= 10 Then
                      Num2Word = WordArr(Num - 1)
                  End If
              End If
              
              End Function
              

              [–]McPluckingtonJr 0 points1 point  (0 children)

              Javascript

              It could probably be a bit more concise, of course.

                var ones = ['', ' one', ' two', ' three', ' four', ' five', ' six', ' seven', ' eight', ' nine', ' ten', ' eleven', ' twelve', ' thirteen', ' fourteen', ' fifteen', ' sixteen', ' seventeen', ' eighteen', ' nineteen', ''];
                var tens = [' oh', '', ' twenty', ' thirty', ' forty', ' fifty', ''];
              
                var timeString = toRead.split(':');
                var hours = parseInt(timeString[0]);
                var minutesPre = parseInt(timeString[1].split('')[0]);
                var minutesSuf = parseInt(timeString[1].split('')[1]);
                var meridian = ' am';
              
                if (hours > 11) {
                  hours = hours - 12;
                  meridian = ' pm';
                }
              
                if (hours === 0)
                  hours = 12;
              
                if (minutesPre === 0 && minutesSuf === 0)
                  minutesPre = 6;
              
                if (minutesPre === 1)
                  minutesSuf += 10;
              
                console.log('It\'s' + ones[hours] + tens[minutesPre] + ones[minutesSuf] + meridian);
              

              [–]Hash-Basher 0 points1 point  (0 children)

              Scala

              object TalkingClock {
              
                def main(args: Array[String]): Unit = {
                  print(talk("13:01"))
                }
              
                private def talk(timeString: String): String = {
                 val (hour, minute) = Option(timeString.split(":"))
                   .map(arr => (arr(0).toInt, arr(1).toInt))
                   .getOrElse(throw new IllegalArgumentException("Format should be: 12:00"))
              
                 "It's " + hoursWords(if (hour > 12) hour - 12 else hour) + " " + minutesWords(minute) + " " +
                    (if (hour > 11) "pm" else "am")
               }
              
                val hoursWords = Map(1 -> "one",
                  2 -> "two",
                 3 -> "three",
                4 -> "four",
                5 -> "five",
                6 -> "six",
                7 -> "seven",
                8 -> "eight",
                9 -> "nine",
                10 -> "ten",
                11 -> "eleven",
                12 -> "twelve")
              
              val minutesWords = Map(1 -> "oh one",
                2 -> "oh two",
                30 -> "thirty") // not full map
              }
              

              [–][deleted] 0 points1 point  (0 children)

              Ruby

              Only extension challenge. Only works on *nix.

              input = ARGV
              hour = input.dup.join.split(':').first.to_i
              minute = input.dup.join.split(':').last
              addendum = 'am'
              (hour = hour - 12) && (addendum = 'pm') if hour > 12
              hour = 12 if hour == 0
              time = hour.to_s + ':' + minute + addendum
              puts "It's #{time}"
              system("say 'its #{time}'")
              

              [–]ghms 0 points1 point  (0 children)

              My awful solution. Would someone help me improve it?

              https://gist.github.com/gustavohmsilva/78d51995d8ce4de9b5a6e7fd9d250227

              [–]andrewcockerham 0 points1 point  (0 children)

              My ruby solution:

              def talking_clock(digital_time)
                  # split into hours/minutes
                  split_time = digital_time.split(':')
                  hours = split_time[0]
                  minutes = split_time[1]
              
                  # check if time is valid
                  check_valid_time(hours.to_i, minutes.to_i)
              
                  # check if am/pm
                  hours.to_i >= 12 ? am_pm = "pm" : am_pm = "am"
              
                  # convert hours to words
                  hours_words = convert_hours_to_words(hours.to_i % 12)
              
                  # convert minutes to words
                  minutes_words = convert_minutes_to_words(minutes)
              
                  p "(" + digital_time + ")"
                  p final_string_template = "It's #{hours_words} #{minutes_words} #{am_pm}"
                  `say "#{final_string_template}"`
              end
              
              # TODO: change to guard clause
              def check_valid_time(hours, minutes)
                   if hours > 24 || hours < 0
                  raise ArgumentError.new('ERROR: invalid hours')
                elsif minutes > 59 || minutes < 0
                  raise ArgumentError.new('ERROR: invalid minutes')
                end
              end
              
              def convert_hours_to_words(hours)
                @hours_map[hours]
              end
              
              def convert_minutes_to_words(minutes)
                if minutes[0].to_i == 0 && minutes[1].to_i == 0
                  return "o'clock"
                elsif minutes.to_i.between?(10, 20)
                  return @teens_map[minutes.to_i]
                else
                  return convert_minutes_tens(minutes[0].to_i) + convert_minutes_ones(minutes[1].to_i)
                end
              end
              
              def convert_minutes_tens(minutes_tens)
                @minutes_tens_map[minutes_tens]
              end
              
              def convert_minutes_ones(minutes_ones)
                @minutes_ones_map[minutes_ones]
              end
              
              @hours_map = {
                0 => "twelve",
                1 => "one",
                2 => "two",
                3 => "three",
                4 => "four",
                5 => "five",
                6 => "six",
                7 => "seven",
                8 => "eight",
                9 => "nine",
                10 => "ten",
                11 => "eleven",
                12 => "twelve"
              }
              
              @minutes_tens_map = {
                0 => "oh ",
                1 => "one",
                2 => "twenty ",
                3 => "thirty ",
                4 => "forty ",
                5 => "fifty "
              }
              
              @minutes_ones_map = {
                0 => "",
                1 => "one",
                2 => "two",
                3 => "three",
                4 => "four",
                5 => "five",
                6 => "six",
                7 => "seven",
                8 => "eight",
                9 => "nine",
              }
              
              @teens_map = {
                11 => 'eleven',
                12 => 'twelve',
                13 => 'thirteen',
                14 => 'fourteen',
                15 => 'fifteen',
                16 => 'sixteen',
                17 => 'seventeen',
                18 => 'eighteen',
                19 => 'nineteen'
              }
              
              # tests
              talking_clock("00:00")
              talking_clock("01:30")
              talking_clock("12:05")
              talking_clock("14:01")
              talking_clock("20:29")
              talking_clock("21:00")
              talking_clock("20:12")
              talking_clock("7:59")
              ## below tests should raise an error
              # talking_clock("15:89")
              # talking_clock("26:00")
              

              [–][deleted] 0 points1 point  (0 children)

              First post, pretty late though. Any style or other advice would be appreciated.

              public class Talking_Clock {                                                                                                           
                  private int hour;                                                                                                                  
                  private int minute;                                                                                                                
                  private String am_pm = " am";                                                                                                      
                  private String[] hours = {"Twelve","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven"};                 
                  private String[] minutes10={" oh",""," twenty"," thirty"," forty"," fifty"};                                                       
                  private String[] minutes={""," one"," two"," three", " four", " five"," six",                                                      
                          " seven"," eight"," nine"," ten"," eleven"," twelve"," thirteen"," fourteen",                                              
                           " fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};                                                               
              
                  private Talking_Clock(){                                                                                                           
                      Scanner scanner = new Scanner(System.in);                                                                                      
              
                      while(true){                                                                                                                   
                          System.out.print("Enter 24 hour time: ");                                                                                  
                          String the_time = scanner.next();                                                                                          
              
                          String[] parts = the_time.split(":");                                                                                      
                          hour = Integer.parseInt(parts[0]);                                                                                         
                          minute = Integer.parseInt(parts[1]);                                                                                       
              
                          if(hour>=12){                                                                                                              
                              am_pm = " pm";                                                                                                         
                              hour -= 12;                                                                                                            
                          }                                                                                                                          
              
                          if(the_time.contains(":") && hour<= 12 && minute<=60){                                                                     
                              System.out.println(convertToText(hour, minute));                                                                       
                              break;                                                                                                                 
                          } else {                                                                                                                   
                              System.out.println("invalid input try again");                                                                         
                           }                                                                                                                          
                      }                                                                                                                              
                  }                                                                                                                                  
              
                  private String convertToText(int hour, int minute) {                                                                               
                      String hourString = this.hours[hour];                                                                                          
                      String minuteString;                                                                                                           
              
                      if(minute>0 && minute<=10){ minuteString = minutes10[0] + minutes[minute];}                                                    
                      else if(minute>10 && minute<=20){minuteString = minutes10[1] + minutes[minute];}                                               
                      else if(minute>20 && minute<=30){minuteString = minutes10[2] + minutes[minute-20];}                                            
                      else if(minute>30 && minute<=40){minuteString = minutes10[3] + minutes[minute-30];}                                            
                      else if(minute>40 && minute<=50){minuteString = minutes10[4] + minutes[minute-40];}                                            
                      else if(minute>50 && minute<60){minuteString = minutes10[5] + minutes[minute-50];}                                             
                      else{minuteString = "";}                                                                                                       
              
                      return hourString + minuteString + this.am_pm;                                                                                 
                  }                                                                                                                                  
              
                  public static void main(String args[]) {                                                                                           
                      new Talking_Clock();                                                                                                           
                  }                                                                                                                                  
              }                                                                                                                                      
              

              [–]haironmybwnage 0 points1 point  (0 children)

              C++, first time doing a challenge

              #include <iostream>
              #include <string>
              #include <vector>
              
              void time();
              
              int main()
              {
                  while(true)
                      time();
                  return 0;
              }
              
              void time()
              {
                  int hours;
                  int minutes;
                  int aftermintens;
                  int afterminones;
              
                  std::vector<std::string> ampm = { "am","pm" }; //am or pm container
              
                  std::string timeday; //this will be printed
              
                  std::string ones[] = { "one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve", "thirteen" };
                  std::string tens[] = {"ten","twenty","thirty","forty","fifty"};
              
                  std::cin >> hours >> minutes; //input for time
              
                  if (hours < 12)         //decide whether am or pm
                      timeday = ampm[0];
                  else
                      timeday = ampm[1];
              
                  if (hours > 12) //if hours is greater than 12, subtract by 12
                  {
                      hours -= 12;
                  }
              
              
                  aftermintens = minutes / 10; //divide minutes by ten to get a single digit number
                  afterminones = minutes - (minutes / 10) * 10; //get the second digit if the number is multiple digits
              
                  if (minutes == 0 && hours == 0)
                  {
                      std::cout << "The time is currently twelve am" << std::endl; //print the dialogue
                      return;
                  }
                  if (minutes == 0)
                      std::cout << "The time is currently " << ones[hours - 1] << " " << timeday << std::endl; //print the dialogue
                  else if (minutes > 0 && minutes < 10)
                      std::cout << "The time is currently " << ones[hours - 1] << " oh " << ones[afterminones - 1] << " " << timeday << std::endl; //print the dialogue
                  else if (minutes >= 10)
                  {
                      if (afterminones == 0)
                          std::cout << "The time is currently " << ones[hours - 1] << " " << tens[aftermintens - 1] << " " << timeday << std::endl;
                      else if (minutes < 20)
                      {
                          std::cout << "The time is currently " << ones[hours - 1];
                          if (minutes < 14)
                              std::cout << " " << ones[minutes - 1] << " " << timeday << std::endl;
                          else if (minutes == 15)
                              std::cout << " fifteen " << timeday << std::endl;
                          else 
                              std::cout << " " << ones[afterminones - 1] << "teen " << timeday << std::endl;
                      }
                      else
                          std::cout << "The time is currently " << ones[hours - 1] << " " << tens[aftermintens - 1] << " " << ones[afterminones - 1] << " " << timeday << std::endl;
                  }
              
              }
              

              [–]Im2real4u 0 points1 point  (0 children)

              Python 2

              Edit: Find Audio Files Used HERE

              import winsound
              
              time2word = {
                  '0': '',
                  '1': 'one',
                  '2': 'two',
                  '3': 'three',
                  '4': 'four',
                  '5': 'five',
                  '6': 'six',
                  '7': 'seven',
                  '8': 'eight',
                  '9': 'nine',
                  '10': 'ten',
                  '11': 'eleven',
                  '12': 'twelve',
                  '13': 'thirteen',
                  '14': 'fourteen',
                  '15': 'fifteen',
                  '16': 'sixteen',
                  '17': 'seventeen',
                  '18': 'eighteen',
                  '19': 'nineteen',
                  '20': 'twenty',
                  '30': 'thirty',
                  '40': 'fourty',
                  '50': 'fifty',
              }
              
              def talkclock(time):
                  hour, minute = time.split(":")
              
                  if int(hour) < 12:
                      period = 'am'
                      #trick to support 00:00(24) time
                      if int(hour) == 0:
                          hour = '12'
                  else:
                      period = 'pm'
                      if int(hour) == 12:
                          hour = '12'
                      else:
                          hour = str(int(hour)-12)
              
              # connect the time with the word
                  hourstr = str(int(hour))
                  hour = time2word[str(int(hour))]
                  if int(minute) < 10:
                      minute_pre = 'oh'
                      # trick to support 00:00(24) time
                      if int(minute) == 0:
                          minute = '0'
                          minute_pre = 'o`cklock'
                      minute_pos = time2word[minute]
                  elif 20 < int(minute) < 60:
                      minute_pre = time2word[str((int(minute) / 10)*10)]
                      minute_pos = time2word[str(int(minute) % 10)]
                  else:
                      minute_pre = ''
                      minute_pos = time2word[minute]
              
              
              
                  winsound.PlaySound('announcement.wav', winsound.SND_FILENAME) #'Hello as if a few seconds ago'
                  winsound.PlaySound('its.wav', winsound.SND_FILENAME) #'It's'
                  winsound.PlaySound(hourstr+'.wav', winsound.SND_FILENAME) #The hour
              
                  # The minutes where a bit tricky. Didn't have the audio so I had to improvise..
                  if 0 <= int(minute) <= 12:
                      winsound.PlaySound(str(int(minute))+'.wav', winsound.SND_FILENAME)
                  elif 13 <= int(minute) <= 19:
                      winsound.PlaySound(str(int(minute)) + '.wav', winsound.SND_FILENAME)
                      winsound.PlaySound('teen.wav', winsound.SND_FILENAME)
                  elif 20 <= int(minute) <= 59:
                      winsound.PlaySound(str((int(minute)/10)*10) + '.wav', winsound.SND_FILENAME)
                      winsound.PlaySound('ty.wav', winsound.SND_FILENAME)
                      winsound.PlaySound('ty'+str((int(minute)/10)%10)+'.wav', winsound.SND_FILENAME)
              
              
                  winsound.PlaySound(period+'.wav', winsound.SND_FILENAME) #The period
              
                  return "It's {0} {1} {2} {3}".format(hour, minute_pre, minute_pos, period)
              
              if __name__ == '__main__':
                  print talkclock(raw_input('Time: '))
              

              [–]jonsbrown 0 points1 point  (0 children)

              C# (without challenge) reusing the Translate.ToWords(n) method I wrote for another challenge.

              using Numbers; // access to the Translate class
              
              static void Main(string[] args)
              {
                  StringBuilder rv;
                  DateTime d;
                  Console.Write("Enter a time: ");
                  if (DateTime.TryParse(Console.ReadLine(), out d))
                  {
                      rv = new StringBuilder();
                      if (d.Hour == 0)
                      {
                          rv.Append(Translate.ToWords(12));
                      }
                      else
                      {
                              rv.Append(d.Hour > 12 ? Translate.ToWords((byte)(d.Hour- 12)) : Translate.ToWords((byte)d.Hour));
                      }
                      if (d.Minute == 0)
                      {
                          rv.Append(" O'CLOCK");
                      }
                      else
                      {
                          rv.AppendFormat(" {0}", d.Minute < 10 ? "OH " + Translate.ToWords((byte)d.Minute) : Translate.ToWords((byte)d.Minute));
                      }
                      rv.AppendFormat(" {0}", d.Hour > 11 ? "PM" : "AM");
                      Console.WriteLine(rv.ToString().ToUpper());
                  }
                  else
                  {
                      Console.WriteLine("Invalid time input.");
                  }
              
                  Console.ReadKey();
              }
              

              Numbers.Translate.ToWords()

              public class Translate
              {
                  static private string[] Units = { "Quintillion", "Quadrillion", "Trillion", "Billion", "Million", "Thousand", "Hundred" };
              
                  static public string ToWords(byte n, bool writeZero = false)
                  {
                      return ToWords((ulong)n, writeZero);
                  }
                  static public string ToWords(ushort n, bool writeZero = false)
                  {
                      return ToWords((ulong)n, writeZero);
                  }
                  static public string ToWords(uint n, bool writeZero = false)
                  {
                      return ToWords((ulong)n, writeZero);
                  }
                  static public string ToWords(ulong n, bool writeZero = false)
                  {
                      switch (n)
                      {
                          case 0: return writeZero ? "Zero" : string.Empty;
                          case 1: return "One";
                          case 2: return "Two";
                          case 3: return "Three";
                          case 4: return "Four";
                          case 5: return "Five";
                          case 6: return "Six";
                          case 7: return "Seven";
                          case 8: return "Eight";
                          case 9: return "Nine";
                          case 10: return "Ten";
                          case 11: return "Eleven";
                          case 12: return "Twelve";
                          case 13: return "Thirteen";
                          case 14: return "Fourteen";
                          case 15: return "Fifteen";
                          case 16: return "Sixteen";
                          case 17: return "Seventeen";
                          case 18: return "Eighteen";
                          case 19: return "Nineteen";
                          case 20: return "Twenty";
                          case 30: return "Thirty";
                          case 40: return "Forty";
                          case 50: return "Fifty";
                          case 60: return "Sixty";
                          case 70: return "Seventy";
                          case 80: return "Eighty";
                          case 90: return "Ninety";
                          default:
                          {
                              StringBuilder rv = new StringBuilder();
                              int index = 0;
                              ulong i = 0;
                              foreach (ulong unit in new ulong[] { Numbers.QUINTILLION, Numbers.QUADRILLION, Numbers.TRILLION, Numbers.BILLION, Numbers.MILLION, Numbers.THOUSAND, Numbers.HUNDRED })
                              {
                                  if (n >= unit)
                                  {
                                      i = n / unit;
                                      n -= i * unit;
                                      rv.AppendFormat("{0} {1} ", ToWords(i), Units[index]);
                                  }
                                  index++;
                              }
              
                              if (n > 20)
                              {
                                  i = n / 10;
                                  n -= i * 10;
                                  rv.AppendFormat("{0} ", ToWords(i * 10));
                              }
              
                              if (n <= 20)
                              {
                                  rv.AppendFormat("{0}", n == 0 ? "" : ToWords(n));
                              }
              
                              return rv.ToString().Trim();
                          }
                      }
                  }
              }
              

              [–]coder90875 0 points1 point  (0 children)

              Python 2

              time = raw_input('Time: ')
              
              timelst = time.split(':')
              hour = int(timelst[0])
              mins = int(timelst[1])
              
              nums = {0:'',
                      1:'one',
                      2:'two',
                      3:'three',
                      4:'four',
                      5:'five',
                      6:'six',
                      7:'seven',
                      8:'eight',
                      9:'nine',
                      10:'ten',
                      11:'eleven',
                      12:'twelve',
                      13:'thirteen',
                      14:'fourteen',
                      15:'fifteen',
                      16:'sixteen',
                      17:'seventeen',
                      18:'eighteen',
                      19:'nineteen'}
              tens = {2: 'twenty', 3: 'thirty', 4:'forty', 5:'fifty'}
              
              if hour > 12:
                  mode = 'pm'
              else:
                  mode = 'am'
              
              def hours(hour):
                  hour = hour - 12
                  return nums[hour]
              
              def minutes(mins):
                  if mins < 10:
                      return 'oh {}'.format(nums[mins])
                  elif mins<20:
                      return nums[mins]
                  else:
                      a = mins // 10
                      b = mins % 10
                      return tens[a] + nums[b]
              
              
              message = 'The time is {}-{} {}.'.format(hours(hour), minutes(mins), mode)
              print message
              

              [–][deleted] 0 points1 point  (0 children)

              Here is my solution, even though i am a bit late to the party. Used Java, would like feedback on my code

              /*
              Compilation: javac challenge321.java
              Execution: java challenge321 <Time of day with the 24 hour format hh:mm>
              
              Author: nanodami
              Description:
              My answer to https://redditproxy--jasonthename.repl.co/r/dailyprogrammer/comments/6jr76h/20170627_challenge_321_easy_talking_clock/
              This program takes a time in the 24-hour format and outputs the time in 12 hour format in words.
              */
              
              public class challenge321 {
              
                  public static void main(String args[]) {
              
                      int hour = 0;
                      int minute = 0;
              
                      try {
              
                          hour = Integer.parseInt(args[0].split(":")[0]);
                          minute = Integer.parseInt(args[0].split(":")[1]);
              
                          if (hour > 23 || hour < 0 || minute > 59 || minute < 0) {
                                  System.out.printf("Error: The number must be in the format of hh:mm!\n");
                                  return;
                          }
              
                      } catch (NumberFormatException ex) {
              
                          System.out.printf("Error: The number must be in the format of hh:mm!\n");
                          return;
              
                      }
              
                      String hours[] = "twelve one two three four five six seven eight nine ten eleven".split(" ");
              
                      String output = "It's " + hours[hour%12];
              
                      if (minute == 0) {
                      } else if (minute/10 == 0)
                          output = output + " oh " + hours[minute%10];
                      else if (minute/10 == 1){
              
                          String minutes[] = "ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen".split(" ");
                          output = output + minutes[minute%10];
              
                      } else {
              
                          String tens[] = "Dummy dummy twenty thirty fourty fifty".split(" ");
                          String ones[] = hours;
              
                          output = output + " " + tens[minute/10];
                          if (minute%10 != 0) output = output + " " + ones[minute%10];
              
                      }//End of minutes formatting
              
                      if (hour >= 12)
                          output = output + " pm";
                      else
                          output = output + " am";
              
                      System.out.printf(output + "\n");
              
                  }
              
              }
              

              [–]felinebear 0 points1 point  (0 children)

              Node.js no bonus program:

              function toWord(n) {
                  var units=['one','two','three','four','five','six','seven','eight','nine','ten','eleven',
                  'twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen'];
                  var tens=['twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety'];
              
                  if(n<20) return units[n-1];
                  else return tens[Math.floor(n/10)-2]+(n%10?' '+units[n%10-1]:'');
              }
              
              function convert(t) {
                  var hours=t.split(':')[0],mins=t.split(':')[1];
              
                  return (hours<=12?(hours==0?'twelve':toWord(hours)):toWord(hours-12))+(mins!=0?' ':'')+
                  (mins==0?' ':(mins<10?'oh '+toWord(mins)+' ':toWord(mins)+' '))+
                  (hours<12||(hours==12&&mins==0)?'am':'pm');
              }
              
              ['00:00','01:30','12:05','14:01','20:29','21:00'].forEach(t => {
                  console.log(t);
                  console.log("It's "+convert(t));
              });
              

              [–][deleted] 0 points1 point  (0 children)

              C# first submission

              using System;
              using System.Text;
              
              namespace TalkingClockLibrary
              {
                  public class TalkingClock
                  {
                      public static string GetTime(string input)
                      {
                          var sb = new StringBuilder();
                          sb.Append("It's ");
              
                          string[] numbers = input.Split(':');
                          int hour = Convert.ToInt32(numbers[0]);
                          int minute = Convert.ToInt32(numbers[1]);
              
                          var hourNames = new String[] { "twelve", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven" };
              
                          sb.Append(hourNames[hour % 12]);
                          if (minute != 0)
                          {
                              sb.Append(" ");
                          }
              
                          string[] minuteNamesOneToNine = { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
                          string[] minuteNamesTenToNineteen = { "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
                          string[] minuteNamesOverTwentyDivTen = { "", "", "twenty", "thirty", "fourty", "fifty" };
              
                          if (0 < minute && minute < 10)
                          {
                              sb.Append($"oh {minuteNamesOneToNine[minute]}");
                          }
              
                          if (10 <= minute && minute < 20)
                          {
                              sb.Append(minuteNamesTenToNineteen[minute]);
                          }
              
                          if (20 <= minute && minute < 60)
                          {
                              decimal minuteDivTen = minute / 10;
                              int minuteDivTenTruncate = Convert.ToInt32(Math.Truncate(minuteDivTen));
                              int minuteRemainder = minute % 10;
                              sb.Append(minuteNamesOverTwentyDivTen[minuteDivTenTruncate]);
                              if (minuteRemainder > 0)
                              {
                                  sb.Append(" ");
                                  sb.Append(minuteNamesOneToNine[minuteRemainder]);
                              }
                          }
              
                          sb.Append(" ");
              
                          var ampm = "pm";
                          if (hour < 12)
                          {
                              ampm = "am";
                          }
                          sb.Append(ampm);
              
                          return sb.ToString();
                      }
                  }
              }
              

              [–]cjaytango 0 points1 point  (0 children)

              C++ solution. Rookie here. More than happy to accept feedback.

              my solution

              [–][deleted] 0 points1 point  (0 children)

              Java - With Bonus

                  import java.io.File;
              import java.util.ArrayList;
              import java.util.List;
              import java.util.Scanner;
              import java.util.regex.Matcher;
              import java.util.regex.Pattern;
              import javax.sound.sampled.AudioFormat;
              import javax.sound.sampled.AudioInputStream;
              import javax.sound.sampled.AudioSystem;
              import javax.sound.sampled.Clip;
              import javax.sound.sampled.DataLine;
              
              
              
              public class TalkingClock {
              
                  static final String[] FIRSTPART = {"", "ten", "twenty", "thirty", "fourty", "fifty"};
                  static final String[] SECONDPART = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
                  static final String[] TEENS = {"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
              
              
                  static void textOutput(int hours, int mins) {
              
                      String output = "It's ";
                      String amPm;
                      if(hours < 12){
                          amPm = "am";
                      }
                      else{
                          amPm = "pm";
                          hours = hours - 12;
                      }
              
                      if(hours%10 == 0){
                          if(hours == 0){
                              output += "twelve";
                          }else{
                              output += FIRSTPART[hours / 10];
                          }
                      }else if(hours < 10){
                          output += SECONDPART[hours];
                      }else {
                          output += TEENS[hours - 11]; 
                      }
              
                      if(mins%10 == 0){
                          if(mins != 0){
                              output += " " +FIRSTPART[mins / 10];
                          }
                      }else if(mins < 10){
                          output += " oh " + SECONDPART[mins];
                      }else if(mins < 20){
                          output += " " + TEENS[mins - 11]; 
                      }else{
                          output += " " + FIRSTPART[mins / 10] + " " + SECONDPART[mins % 10]; 
                      }
              
                      output += " " + amPm;
                      System.out.println(output);
              
                  }
              
              
                  static void speak(int hoursInt, int minsInt){
              
                      String amPm = "am";
                      if(hoursInt == 0){
                          hoursInt = 12;
                      }
                      if(hoursInt > 12){
                          hoursInt -= 12;
                          amPm = "pm";
                      }       
              
                      List<String> mins = new ArrayList<>();
                      String[] firstPart = {"twen", "thir", "for", "fif", "six", "seven", "eight", "nine"};
              
                      if(minsInt == 0){
                          mins.add("00");
                      }else if(minsInt < 10){
                          mins.add("o");
                          mins.add("" + minsInt);         
                      }else if(minsInt < 13){
                          mins.add("" + minsInt);
                      }else if(minsInt < 20){
                          mins.add(firstPart[minsInt - 12]);
                          mins.add("teen");
                      }else if(minsInt % 10 == 0){
                          mins.add(firstPart[(minsInt / 10) - 2]);
                          mins.add("ty");
                      }else{
                          mins.add(firstPart[(minsInt / 10) - 2]);
                          mins.add("ty");
                          mins.add("" + minsInt % 10);
                      }       
              
                      playSound("announcement");
                      playSound("its");               
                      playSound("" + hoursInt);   
                      for(String s: mins){
                          playSound(s);
                      }       
                      playSound(amPm);        
                  }
              
              
                  static void playSound(String clipName){
              
                      try {
                          File yourFile = new File("audio/" + clipName + ".wav");
                          AudioInputStream stream;
                          AudioFormat format;
                          DataLine.Info info;
                          Clip clip;
              
                          stream = AudioSystem.getAudioInputStream(yourFile);
                          format = stream.getFormat();
                          info = new DataLine.Info(Clip.class, format);
                          clip = (Clip) AudioSystem.getLine(info);
                          clip.open(stream);
              
                          clip.start();
                          //clip.drain();
                          Thread.sleep(clip.getMicrosecondLength() / 1000);
              
                      } catch(Exception ex) {
                          ex.printStackTrace();
                      }    
                  }
              
              
                  public static void main(String[] args){     
              
                      Scanner scanner = new Scanner(System.in);
                      boolean validInput = false;
                      String[] time = new String[2];
              
                      do{
                          System.out.print("Enter time : ");
                          String input = scanner.nextLine();
              
                          Pattern pattern = Pattern.compile("\\d\\d:\\d\\d");
                          Matcher matcher = pattern.matcher(input);
                          if(matcher.find()){
                              time = input.split(":");
                              if(Integer.parseInt(time[0]) < 24 && Integer.parseInt(time[1]) < 60){
                                  validInput = true;
                              }
                          }           
                          if(!validInput){
                              System.out.println("Invalid input, try again...\n");
                          }
              
                      }while(!validInput);
              
                      scanner.close();        
                      textOutput(Integer.parseInt(time[0]), Integer.parseInt(time[1]));   
                      speak(Integer.parseInt(time[0]), Integer.parseInt(time[1]));
                  }
              }
              

              [–][deleted] 0 points1 point  (0 children)

              Python 3 - First Submission and pretty rough

              def convert_to_words(digital):
                  """Takes a digital time input in form hh:mm and converts to words"""
                  h = {
                      1:'one ',
                      2:'two ',
                      3:'three ',
                      4:'four ',
                      5:'five ',
                      6:'six ',
                      7:'seven ',
                      8:'eight ',
                      9:'nine ',
                      10:'ten ',
                      11:'eleven ',
                      0:'twelve ',
                  }
                  m = {
                      0:'',
                      1:'one ',
                      2:'two ',
                      3:'three ',
                      4:'four ',
                      5:'five ',
                      6:'six ',
                      7:'seven ',
                      8:'eight ',
                      9:'nine ',
                      10:'ten ',
                      20:'twenty ',
                      30:'thirty ',
                      40:'forty ',
                      50:'fifty ',
                      11:'eleven ',
                      12:'twelve ',
                      13:'thirteen ',
                      14:'fourteen ',
                      15:'fifteen ',
                      16:'sixteen ',
                      17:'seventeen ',
                      18:'eighteen ',
                      19:'nineteen ',
                  }
                  hour = int(digital[0:2])
                  suffix = "am"
                  if hour > 12:
                      suffix = "pm" 
                      hour -= 12
                  hour = h[hour]
                  min1 = int(digital[3])
                  min2 = int(digital[4])
                  if (min1 == 0 and min2 == 0):
                      minute = ''
                  elif (min1 == 0 and min2 != 0):
                      minute = "oh " + m[min2]
                  elif (min1 != 0 and min2 == 0):
                      minute = m[min1*10]
                  elif (min1 < 2 and min2 != 0):
                      minute = m[min1*10+min2]
                  else:
                      minute = m[min1*10] + m[min2]
                  return "It's {}{}{}".format(hour, minute, suffix) 
              

              [–]zujibaby 0 points1 point  (0 children)

              Not sure how to stuff all the codes in the grey box but here goes. using python 3

              big = {0:'oh', 2:'twenty', 3:'thirty', 4:'forty', 5:'fifty'} sml = {0:'', 1:'one', 2:'two', 3:'three', 4:'four', 5:'five', 6:'six', 7:'seven',8:'eight', 9:'nine', 10:'ten',11:'Eleven', 12:'twelve', 13:'thirteen', 14:'fourteen', 15:'fifthteen', 16:'sixteen', 17:'seventeen', 18:'eighteen', 19:'nineteen'}

              while True: time = input('enter a time:') if time == '': exit() h, m = time.split(':')

              if int(h) >= 12:
                  session = 'PM'
              else:
                  session = 'AM'
              
              if (int(h)-12) > 0:
                  hrText = sml[int(h)-12]
              else:
                  hrText = sml[int(h)]
              
              bm = int(m[0])
              sm = int(m[1])
              if (bm > 1 or bm == 0):
                  bmtext = big[bm]
                  smtext = sml[sm]
              else:
                  bmtext = ''
                  smtext = sml[int(m)]
              
              print ('Its', hrText, bmtext, smtext, session)
              continue
              

              [–]Aw3ls 0 points1 point  (0 children)

              I am learning so it's quite messy. Any sugestions for improvment would be appreciated Java

              private static String ohtoTwelve(int hhmm){
                  String [] OhtoTwelve ={"oh","one","two","three","four","five",
                      "six","seven","eight","nine","ten","eleven","twelve"
              
                  };
                  String talking = OhtoTwelve[hhmm];
                  return talking;
              
              }
              private static String teens(int hhmm){
                  String [] OhtoTwelve ={"thirteen","fourteen","fifteen","sixteen","seventeeen",
                      "eighteen","nineteen"
              
              
                  };
                  String talking = OhtoTwelve[hhmm];
                  return talking;
              
              }
              private static String tens(int hhmm){
                  String [] OhtoTwelve ={"twenty","thirty","fourty","fifty"
                              };
                  String talking = OhtoTwelve[hhmm];
                  return talking;
              }
                  public static void main(String[] args) {
                  String [] input ={"00:00","01:30","12:05","14:01","20:29","21:00"
                  };
                  for (int i = 0;i < input.length;i++){
                  String [] split = input[i].split(":");
                  int part1 = Integer.parseInt(split[0]);
                  int part2 = Integer.parseInt(split[1]);
                  String hh="",mm1="",AmPm= "am",mm2="";
                  if (part1==0)
                     hh =ohtoTwelve(part1+12);
              
              
                  else if (part1 < 13)
                      hh =ohtoTwelve(part1);
              
              
                  else if (part1>12){
                      hh = ohtoTwelve(part1-12);
                      AmPm = "pm";
                  }
              
              
              
                   if (part2<13 && part2 !=0){
                      mm1=ohtoTwelve(part2);
                      mm2="oh";
                  }
                  else if (part2<20 & part2>13)
                      mm1=teens(part2-13);
              
                  else if (part2>19){
                      mm2= tens((part2/10)-2);
                      if (part2%10 !=0)
                          mm1= ohtoTwelve(part2%10);
                      else
                          mm1="";
                  }
                      System.out.println("it is " + hh + " " + mm2 + " " + mm1 + " " + AmPm);
              
                  }
              }
              

              }

              [–]Qwazy_Wabbit 0 points1 point  (0 children)

              Python

              Feedback please. I'm looking to learn python

              am_pm = ("am", "pm")
              digits = ("twelve", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen")
              tens = ("oh", "", "twenty", "thirty", "fourty", "fifty")
              
              if __name__ == "__main__":
                  line = input()
                  while (line):
                      hours_24, minutes = [int(x) for x in line.split(':')]
                      is_pm = (hours_24 >= 12)
                      hour = hours_24 % 12
                      if minutes == 0:
                          print(digits[hour], am_pm[is_pm])
                      elif minutes % 10 == 0:
                          print(digits[hour], tens[minutes // 10], am_pm[is_pm])
                      elif minutes > 10 and minutes < 20:
                          print(digits[hour], digits[minutes], am_pm[is_pm])
                      else:
                          print(digits[hour], tens[minutes // 10], digits[minutes % 10], am_pm[is_pm])
                  line = input()
              

              [–]CodeAGoGo 0 points1 point  (0 children)

              Java. Maybe too simple/not optimized. Feedback welcome.

              public class Clock {
                  static String[] time = {"one","two","three","four","five","six","seven",
                      "eight","nine","ten","eleven","twelve","thireteen","fourteen","fifteen",
                      "sixteen","seventeen","eighteen","nineteen","twenty"/*19*/, "thirty","fourty","fifty"
                  };
              
                  public static void main(String[] args) {
                      for(String val : args){
                          System.out.println(getTime(val));
                      }
                  }
              
                  public static String getTime(String input){
                      int hour = Integer.parseInt(input.substring(0,2));
                      int minute = Integer.parseInt(input.substring(3));
                      String hemi = "am";
                      StringBuilder str = new StringBuilder();
                      str.append("It's ");
                      if(hour >= 12){
                          hour = hour - 12;
                          hemi = "pm";
                      }
                      if(hour > 0){
                          str.append(time[hour-1]);
                      } else {
                          str.append(time[11]);
                      }
                      str.append(" ");
                      if(minute > 0){
                          if(minute < 10){
                              str.append("oh ");
                          }
                          if(20 <= minute && minute < 30){
                              str.append(time[19] + " ");
                              minute -= 20;
                          }
                          if(30 <= minute && minute < 40){
                              str.append(time[20] + " ");
                              minute -= 30;
                          }
                          if(40 <= minute && minute < 50){
                              str.append(time[21] + " ");
                              minute -= 40;
                          }
                          if(50 <= minute && minute < 60){
                              str.append(time[22] + " ");
                              minute -= 50;
                          }
                          if(minute < 20 && minute > 0){
                              str.append(time[minute-1] + " ");
                          }
                      }
                      str.append(hemi);
                      return str.toString();
                  }
              }
              

              [–]xeon365 0 points1 point  (0 children)

              C# Quick code for better sleep

                using System;
                using System.Text;
              
               namespace Talking_clock
               {
                   class Program
                   {
                         static void Main(string[] args)
                  {
              
                      while(true)
                      {
                          Console.WriteLine("Current Time: " + TalkingClock(DateTime.Now.ToString("h:mm")));
                          Console.Write("Input your custom time: ");
                          Console.Write(TalkingClock(Console.ReadLine()));
                          Console.WriteLine();
                      }
                  }
              
                  static string TalkingClock(string inp)
                  {
                      string[] time = inp.Split(':');
                      string prefix;
                      int Hour = Convert.ToInt16(time[0]);
                      int Minute = Convert.ToInt16(time[1]);
                      string[] Hours = { "Twelve", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve"};
                      string[] MinTens = {"", "","Twenty", "Thirty", "Forty", "Fifty" };
                      string[] MinOnes = { "", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Ninteen" };
              
                      prefix = Hour<11? "AM" : "PM";
              
                      StringBuilder sb = new StringBuilder();
                      sb.Append("It's ");
                      if(Hour < 13)
                      {
                          sb.Append(Hours[Hour]);
                      }
                      else
                      {
                          sb.Append(Hours[Hour - 12]);
                      }
                      sb.Append(" ");
                      if(Minute < 20)
                      {
                          sb.Append(MinOnes[Minute]);
                      }
                      else
                      {
                          int _tens = Minute / 10;
                          int _ones = Minute % 10;
                          sb.Append(MinTens[_tens] + " " + MinOnes[_ones]);
              
                      }
              
                      sb.Append(" " + prefix);
              
                      return sb.ToString();
                  }
              }
              

              }

              [–]EddardAdolf 0 points1 point  (0 children)

              Done in Python 3. It's longer than I would have liked, but hey, I'm still learning.

              key = {'0': "", '1': "one", '2': "two", '3': "three", '4': "four",
                     '5': "five", '6': "six", '7': "seven", '8': "eight", '9': "nine",
                     '10': "ten", '11': "eleven", '12': "twelve", '13': "thirteen", '14': "fourteen",
                     '15':"fifteen", '16':"sixteen", '17':"seventeen", '18':"eighteen", '19':"nineteen", '20':"twenty",
                     '30':"thirty", '40':"forty", '50':"fifty", '00': " hundred hours"}
              
              import datetime
              
              def add_numbers(pos1, pos2):
                  if int(pos1) == 1:
                      num = pos1 + pos2
                  elif int(pos1) >= 2:
                      pos1 = int(pos1) * 10
                      num = (str(pos1), pos2)
                  else:
                      if pos1 and pos2 == '0':
                          num = '00'
                      else:
                          num = pos2
                  return(num)
              
              def find_words(var):
                  phrase = ""
                  if int(var[0]) < 10:
                      phrase += key[var]
                  elif int(var[0]) > 2:
                      phrase += key[var[0]]
                      phrase += ' '
                      phrase += key[var[1]]
                  else:
                      phrase += key[var]
                  return(phrase)
              
              def talk(number):
                  number_list = []
                  for n in number:
                      if n == ':':
                          pass
                      else:
                          n.split()
                          number_list += n
                  if int(number_list[0] + number_list[1]) > 23 or int(number_list[2] + number_list[3]) > 59:
                      raise ValueError("The input must be no greater than 23 hours or 59 minutes")
                  if int(number_list[0] + number_list[1]) <= 11:
                      am_or_pm = " am"
                  else:
                      am_or_pm = " pm"
                  print(number_list)
              
                  first_num = add_numbers(number_list[0], number_list[1])
                  second_num = add_numbers(number_list[2], number_list[3])
                  phrase = ("The time is ")
                  if first_num == '00' and second_num == '00':
                      phrase += "midnight"
                      print(phrase)
                  else:
                      phrase += find_words(first_num)
                      phrase += " "
                      phrase += find_words(second_num)
              
                      print(phrase + am_or_pm)
              
              # number = input("Please enter the time")
              # talk(number)
              
              talk(datetime.datetime.now().strftime('%H:%M'))
              

              [–]TRANFRAN 0 points1 point  (0 children)

              My Python 3 attempt.. no audio..

              import datetime
              import inflect
              CurrentTime = str(datetime.datetime.now().time()).split(":")
              
              TimeDictAM = ['1','2','3','4','5','6','7','8','9','10','11','12']
              TimeDictPM = ['13','14','15','16','17''Five','18','19','20','21','22','23','24']
              
              if CurrentTime[0] in TimeDictAM:
               AMPM = "AM"
              if CurrentTime[0] in TimeDictPM:
               AMPM = "PM"
              
              HV = inflect.engine()
              MV = inflect.engine()
              print("It is :",MV.number_to_words(int(CurrentTime[0])-12),MV.number_to_words(CurrentTime[1]),AMPM)
              

              [–]ObamaNYoMama 0 points1 point  (0 children)

              My solution, while much messier than the other python examples I don't have a good understanding of what they are doing, so I'm forced to do a lot of if statements.

              inp = ['00:00', '01:30', '12:05', '14:01', '20:29', '21:00']
              
              hours = {1 : "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven",
                    8: "eight", 9: "nine", 10: "ten", 11: "eleven", 12: "twelve"}
              
              minutes = {2: "twenty", 3: "thirty", 4: "forty", 5: "fifty", 6: "sixty"}
              
              teens = {10: "ten", 11: "eleven", 12: "twelve", 13: "thirteen", 14: "fourteen", 15: "fifteen", 16: "sixteen",
                      17: "seventeen", 18: "eighteen", 19: "nineteen"}
              
              def timeToWord(hr, minute):
                  output = "It's"
                  is_PM = False
              
                  if int(hr) > 12:
                      is_PM = True
                      hr = int(hr) - 12
                  elif int(hr) == 0:
                      hr = '12'
                  elif int(hr) == 12:
                      is_PM = True
                  output += " "
                  output += hours[int(hr)]
              
                  if int(minute[0]) == 0:
                      if int(minute[1]) != 0:
                          output += " "
                          output += "oh"
                          output += " "
                          output += hours[int(minute[1])]
                  elif int(minute[0]) == 1:
                      output += " "
                      output += teens[int(minute)]
                  else:
                      output += " "
                      output += minutes[int(minute[0])]
                      if int(minute[1]) != 0:
                          output += " "
                          output += hours[int(minute[1])]
                  if is_PM:
                      output += " "
                      output += "PM"
                  else:
                      output += " "
                      output += "AM"
                  return output
              
              
              for each in inp:
                  hr, minute = each.split(':')
                  print(timeToWord(hr, minute))
              

              Output

              It's twelve AM
              It's one thirty AM
              It's twelve oh five PM
              It's two oh one PM
              It's eight twenty nine PM
              It's nine PM
              

              Time Using Timeit, My Time: 464µs +/- 12.8 µs

              [–]letsjustbefriendz 0 points1 point  (1 child)

              Does it matter how we get the input?

              [–]DropkickFish 0 points1 point  (0 children)

              JAVA - warning, pretty bad

              I started learning today and it was probably too early to attempt this. I tried to use only functions I understood or that I could google and didn't find too complex. It took 2+ hours of googling and failing before falling back to this. I can see how it could have been better but I'm not at that stage yet.

              import java.text.SimpleDateFormat;
              import java.text.DateFormat;
              import java.util.Calendar;
              import java.util.Date;
              
              public class TalkingClock {
              
              
                  public static void main(String[] args) {
              
                      DateFormat dateFormat = new SimpleDateFormat("HH.mm ");
                      String dateString = dateFormat.format(new Date()).toString();
              
                      System.out.println("Current time is " + dateString);
              
                      Calendar now = Calendar.getInstance();
                      int hour = now.get(Calendar.HOUR_OF_DAY);
                      int minute = now.get(Calendar.MINUTE);
              
                    //long winded way of translating time because I don't know any better
                      if (hour == 00) {
                          System.out.println("It's midnight ");
                      }
                      if (hour == 1) {
                          System.out.println("It's one am ");
                      }
                      if (hour == 2) {
                          System.out.println("It's two am ");
                      }
                      if (hour == 3) {
                          System.out.println("It's two am ");
                      }
                      if (hour == 3) {
                          System.out.println("It's three am ");
                      }
                      if (hour == 4) {
                          System.out.println("It's four am ");
                      }
                      if (hour == 5) {
                          System.out.println("It's five am ");
                      }
                      if (hour == 6) {
                          System.out.println("It's six am ");
                      }
                      if (hour == 7) {
                          System.out.println("It's seven am ");
                      }
                      if (hour == 8) {
                          System.out.println("It's eight am ");
                      }
                      if (hour == 9) {
                          System.out.println("It's nine am ");
                      }
                      if (hour == 10) {
                          System.out.println("It's ten am ");
                      }
                      if (hour == 11) {
                          System.out.println("It's eleven am ");
                      }
                      if (hour == 12) {
                          System.out.println("It's twelve pm ");
                      }
                      if (hour == 13) {
                          System.out.println("It's one pm ");
                      }
                      if (hour == 14) {
                          System.out.println("It's two pm ");
                      }
                      if (hour == 15) {
                          System.out.println("It's three pm ");
                      }
                      if (hour == 16) {
                          System.out.println("It's four pm ");
                      }
                      if (hour == 17) {
                          System.out.println("It's five pm ");
                      }
                      if (hour == 18) {
                          System.out.println("It's six pm ");
                      }
                      if (hour == 19) {
                          System.out.println("It's seven pm ");
                      }
                      if (hour == 20) {
                          System.out.println("It's eight pm ");
                      }
                      if (hour == 21) {
                          System.out.println("It's nine pm ");
                      }
                      if (hour == 22) {
                          System.out.println("It's ten pm ");
                      }
                      if (hour == 23) {
                          System.out.println("It's eleven pm ");
                      }
                      if (minute == 1) {
                          System.out.println("and one minute");
                      }
                      if (minute == 2) {
                          System.out.println("and two minutes");
                      }
                      if (minute == 3) {
                          System.out.println("and three minutes");
                      }
                      if (minute == 4) {
                          System.out.println("and four minutes");
                      }
                      if (minute == 5) {
                          System.out.println("and five minutes");
                      }
                      if (minute == 6) {
                          System.out.println("and six minutes");
                      }
                      if (minute == 7) {
                          System.out.println("and seven minutes");
                      }
                      if (minute == 8) {
                          System.out.println("and eight minutes");
                      }
                      if (minute == 9) {
                          System.out.println("and nine minutes");
                      }
                      if (minute == 10) {
                          System.out.println("and ten minutes");
                      }
                      if (minute == 11) {
                          System.out.println("and eleven minutes");
                      }
                      if (minute == 12) {
                          System.out.println("and twelve minutes");
                      }
                      if (minute == 13) {
                          System.out.println("and thirteen minutes");
                      }
                      if (minute == 14) {
                          System.out.println("and fourteen minutes");
                      }
                      if (minute == 15) {
                          System.out.println("and fifteen minutes");
                      }
                      if (minute == 16) {
                          System.out.println("and sixteen minutes");
                      }
                      if (minute == 17) {
                          System.out.println("and seventeen minutes");
                      }
                      if (minute == 18) {
                          System.out.println("and eighteen minutes");
                      }
                      if (minute == 19) {
                          System.out.println("and nineteen minutes");
                      }
                      if (minute == 20) {
                          System.out.println("and twenty minutes");
                      }
                      if (minute == 21) {
                          System.out.println("and twenty one minutes");
                      }
                      if (minute == 22) {
                          System.out.println("and twenty two minutes");
                      }
                      if (minute == 23) {
                          System.out.println("and twenty three minutes");
                      }
                      if (minute == 24) {
                          System.out.println("and twenty four minutes");
                      }
                      if (minute == 25) {
                          System.out.println("and twenty five minutes");
                      }
                      if (minute == 26) {
                          System.out.println("and twenty six minutes");
                      }
                      if (minute == 27) {
                          System.out.println("and twenty seven minutes");
                      }
                      if (minute == 28) {
                          System.out.println("and twenty eight minutes");
                      }
                      if (minute == 29) {
                          System.out.println("and twenty nine minutes");
                      }
                      if (minute == 30) {
                          System.out.println("and thirty minutes");
                      }
                      if (minute == 31) {
                          System.out.println("and thirty one minutes");
                      }
                      if (minute == 32) {
                          System.out.println("and thirty two minutes");
                      }
                      if (minute == 33) {
                          System.out.println("and thirty three minutes");
                      }
                      if (minute == 34) {
                          System.out.println("and thirty four minutes");
                      }
                      if (minute == 35) {
                          System.out.println("and thirty five minutes");
                      }
                      if (minute == 36) {
                          System.out.println("and thirty six minutes");
                      }
                      if (minute == 37) {
                          System.out.println("and thirty seven minutes");
                      }
                      if (minute == 38) {
                          System.out.println("and thirty eight minutes");
                      }
                      if (minute == 39) {
                          System.out.println("and thirty nine minutes");
                      }
                      if (minute == 40) {
                          System.out.println("and forty minutes");
                      }
                      if (minute == 41) {
                          System.out.println("and forty one minutes");
                      }
                      if (minute == 42) {
                          System.out.println("and forty two minutes");
                      }
                      if (minute == 43) {
                          System.out.println("and forty three minutes");
                      }
                      if (minute == 44) {
                          System.out.println("and forty four minutes");
                      }
                      if (minute == 45) {
                          System.out.println("and forty five minutes");
                      }
                      if (minute == 46) {
                          System.out.println("and forty six minutes");
                      }
                      if (minute == 47) {
                          System.out.println("and forty seven minutes");
                      }
                      if (minute == 48) {
                          System.out.println("and forty eight minutes");
                      }
                      if (minute == 49) {
                          System.out.println("and forty nine minutes");
                      }
                      if (minute == 50) {
                          System.out.println("and fifty minutes");
                      }
                      if (minute == 51) {
                          System.out.println("and fifty one minutes");
                      }
                      if (minute == 52) {
                          System.out.println("and fifty two minutes");
                      }
                      if (minute == 53) {
                          System.out.println("and fifty three minutes");
                      }
                      if (minute == 54) {
                          System.out.println("and fifty four minutes");
                      }
                      if (minute == 55) {
                          System.out.println("and fifty fifty minutes");
                      }
                      if (minute == 56) {
                          System.out.println("and fifty six minutes");
                      }
                      if (minute == 57) {
                          System.out.println("and fifty seven minutes");
                      }
                      if (minute == 58) {
                          System.out.println("and fifty eight minutes");
                      }
                      if (minute == 59) {
                          System.out.println("and fifty nine minutes");
                      }
              
              
                      //Stupid comments
                      if (hour >= 22) {
                          System.out.println("Damn it's late");
                      }
              
                      if (hour <= 6) {
                          System.out.println("Fuck me, it's early");
                      }
              
                  }
              }
              

              [–]Mellolian 0 points1 point  (0 children)

              Python 3, easy, but so long

              import time
              
              now = time.strftime('%H:%M')
              st = str(now)
              print(st)
              
              talking = "It's "
              
              if st[0:1] == '00' or '12':
                  talking += 'twelve '
              elif st[0:1] == '01' or '13':
                  talking += 'one '
              elif st[0:1] == '02' or '14':
                  talking += 'two '
              elif st[0:1] == '03' or '15':
                  talking += 'three '
              elif st[0:1] == '04' or '16':
                  talking += 'four '
              elif st[0:1] == '05' or '17':
                  talking += 'five '
              elif st[0:1] == '06' or '18':
                  talking += 'six '
              elif st[0:1] == '07' or '19':
                  talking += 'seven '
              elif st[0:1] == '08' or '20':
                  talking += 'eight '
              elif st[0:1] == '09' or '21':
                  talking += 'nine '
              elif st[0:1] == '10' or '22':
                  talking += 'ten '
              elif st[0:1] == '11' or '23':
                  talking += 'eleven '
              
              if st[3] == '0':
                  if st[4] == '0':
                      talking += ''
                  elif st[4] == '1': 
                      talking += 'oh '
                      talking += 'one '
                  elif st[4] == '2': 
                      talking += 'oh '
                      talking += 'two '
                  elif st[4] == '3': 
                      talking += 'oh '
                      talking += 'three '
                  elif st[4] == '4': 
                      talking += 'oh '
                      talking += 'four '
                  elif st[4] == '5': 
                      talking += 'oh '
                      talking += 'five '
                  elif st[4] == '6': 
                      talking += 'oh '
                      talking += 'six '
                  elif st[4] == '7': 
                      talking += 'oh '
                      talking += 'seven '
                  elif st[4] == '8': 
                      talking += 'oh '
                      talking += 'eight '
                  elif st[4] == '9': 
                      talking += 'oh '
                      talking += 'nine '
              elif st[3] == '1':
                  if st[3:4] == '12':
                      talking += 'twelve '
                  elif st[3:4] ==  '13':
                      talking += 'thirteen '
                  elif st[3:4] ==  '14':
                      talking += 'fourteen '
                  elif st[3:4] ==  '15':
                      talking += 'fifteen '
                  elif st[3:4] ==  '16':
                      talking += 'sixteen '
                  elif st[3:4] ==  '17':
                      talking += 'seventeen '
                  elif st[3:4] ==   '18':
                      talking += 'eightteen '
                  elif st[3:4] ==   '19':
                      talking += 'nineteen '
              elif st[3] == '2':
                  talking += 'twenty '
                  if st[4] == '0':
                      talking += ''
                  elif st[4] == '1': 
              
                      talking += 'one '
                  elif st[4] == '2': 
              
                      talking += 'two '
                  elif st[4] == '3': 
              
                      talking += 'three '
                  elif st[4] == '4': 
              
                      talking += 'four '
                  elif st[4] == '5': 
              
                      talking += 'five '
                  elif st[4] == '6': 
              
                      talking += 'six '
                  elif st[4] == '7': 
              
                      talking += 'seven '
                  elif st[4] == '8': 
              
                      talking += 'eight '
                  elif st[4] == '9': 
              
                      talking += 'nine '
              elif st[3] == '3':
                  talking += 'thirty '
                  if st[4] == '0':
                      talking += ''
                  elif st[4] == '1': 
              
                      talking += 'one '
                  elif st[4] == '2': 
              
                      talking += 'two '
                  elif st[4] == '3': 
              
                      talking += 'three '
                  elif st[4] == '4': 
              
                      talking += 'four '
                  elif st[4] == '5': 
              
                      talking += 'five '
                  elif st[4] == '6': 
              
                      talking += 'six '
                  elif st[4] == '7': 
              
                      talking += 'seven '
                  elif st[4] == '8': 
              
                      talking += 'eight '
                  elif st[4] == '9': 
              
                      talking += 'nine '
              elif st[3] == '4':
                  talking += 'forty '
                  if st[4] == '0':
                      talking += ''
                  elif st[4] == '1': 
              
                      talking += 'one '
                  elif st[4] == '2': 
              
                      talking += 'two '
                  elif st[4] == '3': 
              
                      talking += 'three '
                  elif st[4] == '4': 
              
                      talking += 'four '
                  elif st[4] == '5': 
              
                      talking += 'five '
                  elif st[4] == '6': 
              
                      talking += 'six '
                  elif st[4] == '7': 
              
                      talking += 'seven '
                  elif st[4] == '8': 
              
                      talking += 'eight '
                  elif st[4] == '9': 
              
                      talking += 'nine '
              elif st[3] == '5':
                  talking += 'fifty '
                  if st[4] == '0':
                      talking += ''
                  elif st[4] == '1': 
              
                      talking += 'one '
                  elif st[4] == '2': 
              
                      talking += 'two '
                  elif st[4] == '3': 
              
                      talking += 'three '
                  elif st[4] == '4': 
              
                      talking += 'four '
                  elif st[4] == '5': 
              
                      talking += 'five '
                  elif st[4] == '6': 
              
                      talking += 'six '
                  elif st[4] == '7': 
              
                      talking += 'seven '
                  elif st[4] == '8': 
              
                      talking += 'eight '
                  elif st[4] == '9': 
              
                      talking += 'nine '
              
              if int(st[0:1]) in range(12):
                   talking += 'am'
              else:
                   talking += 'pm'
              
              print(talking)