24
3
Introduction
A bell tower will ring its bells every hour, n
times, with n
being the the current hour on a 12 hour clock.
For example, a bell will ring 5 times at 5pm, and 10 times at 10am.
Task
Given two times in a suitable format, output the number of times the bell will ring, inclusive of the start and end times
Examples
"10am-12pm"
10+11+12= 33
[01:00, 05:00]
1+2+3+4+5 = 15
[11, 15]
11+12+1+2+3 = 29
[10:00pm, 10:00am]
10+11+12+1+2+3+4+5+6+7+8+9+10 = 88
If the start is the same as the end then the you simply just ouput the number of chimes for that hour:
[5pm, 5pm]
5 = 5
As you can see, you may choose an input method but the output must be an integer on its own (or an acceptable alternative) trailing/ leading newlines and spaces are allowed.
Note:
- inputs may span from the afternoon of one day to the morning of the next.
- the difference between the two times will never be more than 24 hours.
- input is flexible so long as you clearly state what format your input is.
- your input must have a clear distinction between AM and PM.
2Do we choose our own input method, or does it have to support all the mentioned? – anonymous2 – 2016-10-03T16:10:09.010
1You may choose the input method – Shaun Wild – 2016-10-03T16:13:57.897
1You should make it more clear that the inputs can go from
pm
toam
, thus crossing to a 2nd day. – mbomb007 – 2016-10-03T16:19:32.6003Will midnight be given as 0 or 24? – xnor – 2016-10-03T17:21:20.600
Does being able to choose the input method go as far as allowing us to take the two times in reverse (i.e. 11pm to 1am as 1, 23)? – Jonathan Allan – 2016-10-03T17:43:19.653
4
We encourage the use of the Sandbox to work out any issues with challenges before they are posted to the main site.
– Mego – 2016-10-03T17:44:13.7801@xnor : All bell towers I've seen rung 12 times at midnight. – vsz – 2016-10-04T06:08:29.340
To make it more challenging, some bell towers ring once at every quarter hour. And as almost all bell towers are attached to churches, they also ring Sundays at the beginning and end of church service. (they also ring when there is a marriage or funeral, but that would be too difficult to predict...) – vsz – 2016-10-04T06:13:59.827
1I think the first example in the "Examples" section is incorrect - 12am is 00:00, or midnight. Therefore 10am-12am = 10:00 to 00:00, or
10+11+12+1+2+3+4+5+6+7+8+9+10+11+12 = 111
– Sok – 2016-10-04T08:38:27.9001Can I use
13
-23
for1pm
-11pm
and0
instead of12am
? – Erik the Outgolfer – 2016-10-04T10:44:21.8071This challenge still has several issues with clarity, and should not have been reopened. – Mego – 2016-10-04T11:35:25.633
@BasicallyAlanTuring Shouting doesn't solve anything. As mentioned in the comments above, the first example is incorrect, and it's not clear whether midnight in 24-hour time should be 0 or 24. – Mego – 2016-10-04T12:50:27.897
@Mego It is your choice just make sure you specify – Shaun Wild – 2016-10-04T13:25:15.617