CS‑01 calc stackhp first, all calculators welcome
#9 — Any

The Dawn Deadline

The problem

Whitby, on the Yorkshire coast. In Bram Stoker’s Dracula, a newspaper cutting dated 8 August reports the storm that brought the schooner Demeter ashore. The reporter sets the scene carefully: “Saturday evening was as fine as was ever known.” The sun “dipped below the black mass of Kettleness,” and “a little after midnight came a strange sound from over the sea.” By the time the derelict had been driven up onto the sand beside Tate Hill Pier and the crowds were scattering homeward, the writer notes that “the sky is beginning to redden over the Yorkshire wolds.”

So the night had a beginning (sunset behind Kettleness) and an end (sunrise). How long was it?

How long was the dark at Whitby, from sunset on the Saturday evening to sunrise on the following morning, 8 August? Give the answer in minutes, to the nearest minute.

Use the standard sunrise equation, with these figures:

  • Latitude of Whitby: φ = 54.486° N

  • Day of the year: N = 220 for 8 August (a non-leap year). Use this one value for both the sunset and the sunrise.

  • The sun’s declination (how far north or south of the celestial equator it stands):

    δ = −23.44° · cos( 360°/365 · (N + 10) )
    
  • Sunrise and sunset happen when the centre of the sun is 0.833° below the horizon. That allows for the sun’s own radius and for the bending of its light by the atmosphere. The sun’s hour angle H at that moment satisfies

    cos(H) = ( sin(−0.833°) − sin(φ)·sin(δ) ) / ( cos(φ)·cos(δ) )
    

    The sun moves through 15° of hour angle every hour.

Notes

  • Every number above is a stated assumption, so the answer follows from them alone. The novel never states the year of its events, and the answer does not depend on one.
  • This is the textbook approximation. An almanac built from the sun’s true position will differ from it by a few minutes. The formulas above define the answer here.
  • Work in degrees throughout. This time the inverse cosine comes back in degrees, and degrees are what you want, so there is no radian conversion at all.
  • Whitby is far enough north that an August night is short, so expect a number well under twelve hours.

Hint

Click for a hint

H is the sun’s hour angle at sunrise or sunset measured from solar noon, so it describes the length of the day: the sun is up for 2H of hour angle, centred on noon. The night is the rest of the full 360° circle. Convert hour angle to time at 15° per hour.

There is a neat shortcut. Because sin(−0.833°) = −sin(0.833°), the cosine in the equation is negative, and the angle you want for the night is the supplement of H, so you can skip the subtraction and take the arccosine of the positive version of the same fraction.

Solution

Click to reveal the solution

Declination. With N = 220:

360/365 · 230 = 226.8493°
cos(226.8493°) = −0.683919
δ = −23.44° · (−0.683919) = +16.0311°

Hour angle. The sine and cosine pieces:

sin(−0.833°) = −0.014538
sin φ · sin δ = 0.813974 × 0.276159 = 0.224786
cos φ · cos δ = 0.580902 × 0.961112 = 0.558312

cos H = (−0.014538 − 0.224786) / 0.558312 = −0.428656
H = acos(−0.428656) = 115.3823°

Day and night. The sun is up for 2H = 230.7646° of hour angle. At 15° per hour that is 15.3843 hours of day. The night is whatever remains of the full 360° circle:

night = (360° − 2H) / 15° per hour = 129.2354° / 15 = 8.6157 hours

Because cos H is the negative of the fraction 0.428656, 180° − H is just acos(+0.428656) = 64.6177°, which gives the same thing more directly:

night = 2 · acos(0.428656) / 15 = 8.6157 hours = 516.94 minutes

Answer: 517 minutes (8 hours 37 minutes).

Check. Day plus night: 15.3843 h + 8.6157 h = 24.0000 h. ✓

Calculator solutions

Every machine below uses the same plan. Put the calculator in degrees. Build sin(0.833°) + sin φ · sin δ as the numerator, build cos φ · cos δ as the denominator, divide, and take the arccosine. That is the night in degrees of hour angle halved, so divide by 7.5 to get hours, then multiply by 60 for minutes.

The declination is keyed twice, once for sin δ and once for cos δ. A four-level stack has no room to keep it around, and this way no memory register is needed.

HP-42S

Set DEG (MODES menu).

0.833  SIN
54.486  SIN
360  ENTER  365  ÷  230  ×  COS  23.44  ×  +/−   δ
SIN                                                sin δ
×  +                                               numerator
54.486  COS
360  ENTER  365  ÷  230  ×  COS  23.44  ×  +/−   δ again
COS
×  ÷                                               the fraction
ACOS                                               64.6177°
7.5  ÷  60  ×

Display: 516.9415 in FIX 4. The full value is 516.94145…, so it is 517 minutes.

HP-15C

