20
I can have a large if/else
condition for each 30 minutes but I'm looking for more math and Unicode based solution.
Here are clock emojis: . If you lack proper rendering support, you can see them below (they're not in the same order and they may look different to what you see) or at the Unicode chart, page 4. They correspond to Unicode codepoints U+1F550 (CLOCK FACE ONE OCLOCK) through U+1F567 (CLOCK FACE TWELVE-THIRTY).
Your challenge is to write a program that outputs to STDOUT the closest clock face emoji to the current system time (AM and PM should be treated the same). For example if the time t
is [5:15 < t < 5:45), you would display the 5:30 emoji .
This is code-golf, so shortest code in bytes wins. You may want to include a way to easily specify the time to test your code.
Edge test cases
Time Output Written
----------------------
11:48 12:00
3:15 3:30
9:45 10:00
7This question isn't currently on-topic here but it's probably an easy fix. You need an objective win condition, but if you tag the question [tag:code-golf] the winner will be whoever writes the shortest program. It's also a bit under specified, but you could say "a script that outputs the clock emoji closest to the current time when run" and that should be enough. Also, while not technically required, I'd recommend that you allow submissions in other languages. (Someone will probably do one in Bash anyway.) – undergroundmonorail – 2014-12-10T20:07:39.373
Windows Command prompt doesn't support emojis :( – stokastic – 2014-12-10T20:48:43.153
https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/emoji-clock/emoji-clock.plugin.zsh – Digital Trauma – 2014-12-10T21:48:37.373
@undergroundmonorail Fair point. Updated – Mohsen – 2014-12-11T00:08:07.237
2I've edited your post to attempt to have it meet our standards by clarifying the rules and making it code golf. Feel free to edit it if I misinterpreted anything. – NinjaBearMonkey – 2014-12-11T03:44:48.113
What if the languages I am writing in does not print the emoji clock face at all, but instead, a box with the hex code in it ? – Optimizer – 2014-12-11T08:30:13.657
3How should xx:15 and xx:45 be rounded? – Peter Taylor – 2014-12-11T08:35:27.843
1@PeterTaylor As seen in the test cases, they should be rounded up (i.e. 1:45 => 2:00) – NinjaBearMonkey – 2014-12-11T12:53:41.103
@Optimizer As long as it's the same character as the emoji, how it looks doesn't matter. – NinjaBearMonkey – 2014-12-11T12:59:36.883
Who even has a programming environment that enables these to be printed and seen? – feersum – 2014-12-11T18:11:58.560
I have a font that supports N:00 but not N:30, lol. – feersum – 2014-12-11T18:13:46.630
@feersum I have that on both my phone and my PC. Seems to be common. – PurkkaKoodari – 2014-12-11T18:28:26.337
Is JavaScript
alert
orconsole.log
allowed instead of stdout? – PurkkaKoodari – 2014-12-11T18:33:23.110@Pietu1998 Yes,
alert
is allowed as it is javascript's closest alternative. – NinjaBearMonkey – 2014-12-11T20:04:48.487