Anonymous user
Nautical bell: Difference between revisions
→{{header|J}}: general solution cleanup (tabluation, bug fixes, simplification of clock2ship)
m (→{{header|J}}: de-magic-ify a constant (slightly)) |
(→{{header|J}}: general solution cleanup (tabluation, bug fixes, simplification of clock2ship)) |
||
Line 246:
BELL =: 7{a. NB. Terminal bell code (\a or ^G)
time =: 6!:0
sleep =: 6!:3
print =: ucp 1!:2
shipsWatch =: verb define
PREV_MARK =. _1 _1
while. do. NB. Loop forever
now =. 3 4 {
NB. If we just flipped over to a new half-hour mark
if. (0 30 e.~ {: now)
PREV_MARK =. now
'allsWell notes'=.callWatch now
print allsWell
(ringBell"0~ -@# {. 2|#) notes
print CRLF
end.
sleep 15.0
end.
)
callWatch =: verb define
'watch bells' =. clock2ship y
NB. 1+bells because ordinals are origin-1, not origin-0
fields=.(0{y);(1{y);(watch{::WATCH);(bells{::ORDINAL);('s'#~0~:bells)
notes =. ; (0 2#:1+bells) #&.> u:16b266b 16b266a NB. ♫♪
NB. Similarly, plural for 0~:bells
notes ;~ '%02d:%02d %
)
clock2ship =: verb define"1
NB. Convert from "24 hours of 60 minutes" to
Line 285:
NB. from index-origin 0 (0 hrs, 0 minutes)
NB. index-origin 1 (0 watches, 1 bell).
6 8 #: 48 |
)
Line 292:
NB. x indicates two rings (0) or just one (1)
if. 0=x do.
sleep 0.75
print BELL
Line 302:
)</lang>
'''Examples''':
'''Notes''': I tested the <tt>clock2ship</tt>, <tt>callWatch</tt>, and <tt>ringBell</tt> functions, but didn't actually have the patience to test <tt>shipsWatch</tt> over a 24-hour period. Use at your own risk (but don't use it to keep watch on your galleon, please).
|