The 15C powers up in degrees. COS⁻¹ is g COS.

0.833  SIN
54.486  SIN
360  ENTER  365  ÷  230  ×  COS  23.44  ×  CHS
SIN
×  +
54.486  COS
360  ENTER  365  ÷  230  ×  COS  23.44  ×  CHS
COS
×  ÷
g COS                    COS⁻¹, in degrees
7.5  ÷  60  ×

Display (FIX 4): 516.9415 → 517 minutes.

HP-41C

Degrees is the power-up mode. ACOS is built in but has no key of its own: run it from the alpha keyboard with XEQ ALPHA A C O S ALPHA.

0.833  SIN
54.486  SIN
360  ENTER  365  ÷  230  ×  COS  23.44  ×  CHS
SIN
×  +
54.486  COS
360  ENTER  365  ÷  230  ×  COS  23.44  ×  CHS
COS
×  ÷
XEQ  ALPHA  ACOS  ALPHA
7.5  ÷  60  ×

Display (FIX 4): 516.9415 → 517 minutes.

HP-48GX

RPL needs an ENTER between two consecutive numbers, and ACOS is ← COS. Set DEG first (type it as a command name; the 48 has no key for it). This list gets the declination without using +/− by computing 0 − 23.44·cos(…), so the same δ has to be keyed twice:

DEG
0.833  SIN
54.486  SIN
0  ENTER  23.44  ENTER  360  ENTER  365  ÷  230  ×  COS  ×  −     δ
SIN
×  +
54.486  COS
0  ENTER  23.44  ENTER  360  ENTER  365  ÷  230  ×  COS  ×  −     δ again
COS
×  ÷
ACOS
7.5  ÷  60  ×

Result: 516.941452342 → 517 minutes, matching the HP-42S to ten significant digits.

HP-25

Degrees is the default. Press f FIX 4 first so the display is not stuck at two decimals, and ACOS is g COS.

0.833  SIN
54.486  SIN
360  ENTER  365  ÷  230  ×  COS  23.44  ×  CHS
SIN
×  +
54.486  COS
360  ENTER  365  ÷  230  ×  COS  23.44  ×  CHS
COS
×  ÷
g COS                    ACOS, in degrees
7.5  ÷  60  ×

Be patient: the HP-25 takes a couple of seconds over every SIN, COS and ACOS, and a key pressed while it is still working is simply lost. Wait for the display to settle before each next key.

Display: 516.9415 → 517 minutes.

Elektronika MK-61

Slide the angle switch to Г (degrees). sin is F 7, cos is F 8, arccos is F 5, В↑ is the Enter key and /-/ changes sign. Enter every number starting with a digit.

0.833  F 7
54.486  F 7
360  В↑  365  ÷  230  ×  F 8  23.44  ×  /-/
F 7
×  +
54.486  F 8
360  В↑  365  ÷  230  ×  F 8  23.44  ×  /-/
F 8
×  ÷
F 5
7.5  ÷  60  ×

Display: 516.94142 → 517 minutes.

The MK-61 carries eight significant digits, so its last digit or two sit a little off the HP machines’ 516.9415. All of them round to 517 minutes.

TI-84

Set MODE → Degree. Store the declination in a variable (any letter works, D here), then evaluate the fraction:

−23.44cos(360/365*230)→D
cos⁻¹((sin(0.833)+sin(54.486)sin(D))/(cos(54.486)cos(D)))/7.5*60

Result: ≈ 516.9415 → 517 minutes.

Casio fx-991

The same two lines as the TI-84. Set Degree mode first: on a ClassWiz (fx-991EX/CW) that is SHIFT MENU → Angle Unit → Degree; on an older fx-991ES it is SHIFT MODE → Degree. Store the declination in memory D, or type the −23.44cos(360÷365×230) expression out twice in place of D if you would rather skip the memory.

−23.44cos(360÷365×230) → D
cos⁻¹((sin(0.833)+sin(54.486)sin(D))÷(cos(54.486)cos(D)))÷7.5×60

Result: ≈ 516.9415 → 517 minutes.

Bonus: Eli’s night shift

For programmable calculators only.

Let the Right One In is set in Blackeberg, a suburb of Stockholm, in 1982. Eli, its vampire, can only be out in the dark, so the question of how long the dark lasts is the question of how long her working day is. And it changes enormously with where you stand and when. Far enough north, there are weeks when the sun never sets, and weeks when it never rises.

The task. Write a program that takes a latitude in register 1 (degrees north) and a day of the year N in register 2, and stops with the length of the night in minutes on the display: the time from sunset to the following sunrise, by the same formulas as the main challenge. The declination is δ = −23.44° · cos(360°/365 · (N + 10)), and the sun’s centre is 0.833° below the horizon at sunrise and sunset.

