24
3
I have a simple task that should be relatively easy to implement by means of code. Your goal is to write a program that will output the time written in Spanish, given the time in HH:MM format. Many people likely don't know how to do this, so I will elaborate.
Time in Spanish is fairly logical. It usually follows the pattern of "Es la/Son las (hour) y (minutes)." Hours are in a 12-hour format, and "Es la" is only used if the hour is 1 (i.e. one o'clock). The minutes are a different story. If the minute is less than 30, then it is represented as shown above. If the minute is over 30, however, then the hour is rounded up and the minute is subtracted. For example, 7:35 is translated to the equivalent of "8 hours minus 25 minutes." Some more examples will be given below. The list of Spanish numbers that are necessary can be found here. There are accents on some numbers, but these are not necessary.
Note: The source says "uno," but to be grammatically correct it should be "una." This shouldn't affect any answers so far.
Note 2: Also, "cero" is not necessary. If your program outputs "Es la una" or "Son las tres," that is fine with me. Sorry for these rule changes.
Rules
- Input will be provided through STDIN or the equivalent in your language.
- No reading from outside libraries.
- Your code can do anything with invalid input.
Bonuses
- -10 if your code adds these extra phrases - "y cuarto" for :15, "y media" for :30, and "menos cuarto" for :45 (rounded up).
- -15 if your code can handle A.M. and P.M., responding with "de la mañana" and "de la tarde," accordingly.
- -15 if your code can translate the current time if no input is provided.
Scoring
- This is a code-golf challenge, and it will be scored by bytes, not characters.
Examples
Input: 8:10
Output: Son las ocho y diez.
Input: 6:45
Output: Son las siete menos quince (or cuarto).
Input: 1:29
Output: Es la una y veintinueve.
Input: 12:55
Output: Es la una menos cinco.
Let me know if there is anything to specify here. This is my first question, so it is definitely not perfect.
I know cero isn't nessesary, but if it makes my code shorter is it okay if I have it? – Maltysen – 2015-01-27T07:24:28.143
For your information, you can get feedback before you post at the sandbox.
– Stretch Maniac – 2014-11-07T01:39:00.397I predict a negative score solution. – Sparr – 2014-11-07T01:40:12.280
@StretchManiac I don't know how I never saw this. I've never really been active on PPCG, so I guess I haven't really looked at Meta enough. – mdc32 – 2014-11-07T01:40:20.030
1@Sparr I doubt it. There are probably enough numbers that have to be hardcoded for this to happen - at least 45 characters worth, even accounting for patterns. – mdc32 – 2014-11-07T01:41:22.730
Shouldn't
12:55
be1:55
? – None – 2014-11-07T02:54:10.323Also, the link you use has
uno
, and you are usinguna
. – None – 2014-11-07T02:54:40.453@hosch250 Es la una menos cinco, so it's 12:55. And thanks for pointing that out with the uno/una. I'll edit that now. – mdc32 – 2014-11-07T02:54:46.343
What should the output for
1:00
be? As a South American, I'd sayEs la una (en punto).
. As a code golfer, I'd sayEs a una y cero.
. – Dennis – 2014-11-07T03:06:13.4201@Dennis Hmm... I guess either would be fine.
Es la una y cero
is pretty repetitive, so I see your point. I didn't specify this, so I guess either one would be fine. Thanks for the feedback. – mdc32 – 2014-11-07T03:18:59.440How should I input AM/PM? Like
HH:MM AM
orHH:MMPM
? – None – 2014-11-07T03:27:24.673@hosch250 HH:MM AM, preferably. I know this makes it longer, but it makes more sense. – mdc32 – 2014-11-07T03:28:46.873
I thought this would be it. – None – 2014-11-07T03:35:58.793
My program has to wait for input, shouldn't I output the current time if they input 'now' instead? Otherwise, it will always just output the current time without waiting for input. – None – 2014-11-07T03:37:09.923
Or should it be if they press 'Enter' without a time? – None – 2014-11-07T03:38:52.083
@hosch250 It should output the current time if the function is called without any arguments - so in your case, if they press 'Enter' without any input. – mdc32 – 2014-11-07T03:40:18.920
What is the expected output for
00:00
? – Peter Taylor – 2014-11-07T07:39:38.437What is the range of valid input? h==0? h>12? – edc65 – 2014-11-07T09:30:37.163
And what about the full stop in examples? Is it part of requested output? – edc65 – 2014-11-07T09:36:51.110
What to do about midday / midnight? – Rodolfo Dias – 2014-11-07T10:18:12.823
The universal answer to "What time is it": https://www.youtube.com/watch?v=1dQXhuey51M
– William Barbosa – 2014-11-07T13:45:22.4731You should add
01:21
as a test case, because at least one answerer was confused by what you said about una vs uno. – Peter Taylor – 2014-11-08T09:23:34.1173The second bonus is (almost?) never worth it because the phrases "de la", "manana" and "tarde" alone count up to 16 bytes already. – britishtea – 2014-11-08T19:11:27.820