Nautical bell: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) (Added Perl example) |
Alpha bravo (talk | contribs) (Added AutoHotkey) |
||
Line 34: | Line 34: | ||
delay 60 |
delay 60 |
||
end repeat</lang> |
end repeat</lang> |
||
=={{header|AutoHotkey}}== |
|||
<lang AutoHotkey>NauticalBell(hh, mm){ |
|||
Hr := 0, min := 30, Bells := [], pattern := [] |
|||
Loop 8 ; genrate 8 patterns |
|||
{ |
|||
num := A_Index , code := "" |
|||
while (num/2 >=1) |
|||
code .= "** ", num := num-2 |
|||
code .= mod(A_Index, 2) ? "*" : "" |
|||
pattern[A_Index] := code |
|||
} |
|||
loop, 48 ; 24 hours * 2 for every half an hour |
|||
{ |
|||
numBells := !mod(A_Index, 8) ? 8 : mod(A_Index, 8) , min := 30 |
|||
if !Mod(A_Index, 2) |
|||
hr++ , min := 00 |
|||
Bells[SubStr("0" hr, -1) ":" min] := numBells |
|||
} |
|||
Bells[00 ":" 00] := Bells[24 ":" 00] , numBells := Bells[hh ":" mm] |
|||
return {"bells": numBells, "pattern": Pattern[numBells]} |
|||
}</lang> |
|||
Example:<lang AutoHotkey>res := "" |
|||
loop, 24 |
|||
{ |
|||
hr := SubStr("0" A_Index -1, -1) |
|||
Loop 60 |
|||
{ |
|||
min := SubStr("0" A_Index -1, -1) |
|||
if (min = 0 || min = 30) |
|||
res .= hr ":" min "`t" NauticalBell(hr, min).bells "`t" NauticalBell(hr, min).pattern "`n" |
|||
} |
|||
} |
|||
MsgBox, 262144, , % "Time`tBells`tPattern`n" res |
|||
return</lang> |
|||
Outputs:<pre>Time Bells Pattern |
|||
00:00 8 ** ** ** ** |
|||
00:30 1 * |
|||
01:00 2 ** |
|||
01:30 3 ** * |
|||
02:00 4 ** ** |
|||
02:30 5 ** ** * |
|||
03:00 6 ** ** ** |
|||
03:30 7 ** ** ** * |
|||
04:00 8 ** ** ** ** |
|||
04:30 1 * |
|||
05:00 2 ** |
|||
05:30 3 ** * |
|||
06:00 4 ** ** |
|||
06:30 5 ** ** * |
|||
07:00 6 ** ** ** |
|||
07:30 7 ** ** ** * |
|||
08:00 8 ** ** ** ** |
|||
08:30 1 * |
|||
09:00 2 ** |
|||
09:30 3 ** * |
|||
10:00 4 ** ** |
|||
10:30 5 ** ** * |
|||
11:00 6 ** ** ** |
|||
11:30 7 ** ** ** * |
|||
12:00 8 ** ** ** ** |
|||
12:30 1 * |
|||
13:00 2 ** |
|||
13:30 3 ** * |
|||
14:00 4 ** ** |
|||
14:30 5 ** ** * |
|||
15:00 6 ** ** ** |
|||
15:30 7 ** ** ** * |
|||
16:00 8 ** ** ** ** |
|||
16:30 1 * |
|||
17:00 2 ** |
|||
17:30 3 ** * |
|||
18:00 4 ** ** |
|||
18:30 5 ** ** * |
|||
19:00 6 ** ** ** |
|||
19:30 7 ** ** ** * |
|||
20:00 8 ** ** ** ** |
|||
20:30 1 * |
|||
21:00 2 ** |
|||
21:30 3 ** * |
|||
22:00 4 ** ** |
|||
22:30 5 ** ** * |
|||
23:00 6 ** ** ** |
|||
23:30 7 ** ** ** *</pre> |
|||
Alternatively, you could remove the forever loop and set it up to run every half hour via launchd or cron. |
Alternatively, you could remove the forever loop and set it up to run every half hour via launchd or cron. |