Related to, but not a duplicate of, this challenge.
Basics
This is a clock:
******
** | **
** | **
* | *
* | *
* | *
* | *
* | *
* | *
* |_______ *
* *
* *
* *
* *
* *
* *
* *
** **
** **
******
Let's note some of the basic properties:
- It's a circle, 40*20 (width*height) characters, made up of asterisks.
- There are two hands: a minute hand made of 9 pipe characters (
|
); and an hour hand made of 7 underscores (_
). I.e., in this example the time is 3:00
If a clock weren't arranged in right angles, it might look something like this:
******
** **
** | **
* | *
* | *
* | *
* | *
* | *
* | *
* |_ *
* _ *
* _ *
* _ *
* *
* *
* *
* *
** **
** **
******
This represents 4:55.
What's happened here is:
- We determine the destination (see the diagram below).
- We determine the number of spaces to delimit by. This will either be 0, 1, or 2 (see the table below).
- We draw the line by using the respective character (
|
for minute,_
for hour). - We then cut off the line at the number of characters (9 for minute, 7 for hour), including spaces, from the center of the circle along the x-axis. If we reach the edge of the clock, we stop anyway:
******
| ** **
*| | **
* | | *
* | | *
* | | *
* | | *
* | | *
* | | 1234567| *
* | |_ | *
* |987654321 _ | *
* _ | *
* _| *
* *
* *
* *
* *
** **
** **
******
For the sake of completeness, here's a diagram of all possible angles. This applies to minute-hands too: they won't go more specific than 5-minute intervals.
**→0←*
↓* ** ↓
** →11 1←*
* *
*↓ ↓*
* →10 2← *
* *
* *
* ↓
↓ • 3
9 ↑
↑ *
* *
* *
* →8 4← *
*↑ ↑*
* *
** →7 5←*
↑* ** ↑
*→6←**
The number of spaces to reach each point is as follows:
+-------+----------------------------------------+
| Point | No. of spaces to delimit with to reach |
+-------+----------------------------------------+
| 1 | 1 |
+-------+----------------------------------------+
| 2 | 2 |
+-------+----------------------------------------+
| 3 | 0 |
+-------+----------------------------------------+
| 4 | 2 |
+-------+----------------------------------------+
| 5 | 1 |
+-------+----------------------------------------+
| 6 | 0 |
+-------+----------------------------------------+
| 7 | 1 |
+-------+----------------------------------------+
| 8 | 2 |
+-------+----------------------------------------+
| 9 | 0 |
+-------+----------------------------------------+
| 10 | 2 |
+-------+----------------------------------------+
| 11 | 1 |
+-------+----------------------------------------+
| 0 | 0 |
+-------+----------------------------------------+
Note that it is asymmetrical. However, if you wish, you can also take input with the clock flipped vertically, horizontally or both, e.g.
*→○←**
↓** **↓
**→○ ○←**
* *
*↓ ↓*
* →○ ○← *
* *
* *
* ↓
↓ • ○
○ ↑
↑ *
* *
* *
* →○ ○← *
*↑ ↑*
* *
**→○ ○←**
↑** **↑
**→○←*
(flipped horizontally)
Similarly, when two hands overlap (see below) both hands would usually be aligned to the top of the top-left of the four centre squares. When requesting a flipped input, the centre location will also be flipped accordingly. Note that you cannot mix the two: if you want a flipped input, all aspects, including the centre-point and the angle anchors, will be flipped. (On these example diagrams, the centre-point is represented with the centre dot •
)
For this challenge:
- The minute hand will always be a multiple of five
- The hour hand will always be on the base of the hour (e.g. even if it is 5:59, the hour hand will be exactly on 5)
- Only valid times will be given, and the size of the clock will be constant
- If the hour hand and minute hand are on the same line, the hour hand (
_
) will be used for the first seven characters, followed by|
for two more, e.g.:
******
** **
** **
* *
* *
* *
* *
* *
* *
* _ *
* _ *
* _ *
* _ *
* | *
* *
* *
* *
** **
** **
******
would represent 8:40.
Challenge
Given a clock in this format, output the time displayed on the clock. The time should be in 12-hour format (i.e. not starting at 12), but the top number can be 0 or 12, as you wish.
Rules
- You can return the time as an array of
[hours, minutes]
, a string delimited by some character, or any other reasonable format. You must return pure, base-10 numbers, though: hex representations (0-A instead of 0-11) or other replacements for numbers are disallowed. - Results can be padded by whitespace or zeros if you wish (e.g. 01:12 instead of 1:12)
- The characters mentioned here must be the ones used by your program. Your submission cannot require substitution of these characters for something else, e.g. take a clock with '
#
' for the hour hand. Further, the input will always contain the spaces at the start of lines, but spaces after the clock (on the right of the diagram) are optional, e.g.:
******
** | **
** | **
* | *
* | *
* | *
* | *
* | *
* | *
* |_______ *
* *
* *
* *
* *
* *
* *
* *
** **
** **
******
(select this!)
- Input can be taken as an array of lines or a single newline-delimited string. Standard I/O rules apply.
- Standard loopholes are disallowed.
- This is code-golf, so shortest answer in bytes wins.
•
in combination with the8:40
example and positions of the 6 and 9 o'clocko
s in your graph.. Being an asymmetrical circle, it seems there are three different centers to start from - where the hours 6, 8, and 9 differ from that dot•
, unless I'm doing something wrong? Here a pastebin of how I currently understand the hour and minute arms of each time. I'm pretty sure it's incorrect, but I'm not sure what the intended arms should be instead.. \$\endgroup\$