The main challenge only ever needed one latitude, where the sun always rises and sets. This program has to work everywhere, and that is where the trap is. North of a certain latitude, in summer, the sun never sets, so there is no night at all; in winter it never rises, so the whole day is night. Your program must return 0 in the first case and the number of minutes in a whole day in the second.

Set your calculator to degrees, then test your program on these cases:

Case Place Latitude (°N) Day N
A Blackeberg, Stockholm, midwinter (21 Dec) 59.35 355
B Blackeberg, Stockholm, midsummer (21 Jun) 59.35 172
C Tromsø, Norway, midsummer (21 Jun) 69.65 172
D Tromsø, Norway, midwinter (21 Dec) 69.65 355
Click for a hint

Compute the fraction inside the arccosine first, and keep it in a register. That fraction is the whole story. Where the sun rises and sets normally it lies between −1 and 1. Where the sun never sets or never rises it falls outside that range, and the arccosine of a number outside it is not defined, so the calculator gives you an error instead of an answer.

So test the fraction before you take its arccosine. Decide which side of the range it is on, and what that means for the night. Keep the declination in a register too, since you need both its sine and its cosine.

Because the arccosine gives degrees of hour angle and the sun covers 15 degrees an hour, the conversion to minutes is a single multiplication by a whole number. Work out which.

Click to reveal the solution
Case The fraction Night
A −0.7006 1075.79 minutes (17 h 56 min)
B 0.7627 322.37 minutes (5 h 22 min)
C 1.2145, above 1 0: the sun never sets
D −1.1234, below −1 1440: the sun never rises, and a whole day is 1,440 minutes

The method. The fraction is

x = ( sin 0.833° + sin φ · sin δ ) / ( cos φ · cos δ )

Where −1 ≤ x ≤ 1, the night is 2 · acos(x) degrees of hour angle, which at 15° an hour is 2 · acos(x) / 15 hours, or 2 · acos(x) · 60 / 15 = 8 · acos(x) minutes.

Where x > 1, the sun’s lowest point is still above the horizon at midnight, so there is no night: the answer is 0. Where x < −1, its highest point is still below the horizon at noon: the answer is the full 1,440 minutes. These are exactly what the formula gives if you clamp x to the range −1 to 1 first, since acos(1) = 0 and acos(−1) = 180, and 8 · 180 = 1,440. So the program is the main challenge’s calculation, then two tests on x, then the multiplication by 8.

Why the tests come first. The arccosine is only defined for numbers from −1 to 1, and x leaves that range exactly when the day has no sunrise or no sunset. In case C the sun is above the horizon even at its lowest point, so x is above 1. In case D it is below the horizon even at its highest, so x is below −1. Take the arccosine first and the calculator stops with an error. Test x first and the program returns the right answer for every place on Earth.

Programs

Programs follow for the HP-42S, HP-15C, HP-41C and Elektronika MK-61. The HP-25 is left out: this program, keyed in one step per key as the HP-25 requires, comes to nearly sixty steps, against the HP-25’s 49. Open the one for your calculator, key it in once, then store a latitude and a day and run it. The text to the right of a listing explains it; do not key it in. Put the calculator in degrees first.

HP-42S

This program uses 46 lines. Press PRGM, key in the lines, press PRGM again.

01      LBL 01                            start
02-04   RCL 02   10   +                    N + 10
05-08   360   ×   365   ÷                  360 · (N + 10) / 365
09      COS
10-12   23.44   ×   +/−                   δ = −23.44 · cos( … )
13      STO 03                            δ, saved
14      SIN
15-17   RCL 01   SIN   ×                  sin φ · sin δ
18-20   0.833   SIN   +                   + sin 0.833°: the numerator
21-22   RCL 03   COS                      cos δ
23-25   RCL 01   COS   ×                  cos φ · cos δ
26      ÷                                 the fraction x
27      STO 04                            x, saved
28-30   1   X≤Y?   GTO 02                 1 ≤ x: the sun never sets, leave
31-35   1   +/−   RCL 04   X≤Y?   GTO 03    x ≤ −1: the sun never rises, leave
36-40   RCL 04   ACOS   8   ×   RTN       8 · acos(x), the night in minutes
41-43   LBL 02   0   RTN                  the sun never sets: 0
44-46   LBL 03   1440   RTN               the sun never rises: a whole day

Typing the 1 right after STO 04 pushes x up into Y, so the first test asks whether 1 ≤ x. In the second test, 1 +/− RCL 04 leaves x in X and −1 in Y, so it asks whether x ≤ −1.

To run it, put the calculator in DEG, store the latitude and the day, and start it. For case A:

59.35  STO 01
355    STO 02
XEQ 01

The night in minutes appears in X: ≈ 1075.79.

HP-15C

g P/R toggles program mode; LBL 1 is f LBL 1, the test is g x≤y (the g ÷ key) and COS⁻¹ is g COS. The 15C powers up in degrees.

