2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,7 +1,15 @@
The task is to write a small program that emulates a [[wp:Ship's bell#Timing_of_duty_periods|nautical bell]] producing a ringing bell pattern at certain times throughout the day.
[[File:ship'sBell.jpg|650px||right]]
[[Category: Date and time]]
;Task
Write a small program that emulates a [[wp:Ship's bell#Timing_of_duty_periods|nautical bell]] producing a ringing bell pattern at certain times throughout the day.
The bell timing should be in accordance with [[wp:GMT|Greenwich Mean Time]], unless locale dictates otherwise.
It is permissible for the program to [[Run as a daemon or service|daemonize]], or to slave off a scheduler, and it is permissible to use alternative notification methods (such as producing a written notice "Two Bells Gone"), if these are more usual for the system type.
;Cf.:
* [[Sleep]]
<br><br>

View file

@ -0,0 +1,51 @@
# syntax: GAWK -f NAUTICAL_BELL.AWK
BEGIN {
# sleep_cmd = "sleep 55s" # Unix
sleep_cmd = "TIMEOUT /T 55 >NUL" # MS-Windows
split("Middle,Morning,Forenoon,Afternoon,Dog,First",watch_arr,",")
split("One,Two,Three,Four,Five,Six,Seven,Eight",bells_arr,",")
simulate1day()
while (1) {
t = systime()
h = strftime("%H",t) + 0
m = strftime("%M",t) + 0
if (m == 0 || m == 30) {
nb(h,m)
while (systime() < t + 5) {}
}
system(sleep_cmd)
}
exit(0)
}
function nb(h,m, bells,hhmm,plural,sounds,watch) {
# hhmm = sprintf("%02d:%02d",h,m)
# if (hhmm == "00:00") { watch = 6 }
# else if (hhmm <= "04:00") { watch = 1 }
# else if (hhmm <= "08:00") { watch = 2 }
# else if (hhmm <= "12:00") { watch = 3 }
# else if (hhmm <= "16:00") { watch = 4 }
# else if (hhmm <= "20:00") { watch = 5 }
# else { watch = 6}
# determining watch: verbose & readable (above) vs. terse & cryptic (below)
watch = 60 * h + m
watch = (watch < 1 ) ? 6 : int((watch - 1) / 240 + 1)
bells = (h % 4) * 2 + int(m / 30)
if (bells == 0) { bells = 8 }
plural = (bells == 1) ? " " : "s"
sounds = strdup("\x07",bells)
printf("%02d:%02d %9s watch %5s bell%s %s\n",h,m,watch_arr[watch],bells_arr[bells],plural,sounds)
}
function simulate1day( h,m) {
for (h=0; h<=23; h++) {
for (m=0; m<=59; m+=30) {
nb(h,m)
}
}
}
function strdup(str,n, i,new_str) {
for (i=1; i<=n; i++) {
new_str = new_str str
}
gsub(str str,"& ",new_str)
return(new_str)
}

View file

@ -0,0 +1,15 @@
repeat
set {hours:h, minutes:m} to (current date)
if {0, 30} contains m then
set bells to (h mod 4) * 2 + (m div 30)
if bells is 0 then set bells to 4
set pairs to bells div 2
repeat pairs times
say "ding dong" using "Bells"
end repeat
if (bells mod 2) is 1 then
say "dong" using "Bells"
end if
end if
delay 60
end repeat

View file

@ -43,7 +43,7 @@ public class NauticalBell extends Thread {
try {
Thread.sleep(wait);
} catch (InterruptedException e) {
System.out.println(e);
return;
}
}
}

View file

@ -0,0 +1,46 @@
/*REXX pgm beep's "bells" (using PC speaker) when running (perpetually).*/
Parse Arg msg
If msg='?' Then Do
Say 'Ring a nautical bell'
Exit
End
Signal on Halt /* allow a clean way to stop prog.*/
Do Forever
Parse Value time() With hh ':' mn ':' ss
ct=time('C')
hhmmc=left(right(ct,7,0),5) /* HH:MM (leading zero). */
If msg>'' Then
Say center(arg(1) ct time(),79) /* echo arg1 with time ? */
If ss==00 & ( mn==00 | mn==30 ) Then Do /*It's time to ring bell */
dd=dd(hhmmc) /* compute number of times */
If msg>'' Then
Say center(dd "bells",79) /* echo bells? */
Do k=1 For dd
Call beep 650,500
Call syssleep 1+(k//2==0)
End
Call syssleep 60 /* ensure don't re-peel. */
End
Else
Call syssleep (60-ss)
End
/* test
time:
If arg(1)='C' Then
res='8:30am'
Else
res='08:30:00'
Return res
*/
dd: Parse Arg hhmmc
Parse Var hhmmc hh +2 ':' mm .
h=hh//4
If h=0 Then
If mm=00 Then res=8
Else res=1
Else
res=2*h+(mm=30)
Return res
halt:

View file

@ -0,0 +1,79 @@
function Get-Bell
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,
Position=0)]
[ValidateRange(1,12)]
[int]
$Hour,
[Parameter(Mandatory=$true,
Position=1)]
[ValidateSet(0,30)]
[int]
$Minute
)
$bells = @{
OneBell = 1
TwoBells = 2
ThreeBells = 2, 1
FourBells = 2, 2
FiveBells = 2, 2, 1
SixBells = 2, 2, 2
SevenBells = 2, 2, 2, 1
EightBells = 2, 2, 2, 2
}
filter Invoke-Bell
{
if ($_ -eq 1)
{
[System.Media.SystemSounds]::Asterisk.Play()
Write-Host -NoNewline "♪"
}
else
{
[System.Media.SystemSounds]::Exclamation.Play()
Write-Host -NoNewline "♪♪ "
}
Start-Sleep -Milliseconds 500
}
$time = New-TimeSpan -Hours $Hour -Minutes $Minute
switch ($time.Hours)
{
1 {if ($time.Minutes -eq 0) {$bells.TwoBells | Invoke-Bell} else {$bells.ThreeBells | Invoke-Bell}; break}
2 {if ($time.Minutes -eq 0) {$bells.FourBells | Invoke-Bell} else {$bells.FiveBells | Invoke-Bell}; break}
3 {if ($time.Minutes -eq 0) {$bells.SixBells | Invoke-Bell} else {$bells.SevenBells | Invoke-Bell}; break}
4 {if ($time.Minutes -eq 0) {$bells.EightBells | Invoke-Bell} else {$bells.OneBell | Invoke-Bell}; break}
5 {if ($time.Minutes -eq 0) {$bells.TwoBells | Invoke-Bell} else {$bells.ThreeBells | Invoke-Bell}; break}
6 {if ($time.Minutes -eq 0) {$bells.FourBells | Invoke-Bell} else {$bells.FiveBells | Invoke-Bell}; break}
7 {if ($time.Minutes -eq 0) {$bells.SixBells | Invoke-Bell} else {$bells.SevenBells | Invoke-Bell}; break}
8 {if ($time.Minutes -eq 0) {$bells.EightBells | Invoke-Bell} else {$bells.OneBell | Invoke-Bell}; break}
9 {if ($time.Minutes -eq 0) {$bells.TwoBells | Invoke-Bell} else {$bells.ThreeBells | Invoke-Bell}; break}
10 {if ($time.Minutes -eq 0) {$bells.FourBells | Invoke-Bell} else {$bells.FiveBells | Invoke-Bell}; break}
11 {if ($time.Minutes -eq 0) {$bells.SixBells | Invoke-Bell} else {$bells.SevenBells | Invoke-Bell}; break}
12 {if ($time.Minutes -eq 0) {$bells.EightBells | Invoke-Bell} else {$bells.OneBell | Invoke-Bell}}
}
Write-Host
}
Write-Host "Time Bells`n---- -----`n"
1..12 | ForEach-Object {
$date = Get-Date -Hour $_ -Minute 0
Write-Host -NoNewline "$($date.ToString("hh:mm")) "
Get-Bell -Hour $_ -Minute 0
$date = $date.AddMinutes(30)
Write-Host -NoNewline "$($date.ToString("hh:mm")) "
Get-Bell -Hour $_ -Minute 30
}

View file

@ -1,24 +1,25 @@
/*REXX pgm sounds "bells" (using PC speaker) when running (perpetually).*/
echo= arg()\==0 /*echo time & bells if any args. */
signal on halt /*allow a clean way to stop prog.*/
t.1 = '00:30 01:00 01:30 02:00 02:30 03:00 03:30 04:00'
t.2 = '04:30 05:00 05:30 06:00 06:30 07:00 07:30 08:00'
t.3 = '08:30 09:00 09:30 10:00 10:30 11:00 11:30 12:00'
/*REXX program sounds "ship's bells" (using PC speaker) when executing (perpetually).*/
echo= (arg()\==0) /*echo time and bells if any arguments.*/
signal on halt /*allow a clean way to stop the program*/
t.1= '00:30 01:00 01:30 02:00 02:30 03:00 03:30 04:00'
t.2= '04:30 05:00 05:30 06:00 06:30 07:00 07:30 08:00'
t.3= '08:30 09:00 09:30 10:00 10:30 11:00 11:30 12:00'
do forever; t=time(); ss=right(t,2); mn=right(t,2) /*times.*/
ct=time('C') /*[↓] add leading zero.*/
hhmmc=left( right( ct, 7, 0), 5) /*HH:MM (leading zero).*/
if echo then say center(arg(1) ct, 79) /*echo arg1 with time ?*/
if ss\==00 & mn\==00 & mn\==30 then /*wait for next min ? */
do; call delay 60-ss; iterate; end /*delay fraction of min*/
do forever; t=time(); ss=right(t,2); mn=substr(t,4,2) /*the current time. */
ct=time('C') /*[↓] maybe add leading zero*/
hhmmc=left( right( ct, 7, 0), 5) /*HH:MM (with leading zero).*/
if echo then say center(arg(1) ct, 79) /*echo 1st arg with the time?*/
if ss\==00 & mn\==00 & mn\==30 then do /*wait for the next minute ? */
call delay 60-ss; iterate
end /* [↑] delay minute fraction*/
/* [↓] number bells to peel.*/
do j=1 for 3 until $\==0; $=wordpos(hhmmc,t.j)
end /*j*/
/*[↓] # bells to peel.*/
do j=1 for 3 until $\==0; $=wordpos(hhmmc,t.j); end /*j*/
if $\==0 & echo then say center($ "bells", 79) /*echo the bells ? */
if $\==0 & echo then say center($ "bells", 79) /*echo bells? */
do k=1 for $; call sound 650,1; call delay 1+(k//2==0); end /*k*/
/*[↑] peel and pause.*/
call delay 60 /*ensure don't re-peel.*/
end /*forever*/
halt: /*stick a fork in it, we're done.*/
do k=1 for $; call sound 650,1; call delay 1 +(k//2==0)
end /*k*/ /*[↑] peel and then pause. */
call delay 60 /*ensure we don't re-peel. */
end /*forever*/
halt: /*stick a fork in it, we're all done. */