f LBL 1                                   start
RCL 2   1 0   +                           N + 10
3 6 0   ×   3 6 5   ÷                     360 · (N + 10) / 365
COS
2 3 . 4 4   ×   CHS                       δ = −23.44 · cos( … )
STO 3                                     δ, saved
SIN   RCL 1   SIN   ×                     sin φ · sin δ
0 . 8 3 3   SIN   +                       + sin 0.833°: the numerator
RCL 3   COS   RCL 1   COS   ×   ÷         divided by cos φ · cos δ: the fraction x
STO 4                                     x, saved
1   g x≤y   GTO 2                         1 ≤ x: the sun never sets, leave
1   CHS   RCL 4   g x≤y   GTO 3           x ≤ −1: the sun never rises, leave
RCL 4   g COS   8   ×   R/S              8 · acos(x), the night in minutes
f LBL 2   0   R/S                         the sun never sets: 0
f LBL 3   1 4 4 0   R/S                   the sun never rises: a whole day

To run it, store the latitude and the day and start it. For case A:

59.35  STO 1
355    STO 2
GSB 1

The night in minutes shows when the program stops: ≈ 1,075.79. The 15C works at its own speed: wait for the program to stop before reading the display.

HP-41C

PRGM toggles program mode; LBL is the gold shift of STO, and the test X<=Y? is the gold shift of +. ACOS has no key. Key it in with XEQ ALPHA A C O S ALPHA, which records it as a program line. The 41C powers up in degrees.

LBL 01                                    start
RCL 02   10   +                           N + 10
360   ×   365   ÷                         360 · (N + 10) / 365
COS
23.44   ×   CHS                           δ = −23.44 · cos( … )
STO 03                                    δ, saved
SIN   RCL 01   SIN   ×                    sin φ · sin δ
0.833   SIN   +                           + sin 0.833°: the numerator
RCL 03   COS   RCL 01   COS   ×   ÷       divided by cos φ · cos δ: the fraction x
STO 04                                    x, saved
1   X<=Y?   GTO 02                        1 ≤ x: the sun never sets, leave
1   CHS   RCL 04   X<=Y?   GTO 03         x ≤ −1: the sun never rises, leave
RCL 04   ACOS   8   ×   R/S              8 · acos(x), the night in minutes
LBL 02   0   R/S                          the sun never sets: 0
LBL 03   1440   R/S                       the sun never rises: a whole day

To run it, store the latitude and the day and start it. For case A:

59.35  STO 01
355    STO 02
XEQ 01

The night in minutes shows when the program stops: ≈ 1,075.79. The 41C is slow: wait for the program to stop before reading the display.

Elektronika MK-61

This program uses 64 of the machine’s 105 steps. Put the angle switch on Г (degrees). F ПРГ enters program mode and F АВТ leaves it. sin is F 7, cos is F 8, arccos is F 5. Addresses start at 00. A conditional jump takes its two-digit address as one step and jumps when its test is false. The MK-61 can only test a number against zero, so each limit is tested as x − 1 or x + 1. A new number typed straight after a recall replaces X, so each one is preceded by В↑.

00-04   П→x 2   В↑   1 0   +              N + 10
05-12   3 6 0   ×   3 6 5   ÷              360 · (N + 10) / 365
13      F cos
14-20   2 3 . 4 4   ×   /-/                δ = −23.44 · cos( … )
21      x→П 3                              δ, saved
22-25   F sin   П→x 1   F sin   ×          sin φ · sin δ
26-32   0 . 8 3 3   F sin   +              + sin 0.833°: the numerator
33-38   П→x 3   F cos   П→x 1   F cos   ×   ÷    divided by cos φ · cos δ
39      x→П 4                              the fraction x, saved
40-43   П→x 4   В↑   1   −                 x − 1
44-45   F x<0   57                         if x − 1 is not negative, x ≥ 1: go to 57
46-49   П→x 4   В↑   1   +                 x + 1
50-51   F x≥0   59                         if x + 1 is negative, x < −1: go to 59
52-56   П→x 4   F arccos   8   ×   С/П     8 · acos(x): the night in minutes, stop
57-58   0   С/П                            the sun never sets: 0
59-63   1 4 4 0   С/П                      the sun never rises: a whole day

To run it, store the latitude and the day and start it. For case A:

5 9 . 3 5   x→П 1
3 5 5       x→П 2
БП 0 0
С/П

The night in minutes shows when it stops: ≈ 1075.79.

The MK-61 works to eight digits, so its last digits differ a little from the HP machines’.

Anymediumtrigastronomyhalloweendraculaliterature

Solvable on: HP-42S, HP-15C, HP-41C, HP-48GX, HP-25, Elektronika MK-61, TI-84, Casio fx-991